From 1cfe0c2a5570268e91ae815c59137bc15226fa57 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sat, 21 Mar 2015 18:17:22 -0400 Subject: [PATCH] add host api --- lib/api/host.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++ lib/api/index.js | 1 + 2 files changed, 113 insertions(+) create mode 100644 lib/api/host.js diff --git a/lib/api/host.js b/lib/api/host.js new file mode 100644 index 0000000..90772bb --- /dev/null +++ b/lib/api/host.js @@ -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 [--end ] [--override]", + "${command} host unmute " + ]; + }, + getHelp: function(){ + return [ + "Host:", + " Subcommands:", + " mute mute the host with the provided hostname", + " unmute unmute the host with the provided hostname", + "", + " Options:", + " --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); + } + } +}; diff --git a/lib/api/index.js b/lib/api/index.js index 4ca8d83..90a1b3f 100644 --- a/lib/api/index.js +++ b/lib/api/index.js @@ -1,5 +1,6 @@ var api = { event: require("./event"), + host: require("./host"), infrastructure: require("./infrastructure"), metric: require("./metric"), monitor: require("./monitor"),