Browse Source

add dogapi.service_check method

pull/11/head
Brett Langdon 11 years ago
parent
commit
e1a8103030
4 changed files with 67 additions and 0 deletions
  1. +2
    -0
      README.md
  2. +47
    -0
      lib/api/service_check.js
  3. +13
    -0
      lib/constants.js
  4. +5
    -0
      lib/index.js

+ 2
- 0
README.md View File

@ -121,6 +121,8 @@ DD_API_KEY=YOUR_KEY_HERE DD_APP_KEY=YOUR_KEY_HERE node app.js
* method used to take a snapshot of a datadog graph * method used to take a snapshot of a datadog graph
* `dogapi.snapshot_status(snapshot_url, [callback])` * `dogapi.snapshot_status(snapshot_url, [callback])`
* method used to check the status of a datadog snapshot * method used to check the status of a datadog snapshot
* `dogapi.service_check(status, check, host, [[extra], [callback]])`
* method used to post a new service check
## Sample Usage: ## Sample Usage:


+ 47
- 0
lib/api/service_check.js View File

@ -0,0 +1,47 @@
var util = require('util');
var constants = require('../constants');
var service_check_api = function(){};
service_check_api.prototype.service_check = function(status, check, host, extra, callback){
/*
* service_check_api.service_check(options, callback])
*
* used to post a service check
*
* `status` the `dogapi.constant.STATUSES` status code for the check
* `check` the name of the check
* `host` the host associated with the check
* `extra` an object of optional arguments `timestamp`, `message` or `tags`
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(typeof extra === 'function'){
callback = extra;
extra = {};
}
if(constants.ALL_STATUSES.indexOf(status) < 0){
throw new Error(util.format('Unknown service_check status %s', status));
}
var body = {
check: check,
status: status,
host_name: host,
timestamp: parseInt(extra['timestamp'] || (new Date().getTime() / 1000)),
};
if(extra['message']){
body['message'] = extra['message'];
}
if(extra['tags']){
body['tags'] = extra['tags'];
}
this.request('POST', '/check_run', {body: body}, callback);
};
return module.exports = service_check_api;

+ 13
- 0
lib/constants.js View File

@ -0,0 +1,13 @@
module.exports.STATUSES = {
OK: 0,
WARNING: 1,
CRITICAL: 2,
UNKNOWN: 3,
};
module.exports.ALL_STATUSES = [
module.exports.STATUSES.OK,
module.exports.STATUSES.WARNING,
module.exports.STATUSES.CRITICAL,
module.exports.STATUSES.UNKNOWN,
];

+ 5
- 0
lib/index.js View File

@ -1,6 +1,7 @@
var extend = require('extend'); var extend = require('extend');
var http_client = require('./http_client.js'); var http_client = require('./http_client.js');
var constants = require('./constants.js');
var alert_api = require('./api/alert.js'); var alert_api = require('./api/alert.js');
var dash_api = require('./api/dash.js'); var dash_api = require('./api/dash.js');
var screen_api = require('./api/screen.js'); var screen_api = require('./api/screen.js');
@ -8,6 +9,7 @@ var event_api = require('./api/event.js');
var tag_api = require('./api/tag.js'); var tag_api = require('./api/tag.js');
var metric_api = require('./api/metric.js'); var metric_api = require('./api/metric.js');
var search_api = require('./api/search.js'); var search_api = require('./api/search.js');
var service_check_api = require('./api/service_check.js');
var snapshot_api = require('./api/snapshot.js'); var snapshot_api = require('./api/snapshot.js');
@ -24,6 +26,9 @@ extend(dogapi.prototype,
tag_api.prototype, tag_api.prototype,
metric_api.prototype, metric_api.prototype,
search_api.prototype, search_api.prototype,
service_check_api.prototype,
snapshot_api.prototype); snapshot_api.prototype);
dogapi.constants = constants;
return module.exports = dogapi; return module.exports = dogapi;

Loading…
Cancel
Save