diff --git a/lib/api/alert.js b/lib/api/alert.js index 197b086..cc7bc9c 100644 --- a/lib/api/alert.js +++ b/lib/api/alert.js @@ -23,7 +23,7 @@ alert_api.prototype.add_alert = function(alert, callback){ } if(!alert['query']){ - throw new Error('`alert["query"]` is required'); + throw new Error('`alert["query"]` is required'); } this.request('POST', '/alert', {body: alert}, callback); @@ -50,7 +50,7 @@ alert_api.prototype.update_alert = function(alert_id, alert, callback){ } if(!alert['query']){ - throw new Error('`alert["query"]` is required'); + throw new Error('`alert["query"]` is required'); } this.request('PUT', util.format('/alert/%s', alert_id), {body: alert}, callback); @@ -67,7 +67,7 @@ alert_api.prototype.get_alert = function(alert_id, callback){ * `callback` an optional function to call with the results * callback(error, result, status_code) */ - this.request('GET', util.format('/alert/%s', alert_id), callback) + this.request('GET', util.format('/alert/%s', alert_id), callback); }; alert_api.prototype.delete_alert = function(alert_id, callback){ @@ -81,7 +81,7 @@ alert_api.prototype.delete_alert = function(alert_id, callback){ * `callback` an optional function to call with the results * callback(error, result, status_code) */ - this.request('DELETE', util.format('/alert/%s', alert_id), callback) + this.request('DELETE', util.format('/alert/%s', alert_id), callback); }; alert_api.prototype.get_all_alerts = function(callback){ @@ -93,7 +93,7 @@ alert_api.prototype.get_all_alerts = function(callback){ * `callback` an optional function to call with the results * callback(error, result, status_code) */ - this.request('GET', '/alert', callback) + this.request('GET', '/alert', callback); }; alert_api.prototype.mute_alerts = function(callback){ @@ -105,7 +105,7 @@ alert_api.prototype.mute_alerts = function(callback){ * `callback` an optional function to call with the results * callback(error, result, status_code) */ - this.request('POST', '/mute_alerts', callback) + this.request('POST', '/mute_alerts', callback); }; alert_api.prototype.unmute_alerts = function(callback){ @@ -117,7 +117,7 @@ alert_api.prototype.unmute_alerts = function(callback){ * `callback` an optional function to call with the results * callback(error, result, status_code) */ - this.request('POST', '/unmute_alerts', callback) + this.request('POST', '/unmute_alerts', callback); }; return module.exports = alert_api; diff --git a/lib/api/dash.js b/lib/api/dash.js index e6b76a3..8abe9c4 100644 --- a/lib/api/dash.js +++ b/lib/api/dash.js @@ -18,14 +18,14 @@ var validate_dashboard = function(dashboard){ } for(var i in dashboard['graphs']){ - if(!dashboard['graphs'][i]['title']){ - throw new Error(util.format('`dashboard["graphs"][%s]["title"]` is missing', i)); - } - if(!dashboard['graphs'][i]['definition']){ - throw new Error(util.format('`dashboard["graphs"][%s]["definition"]` is missing', i)); - } + if(!dashboard['graphs'][i]['title']){ + throw new Error(util.format('`dashboard["graphs"][%s]["title"]` is missing', i)); + } + if(!dashboard['graphs'][i]['definition']){ + throw new Error(util.format('`dashboard["graphs"][%s]["definition"]` is missing', i)); + } } -} +}; var dash_api = function(){}; @@ -39,7 +39,7 @@ dash_api.prototype.get_dashboard = function(dash_id, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, results, status_code) */ - this.request('GET', util.format('/dash/%s', dash_id), callback) + this.request('GET', util.format('/dash/%s', dash_id), callback); }; dash_api.prototype.get_all_dashboards = function(callback){ @@ -51,7 +51,7 @@ dash_api.prototype.get_all_dashboards = function(callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - this.request('GET', '/dash', callback) + this.request('GET', '/dash', callback); }; dash_api.prototype.create_dashboard = function(dashboard, callback){ @@ -97,7 +97,7 @@ dash_api.prototype.delete_dashboard = function(dash_id, callback){ * `callback` an optional function to call with the results of the api call * callback(error, result, status_code) */ - this.request('DELETE', util.format('/dash/%s', dash_id), callback) + this.request('DELETE', util.format('/dash/%s', dash_id), callback); }; return module.exports = dash_api; diff --git a/lib/api/event.js b/lib/api/event.js index ed33c36..8930e47 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -23,11 +23,11 @@ event_api.prototype.stream = function(start, end, filter, callback){ * callback(error, result, status_code) */ if(arguments.length < 2){ - throw new Error('parameters `start` and `end` are required'); + throw new Error('parameters `start` and `end` are required'); } query = { - start: parseInt(start), - end: parseInt(end), + start: parseInt(start), + end: parseInt(end), }; // this is the only case we have to check @@ -41,7 +41,7 @@ event_api.prototype.stream = function(start, end, filter, callback){ // validate the filters we were given and append to `query` // if they exist and meet their requirements if(filter['priority'] && ['low', 'normal'].indexOf(filter['priority'].toLowerCase()) >= 0){ - query['priority'] = filter['priority'].toLowerCase(); + query['priority'] = filter['priority'].toLowerCase(); } if(filter['sources'] && typeof filter['sources'] == 'object'){ query['sources'] = filter['sources'].join(); @@ -51,7 +51,7 @@ event_api.prototype.stream = function(start, end, filter, callback){ } params = { - query: query, + query: query, }; this.request('GET', '/events', params, callback); }; @@ -67,20 +67,20 @@ event_api.prototype.polling_stream = function(interval, filter, callback){ * `callback` is an optional function called with the results of the api call * callback(error, result, status_code) */ - if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ - callback = arguments[1]; - filter = {}; + if(arguments.length < 3 && typeof arguments[1] == 'function'){ + callback = arguments[1]; + filter = {}; } - if(!v8type.is(filter, v8type.OBJECT)){ - throw new Error('`filter` parameter must be an object'); + if(typeof filter != 'object'){ + throw new Error('`filter` parameter must be an object'); } var last_run = new Date().getTime() / 1000; var self = this; setInterval(function(){ - var start = last_run; - var end = last_run = new Date().getTime() / 1000; - self.stream(start, end, filter, callback); + var start = last_run; + last_run = new Date().getTime() / 1000; + self.stream(start, last_run, filter, callback); }, interval * 1000); }; @@ -96,7 +96,7 @@ event_api.prototype.get_event = function(event_id, callback){ * callback(error, result, status_code) */ if(!event_id){ - throw new Error('`event_id` parameter is required'); + throw new Error('`event_id` parameter is required'); } this.request('GET', util.format('/events/%s', event_id), callback); @@ -123,30 +123,30 @@ event_api.prototype.add_event = function(event, callback){ * `callback` is an optional function for the result * callback(error, result, status_code) */ - if(!v8type.is(event, v8type.OBJECT)){ - throw new Error('`event` parameter must be an object'); + if(typeof event != 'object'){ + throw new Error('`event` parameter must be an object'); } if(!event['title']){ - throw new Error('`title` property of `event` parameter is required'); + throw new Error('`title` property of `event` parameter is required'); } if(!event['text']){ - throw new Error('`text` property of `event` parameter is required'); + throw new Error('`text` property of `event` parameter is required'); } if(!event['date_happened']){ - event['date_happened'] = (new Date().getTime()) / 1000; + event['date_happened'] = (new Date().getTime()) / 1000; } if(event['priority']){ - if(['normal', 'low'].indexOf(event['priority'].toLowerCase()) == -1){ - event['priority'] = undefined; - } + if(['normal', 'low'].indexOf(event['priority'].toLowerCase()) == -1){ + event['priority'] = undefined; + } } if(event['tags']){ - event['tags'] = event['tags'].join(); + event['tags'] = event['tags'].join(); } this.request('POST', '/events', {body: event}, callback); @@ -166,12 +166,12 @@ event_api.prototype.add_comment = function(comment, callback){ * `callback` is an optional function for the result of the call * callback(error, result, status_code) */ - if(!v8type.is(comment, v8type.OBJECT)){ - throw new Error('`comment` parameter must be an object'); + if(typeof comment != 'object'){ + throw new Error('`comment` parameter must be an object'); } if(!comment['message']){ - throw new Error('`message` property of `comment` paramter is required'); + throw new Error('`message` property of `comment` paramter is required'); } this.request('POST', '/comments', {body: comment}, callback); diff --git a/lib/api/metric.js b/lib/api/metric.js index 2ff0640..6cdba32 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -17,7 +17,7 @@ metric_api.prototype.add_metric = function(metric, callback){ * callback(metric, [callback]) */ var metrics = { - 'series': [metric] + 'series': [metric] }; this.add_metrics(metrics, callback); }; @@ -43,10 +43,10 @@ metric_api.prototype.add_metrics = function(metrics, callback){ } for(var i in metrics['series']){ - var metric = metrics['series'][i]; - if(!metric['metric']){ - throw new Error('metric["metric"] is required'); - } + var metric = metrics['series'][i]; + if(!metric['metric']){ + throw new Error('metric["metric"] is required'); + } if(!metric['points'] || typeof metric['points'] != 'object'){ throw new Error('metric["points"] must be an array'); diff --git a/lib/api/screen.js b/lib/api/screen.js index 4845e1c..febfb8f 100644 --- a/lib/api/screen.js +++ b/lib/api/screen.js @@ -38,7 +38,7 @@ var validate_screenboard = function(screenboard){ throw new Error(util.format('`screenboard["widgets"][%s]["y"]` is missing', i)); } } -} +}; var screen_api = function(){}; @@ -52,7 +52,7 @@ screen_api.prototype.get_screenboard = function(screen_id, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, results, status_code) */ - this.request('GET', util.format('/screen/%s', screen_id), callback) + this.request('GET', util.format('/screen/%s', screen_id), callback); }; screen_api.prototype.get_all_screenboards = function(callback){ @@ -64,7 +64,7 @@ screen_api.prototype.get_all_screenboards = function(callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - this.request('GET', '/screen', callback) + this.request('GET', '/screen', callback); }; screen_api.prototype.create_screenboard = function(screenboard, callback){ @@ -110,7 +110,7 @@ screen_api.prototype.delete_screenboard = function(screen_id, callback){ * `callback` an optional function to call with the results of the api call * callback(error, result, status_code) */ - this.request('DELETE', util.format('/screen/%s', screen_id), callback) + this.request('DELETE', util.format('/screen/%s', screen_id), callback); }; return module.exports = screen_api; diff --git a/lib/api/tag.js b/lib/api/tag.js index e9213f8..f155430 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -19,9 +19,9 @@ tag_api.prototype.all_tags = function(source, callback){ } params = { - query: { - source: source - } + query: { + source: source + } }; this.request('GET', '/tags/hosts', params, callback); }; @@ -43,9 +43,9 @@ tag_api.prototype.host_tags = function(host, source, callback){ } params = { - query: { - source: source, - } + query: { + source: source, + } }; this.request('GET', util.format('/tags/hosts/%s', host), params, callback); }; @@ -67,10 +67,10 @@ tag_api.prototype.host_tags_by_source = function(host, source, callback){ } params = { - query: { - source: source, - by_source: true, - } + query: { + source: source, + by_source: true, + } }; this.request('GET', util.format('/tags/hosts/%s', host), params, callback); }; @@ -97,12 +97,12 @@ tag_api.prototype.add_tags = function(host, tags, source, callback){ } params = { - query: { - source: source, - }, - body: { - tags: tags, - } + query: { + source: source, + }, + body: { + tags: tags, + } }; this.request('POST', util.format('/tags/hosts/%s', host), params, callback); @@ -130,12 +130,12 @@ tag_api.prototype.update_tags = function(host, tags, source, callback){ } params = { - query: { - source: source, - }, - body: { - tags: tags, - } + query: { + source: source, + }, + body: { + tags: tags, + } }; this.request('PUT', util.format('/tags/hosts/%s', host), params, callback); @@ -158,9 +158,9 @@ tag_api.prototype.detach_tags = function(host, source, callback){ } params = { - query: { - source: source, - }, + query: { + source: source, + }, }; this.request('DELETE', util.format('/tags/hosts/%s', host), params, callback); diff --git a/lib/http_client.js b/lib/http_client.js index 3d759d5..c2eb04d 100644 --- a/lib/http_client.js +++ b/lib/http_client.js @@ -30,22 +30,22 @@ var client = function(options){ this.api_key = (options['api_key'])? options['api_key'] : process.env['DD_API_KEY']; if(!this.api_key){ - throw new Error('`api_key` is not present, either provide `api_key` in `options` or use environment variable `DD_API_KEY`'); + throw new Error('`api_key` is not present, either provide `api_key` in `options` or use environment variable `DD_API_KEY`'); } this.app_key = (options['app_key'])? options['app_key'] : process.env['DD_APP_KEY']; if(!this.api_key){ - throw new Error('`app_key` is not present, either provide `app_key` in `options` or use environment variable `DD_APP_KEY`'); + throw new Error('`app_key` is not present, either provide `app_key` in `options` or use environment variable `DD_APP_KEY`'); } this.api_version = (options['api_version'])? options['api_version'] : process.env['DD_API_VERSION']; if(!this.api_version){ - this.api_version = 'v1'; + this.api_version = 'v1'; } this.api_host = (options['api_host'])? options['api_host'] : process.env['DD_API_HOST']; if(!this.api_host){ - this.api_host = 'app.datadoghq.com'; + this.api_host = 'app.datadoghq.com'; } @@ -75,8 +75,8 @@ client.prototype.request = function(method, path, params, callback){ params = params || {}; var body = (typeof params['body'] == 'object')? JSON.stringify(params['body']) : params['body']; var query = { - 'api_key': this.api_key, - 'application_key': this.app_key, + 'api_key': this.api_key, + 'application_key': this.app_key, }; if(typeof params['query'] == 'object'){ @@ -84,22 +84,22 @@ client.prototype.request = function(method, path, params, callback){ } path = url.format({ - 'pathname': util.format('/api/%s%s', this.api_version, path), - 'query': query, + 'pathname': util.format('/api/%s%s', this.api_version, path), + 'query': query, }); var http_options = { - hostname: this.api_host, - port: 443, - method: method.toUpperCase(), - path: path, + hostname: this.api_host, + port: 443, + method: method.toUpperCase(), + path: path, }; if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){ - http_options['headers'] = { - 'Content-Type': 'application/json', - 'Content-Length': body.length, - }; + http_options['headers'] = { + 'Content-Type': 'application/json', + 'Content-Length': body.length, + }; } var req = https.request(http_options, function(res){ @@ -109,18 +109,18 @@ client.prototype.request = function(method, path, params, callback){ } }); - var data = ''; - res.on('data', function(chunk){ - data += chunk; - }); + var data = ''; + res.on('data', function(chunk){ + data += chunk; + }); - res.on('end', function(){ - error = null; - try{ data = JSON.parse(data); }catch(e){} - if(data['errors']){ - error = data['errors']; - data = null; - } + res.on('end', function(){ + error = null; + try{ data = JSON.parse(data); }catch(e){} + if(data['errors']){ + error = data['errors']; + data = null; + } if(typeof callback == 'function'){ callback(error, data, res.statusCode); @@ -129,7 +129,7 @@ client.prototype.request = function(method, path, params, callback){ }); if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){ - req.write(body); + req.write(body); } req.end() };