Browse Source

add host api

pull/14/head
Brett Langdon 11 years ago
parent
commit
1cfe0c2a55
2 changed files with 113 additions and 0 deletions
  1. +112
    -0
      lib/api/host.js
  2. +1
    -0
      lib/api/index.js

+ 112
- 0
lib/api/host.js View File

@ -0,0 +1,112 @@
var client = require("../client");
/*section: host
*comment: mute the given host, if it is not already muted
*params:
* hostname: the hostname of the host to mute
* options: |
* optional, an object containing any of the following
* * end: POSIX timestamp for when the mute should end
* * override: whether or not to override the end for an existing mute
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.host.mute("my.host.name", function(err, res){
* console.dir(res);
* });
* ```
*/
function mute(hostname, options, callback){
if(arguments.length < 3 && typeof arguments[1] === "function"){
callback = options;
options = {};
}
var params = {
body: {
hostname: hostname
}
};
if(typeof options === "object"){
if(options.end){
params.body.end = parseInt(options.end);
}
if(options.override){
params.body.override = options.override;
}
}
client.request("POST", "/host", params, callback);
}
/*section: host
*comment: unmute the given host, if it is not already unmuted
*params:
* hostname: the hostname of the host to unmute
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.host.unmute("my.host.name", function(err, res){
* console.dir(res);
* });
* ```
*/
function unmute(hostname, callback){
var params = {
body: {
hostname: hostname
}
};
client.request("POST", "/host", params, callback);
}
module.exports = {
mute: mute,
unmute: unmute,
getUsage: function(){
return [
"${command} host mute <host> [--end <end>] [--override]",
"${command} host unmute <host>"
];
},
getHelp: function(){
return [
"Host:",
" Subcommands:",
" mute <host> mute the host with the provided hostname",
" unmute <host> unmute the host with the provided hostname",
"",
" Options:",
" --end <end> POSIX timestamp for when the mute should end",
" --override override an existing \"end\" for a mute on a host"
];
},
handleCli: function(subcommand, args, callback){
if(subcommand === "mute"){
var hostname = args._[4];
var options = {};
if(args["end"]){
options.end = parseInt(args["end"]);
}
if(args["override"]){
options.override = args["override"];
}
mute(hostname, options, callback);
} else if(subcommand === "unmute"){
var hostname = args._[4];
unmute(hostname, callback);
} else {
callback("unknown subcommand or arguments try `dogapi host --help` for help", false);
}
}
};

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

@ -1,5 +1,6 @@
var api = {
event: require("./event"),
host: require("./host"),
infrastructure: require("./infrastructure"),
metric: require("./metric"),
monitor: require("./monitor"),


Loading…
Cancel
Save