Browse Source

add serviceCheck api

pull/14/head
Brett Langdon 11 years ago
parent
commit
1818028180
4 changed files with 61 additions and 48 deletions
  1. +2
    -1
      lib/api/index.js
  2. +55
    -0
      lib/api/serviceCheck.js
  3. +0
    -47
      lib/api/service_check.js
  4. +4
    -0
      lib/index.js

+ 2
- 1
lib/api/index.js View File

@ -1,7 +1,8 @@
var api = {
tag: require("./tag"),
metric: require("./metric"),
event: require("./event")
event: require("./event"),
serviceCheck: require("./serviceCheck")
};
module.exports = function(obj){


+ 55
- 0
lib/api/serviceCheck.js View File

@ -0,0 +1,55 @@
var client = require("../client");
/*section: serviceCheck
*comment: |
* post an update to a service check
*params:
* check: the check name (e.g. "app.ok")
* hostName: the name of the host submitting the check
* status: one of `dogapi.OK`, `dogapi.WARNING`, `dogapi.CRITICAL` or `dogapi.UNKNOWN`
* parameters: |
* optional, an object containing any of the following
* * timestamp: POSIX timestamp for when the check happened
* * message: string message to accompany the check
* * tags: an array of "tag:value"'s associated with the check
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var check = "app.ok";
* var hostName = "some.machine";
* dogapi.serviceCheck.check(
* check, hostName, dogapi.WARNING, function(err, res){
* console.dir(res);
* });
* ```
*/
function check(check, hostName, status, parameters, callback){
if(arguments.length < 5 && typeof arguments[3] === "function"){
callback = parameters;
parameters = {};
}
if(typeof parameters !== "object"){
parameters = {};
}
parameters.check = check;
parameters.host_name = hostName,
parameters.status = status;
var params = {
body: parameters
};
client.request("POST", "/check_run", params, callback);
};
module.exports = {
check: check
};

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

@ -1,47 +0,0 @@
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;

+ 4
- 0
lib/index.js View File

@ -33,3 +33,7 @@ function initialize(options){
module.exports.client = require("./client"),
module.exports.initialize = initialize;
module.exports.OK = 0;
module.exports.WARNING = 1;
module.exports.CRITICAL = 2;
module.exports.UNKNOWN = 3;

Loading…
Cancel
Save