| @ -0,0 +1,2 @@ | |||||
| node_modules/ | |||||
| test/coverage/ | |||||
| @ -0,0 +1,38 @@ | |||||
| { | |||||
| "env": { | |||||
| "commonjs": true, | |||||
| "es6": true, | |||||
| "node": true | |||||
| }, | |||||
| "extends": [ | |||||
| "plugin:@coorpacademy/coorpacademy/core", | |||||
| "plugin:@coorpacademy/coorpacademy/mocha", | |||||
| "plugin:@coorpacademy/coorpacademy/es20XX", | |||||
| "plugin:@coorpacademy/coorpacademy/lodash-fp", | |||||
| "plugin:@coorpacademy/coorpacademy/prettier" | |||||
| ], | |||||
| "parserOptions": { | |||||
| "ecmaVersion": 2017, | |||||
| "sourceType": "module" | |||||
| }, | |||||
| "plugins": [ | |||||
| "@coorpacademy/coorpacademy" | |||||
| ], | |||||
| "rules": { | |||||
| "promise/no-native": "off", | |||||
| "strict": "off", | |||||
| "fp/no-arguments": "warn", | |||||
| "no-param-reassign": "warn", | |||||
| "prefer-rest-params": "warn", | |||||
| "fp/no-loops": "warn" | |||||
| }, | |||||
| "overrides": [ | |||||
| { | |||||
| "files": [ "bin/*" ], | |||||
| "rules": { | |||||
| "no-console": "off", | |||||
| "no-continue": "warn" | |||||
| } | |||||
| } | |||||
| ] | |||||
| } | |||||
| @ -1,10 +1,15 @@ | |||||
| language: node_js | language: node_js | ||||
| node_js: | node_js: | ||||
| - "4" | |||||
| - "5" | |||||
| - "6" | - "6" | ||||
| - "7" | - "7" | ||||
| - "8" | - "8" | ||||
| - "9" | - "9" | ||||
| - "10" | - "10" | ||||
| - "node" | - "node" | ||||
| install: | |||||
| - npm install | |||||
| script: | |||||
| - npm run lint | |||||
| - npm test | |||||
| @ -1,81 +1,90 @@ | |||||
| #!/usr/bin/env node | #!/usr/bin/env node | ||||
| var dogapi = require("../"); | |||||
| var json = require("../lib/json"); | |||||
| var minimist = require("minimist"); | |||||
| var rc = require("rc"); | |||||
| var EOL = require("os").EOL; | |||||
| const dogapi = require('..'); | |||||
| const json = require('../lib/json'); | |||||
| const minimist = require('minimist'); | |||||
| const rc = require('rc'); | |||||
| const EOL = require('os').EOL; | |||||
| var config = rc("dogapi", { | |||||
| api_key: null, | |||||
| app_key: null | |||||
| const config = rc('dogapi', { | |||||
| api_key: null, | |||||
| app_key: null | |||||
| }); | }); | ||||
| dogapi.initialize(config); | dogapi.initialize(config); | ||||
| var usage = [ | |||||
| "Usage:", | |||||
| " dogapi --help", | |||||
| " dogapi <command> --help", | |||||
| " dogapi --version", | |||||
| " dogapi now", | |||||
| " dogapi past <seconds-ago>", | |||||
| " dogapi future <seconds-ahead>" | |||||
| let usage = [ | |||||
| 'Usage:', | |||||
| ' dogapi --help', | |||||
| ' dogapi <command> --help', | |||||
| ' dogapi --version', | |||||
| ' dogapi now', | |||||
| ' dogapi past <seconds-ago>', | |||||
| ' dogapi future <seconds-ahead>' | |||||
| ]; | ]; | ||||
| var help = []; | |||||
| for(var key in dogapi){ | |||||
| if(!dogapi.hasOwnProperty(key)){ | |||||
| continue; | |||||
| } else if(!dogapi[key].hasOwnProperty("getUsage") || typeof dogapi[key].getUsage !== "function"){ | |||||
| continue; | |||||
| } else if(!dogapi[key].hasOwnProperty("handleCli") || typeof dogapi[key].handleCli !== "function"){ | |||||
| continue; | |||||
| } | |||||
| usage = usage.concat(dogapi[key].getUsage()); | |||||
| let help = []; | |||||
| for (const key in dogapi) { | |||||
| if (!dogapi.hasOwnProperty(key)) { | |||||
| continue; | |||||
| } else if ( | |||||
| !dogapi[key].hasOwnProperty('getUsage') || | |||||
| typeof dogapi[key].getUsage !== 'function' | |||||
| ) { | |||||
| continue; | |||||
| } else if ( | |||||
| !dogapi[key].hasOwnProperty('handleCli') || | |||||
| typeof dogapi[key].handleCli !== 'function' | |||||
| ) { | |||||
| continue; | |||||
| } | |||||
| usage = usage.concat(dogapi[key].getUsage()); | |||||
| if(dogapi[key].hasOwnProperty("getHelp") && typeof dogapi[key].getHelp === "function"){ | |||||
| help = help.concat([""], dogapi[key].getHelp()); | |||||
| } | |||||
| if (dogapi[key].hasOwnProperty('getHelp') && typeof dogapi[key].getHelp === 'function') { | |||||
| help = help.concat([''], dogapi[key].getHelp()); | |||||
| } | |||||
| } | } | ||||
| usage = usage.concat(help); | usage = usage.concat(help); | ||||
| usage = usage.join(EOL); | usage = usage.join(EOL); | ||||
| var args = minimist(process.argv); | |||||
| const args = minimist(process.argv); | |||||
| var command = args._[2]; | |||||
| var subcommand = args._[3]; | |||||
| let command = args._[2]; | |||||
| const subcommand = args._[3]; | |||||
| // this is the one unusual case | // this is the one unusual case | ||||
| if(command === "servicecheck"){ | |||||
| command = "serviceCheck"; | |||||
| if (command === 'servicecheck') { | |||||
| command = 'serviceCheck'; | |||||
| } | } | ||||
| if(command === "now"){ | |||||
| console.log(dogapi.now()); | |||||
| } else if(command === "past" && args._.length > 3){ | |||||
| console.log(dogapi.now() - parseInt(args._[args._.length - 1])); | |||||
| } else if(command === "future" && args._.length > 3){ | |||||
| console.log(dogapi.now() + parseInt(args._[args._.length - 1])); | |||||
| } else if(dogapi.hasOwnProperty(command)){ | |||||
| if(subcommand){ | |||||
| dogapi[command].handleCli(subcommand, args, function(err, res){ | |||||
| if(err){ | |||||
| console.error(json.stringify(err, null, ' ')); | |||||
| process.exit(1); | |||||
| } else { | |||||
| if(res === ""){ | |||||
| res = "success"; | |||||
| } | |||||
| console.log(json.stringify(res, null, ' ')); | |||||
| } | |||||
| }); | |||||
| } else { | |||||
| var commandUsage = ["Usage:"].concat(dogapi[command].getUsage()); | |||||
| if(dogapi[command].hasOwnProperty("getHelp") && typeof dogapi[command].getHelp === "function"){ | |||||
| commandUsage = commandUsage.concat([EOL], dogapi[command].getHelp()); | |||||
| if (command === 'now') { | |||||
| console.log(dogapi.now()); | |||||
| } else if (command === 'past' && args._.length > 3) { | |||||
| console.log(dogapi.now() - parseInt(args._[args._.length - 1])); | |||||
| } else if (command === 'future' && args._.length > 3) { | |||||
| console.log(dogapi.now() + parseInt(args._[args._.length - 1])); | |||||
| } else if (dogapi.hasOwnProperty(command)) { | |||||
| if (subcommand) { | |||||
| dogapi[command].handleCli(subcommand, args, function(err, res) { | |||||
| if (err) { | |||||
| console.error(json.stringify(err, null, ' ')); | |||||
| process.exit(1); | |||||
| } else { | |||||
| if (res === '') { | |||||
| res = 'success'; | |||||
| } | } | ||||
| console.log(commandUsage.join(EOL).replace(/\$\{command\}/g, " dogapi")); | |||||
| console.log(json.stringify(res, null, ' ')); | |||||
| } | |||||
| }); | |||||
| } else { | |||||
| let commandUsage = ['Usage:'].concat(dogapi[command].getUsage()); | |||||
| if ( | |||||
| dogapi[command].hasOwnProperty('getHelp') && | |||||
| typeof dogapi[command].getHelp === 'function' | |||||
| ) { | |||||
| commandUsage = commandUsage.concat([EOL], dogapi[command].getHelp()); | |||||
| } | } | ||||
| } else if(args.version){ | |||||
| console.log(require("../package.json").version); | |||||
| console.log(commandUsage.join(EOL).replace(/\$\{command\}/g, ' dogapi')); | |||||
| } | |||||
| } else if (args.version) { | |||||
| console.log(require('../package.json').version); | |||||
| } else { | } else { | ||||
| console.log(usage); | |||||
| console.log(usage); | |||||
| } | } | ||||
| @ -0,0 +1,10 @@ | |||||
| const Dogapi = require('../lib'); | |||||
| const options = { | |||||
| api_key: 'YOUR_KEY_HERE', | |||||
| app_key: 'YOUR_KEY_HERE' | |||||
| }; | |||||
| const dogapi = new Dogapi(options); | |||||
| dogapi.metric.send('test', 1); | |||||
| @ -0,0 +1,10 @@ | |||||
| const dogapi = require('../lib'); | |||||
| const options = { | |||||
| api_key: 'YOUR_KEY_HERE', | |||||
| app_key: 'YOUR_KEY_HERE' | |||||
| }; | |||||
| dogapi.initialize(options); | |||||
| dogapi.metric.send('test', 1); | |||||
| @ -1,157 +1,158 @@ | |||||
| var client = require("../client"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| /*section: comment | |||||
| *comment: create a new comment | |||||
| *params: | |||||
| * message: the message of the comment | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * handle: the handle to associate the comment with (e.g. "user@domain.com") | |||||
| * * related_event_id: the event to associate the comment with | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.comment.create("a comment message", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(message, properties, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| module.exports = function(client) { | |||||
| /* section: comment | |||||
| *comment: create a new comment | |||||
| *params: | |||||
| * message: the message of the comment | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * handle: the handle to associate the comment with (e.g. "user@domain.com") | |||||
| * * related_event_id: the event to associate the comment with | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.comment.create("a comment message", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(message, properties, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| message: message | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| message | |||||
| } | |||||
| }; | }; | ||||
| if(typeof properties === "object"){ | |||||
| if(properties.handle){ | |||||
| params.body.handle = properties.handle; | |||||
| } | |||||
| if(properties.related_event_id){ | |||||
| params.body.related_event_id = properties.related_event_id; | |||||
| } | |||||
| if (typeof properties === 'object') { | |||||
| if (properties.handle) { | |||||
| params.body.handle = properties.handle; | |||||
| } | |||||
| if (properties.related_event_id) { | |||||
| params.body.related_event_id = properties.related_event_id; | |||||
| } | |||||
| } | } | ||||
| client.request("POST", "/comments", params, callback); | |||||
| } | |||||
| client.request('POST', '/comments', params, callback); | |||||
| } | |||||
| /*section: comment | |||||
| *comment: update an existing comment | |||||
| *params: | |||||
| * commentId: the id of the comment to update | |||||
| * message: the message of the comment | |||||
| * handle: optional, the handle to associate the comment with (e.g. "user@domain.com") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.comment.update(1234, "new message", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(commentId, message, handle, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = handle; | |||||
| handle = undefined; | |||||
| /* section: comment | |||||
| *comment: update an existing comment | |||||
| *params: | |||||
| * commentId: the id of the comment to update | |||||
| * message: the message of the comment | |||||
| * handle: optional, the handle to associate the comment with (e.g. "user@domain.com") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.comment.update(1234, "new message", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(commentId, message, handle, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = handle; | |||||
| handle = undefined; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| message: message | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| message, | |||||
| handle: handle || undefined | |||||
| } | |||||
| }; | }; | ||||
| if(handle){ | |||||
| params.body.handle = properties.handle; | |||||
| } | |||||
| client.request("PUT", util.format("/comments/%s", commentId), params, callback); | |||||
| } | |||||
| client.request('PUT', util.format('/comments/%s', commentId), params, callback); | |||||
| } | |||||
| /*section: comment | |||||
| *comment: remove a comment | |||||
| *params: | |||||
| * commentId: the id of the comment to remove | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.comment.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(commentId, callback){ | |||||
| client.request("DELETE" ,util.format("/comments/%s", commentId), callback); | |||||
| } | |||||
| /* section: comment | |||||
| *comment: remove a comment | |||||
| *params: | |||||
| * commentId: the id of the comment to remove | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.comment.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(commentId, callback) { | |||||
| client.request('DELETE', util.format('/comments/%s', commentId), callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| update: update, | |||||
| remove: remove, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi comment create <message> [--handle <handle>] [--event <event-id>]", | |||||
| " dogapi comment update <comment-id> <message> [--handle <handle>]", | |||||
| " dogapi comment remove <comment-id>" | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| update, | |||||
| remove, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi comment create <message> [--handle <handle>] [--event <event-id>]', | |||||
| ' dogapi comment update <comment-id> <message> [--handle <handle>]', | |||||
| ' dogapi comment remove <comment-id>' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Comment:", | |||||
| " Subcommands:", | |||||
| " create <message> add a new comment", | |||||
| " update <comment-id> <message> update an existing comment", | |||||
| " remove <comment-id> delete a comment", | |||||
| "", | |||||
| " Options:", | |||||
| " --handle <handle> the handle to associate with the comment (e.g. \"user@domain.com\")", | |||||
| " --event <event-id> related event id to associate the comment with" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Comment:', | |||||
| ' Subcommands:', | |||||
| ' create <message> add a new comment', | |||||
| ' update <comment-id> <message> update an existing comment', | |||||
| ' remove <comment-id> delete a comment', | |||||
| '', | |||||
| ' Options:', | |||||
| ' --handle <handle> the handle to associate with the comment (e.g. "user@domain.com")', | |||||
| ' --event <event-id> related event id to associate the comment with' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "create"){ | |||||
| var message = args._[4]; | |||||
| var properties = {}; | |||||
| if(args["handle"]){ | |||||
| properties.handle = args["handle"]; | |||||
| } | |||||
| if(args["event"]){ | |||||
| properties.related_event_id = parseInt(args["event"]); | |||||
| } | |||||
| create(message, properties, callback); | |||||
| } else if(subcommand === "update"){ | |||||
| var commentId = args._[4]; | |||||
| var message = args._[5]; | |||||
| update(commentId, message, args["handle"], callback); | |||||
| } else if(subcommand === "remove"){ | |||||
| var commentId = args._[4]; | |||||
| remove(commentId, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'create') { | |||||
| const message = args._[4]; | |||||
| const properties = {}; | |||||
| if (args.handle) { | |||||
| properties.handle = args.handle; | |||||
| } | |||||
| if (args.event) { | |||||
| properties.related_event_id = parseInt(args.event); | |||||
| } | } | ||||
| create(message, properties, callback); | |||||
| } else if (subcommand === 'update') { | |||||
| const commentId = args._[4]; | |||||
| const message = args._[5]; | |||||
| update(commentId, message, args.handle, callback); | |||||
| } else if (subcommand === 'remove') { | |||||
| const commentId = args._[4]; | |||||
| remove(commentId, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi comment --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,242 +1,245 @@ | |||||
| var client = require("../client"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| /*section: downtime | |||||
| *comment: schedule a new downtime | |||||
| *params: | |||||
| * scope: string scope that the downtime should apply to (e.g. "env:staging") | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * start: POSIX timestamp for when the downtime should start | |||||
| * * end: POSIX timestamp for when the downtime should end | |||||
| * * message: a string message to accompany the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.create("env:staging", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(scope, properties, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| module.exports = function(client) { | |||||
| /* section: downtime | |||||
| *comment: schedule a new downtime | |||||
| *params: | |||||
| * scope: string scope that the downtime should apply to (e.g. "env:staging") | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * start: POSIX timestamp for when the downtime should start | |||||
| * * end: POSIX timestamp for when the downtime should end | |||||
| * * message: a string message to accompany the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.create("env:staging", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(scope, properties, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| scope: scope | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| scope | |||||
| } | |||||
| }; | }; | ||||
| if(typeof properties === "object"){ | |||||
| if(properties.start){ | |||||
| params.body.start = parseInt(properties.start); | |||||
| } | |||||
| if(properties.end){ | |||||
| params.body.end = parseInt(properties.end); | |||||
| } | |||||
| if(properties.message){ | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| if (typeof properties === 'object') { | |||||
| if (properties.start) { | |||||
| params.body.start = parseInt(properties.start); | |||||
| } | |||||
| if (properties.end) { | |||||
| params.body.end = parseInt(properties.end); | |||||
| } | |||||
| if (properties.message) { | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| } | } | ||||
| client.request("POST", "/downtime", params, callback); | |||||
| } | |||||
| client.request('POST', '/downtime', params, callback); | |||||
| } | |||||
| /*section: downtime | |||||
| *comment: update an existing downtime | |||||
| *params: | |||||
| * downtimeId: the id the downtie to update | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * scope: the scope the downtime should be changed to (e.g. "env:staging") | |||||
| * * start: POSIX timestamp for when the downtime should start | |||||
| * * end: POSIX timestamp for when the downtime should end | |||||
| * * message: a string message to accompany the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var properties = { | |||||
| * scope: "env:staging" | |||||
| * }; | |||||
| * dogapi.downtime.update(1234, properties, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(downtimeId, properties, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| /* section: downtime | |||||
| *comment: update an existing downtime | |||||
| *params: | |||||
| * downtimeId: the id the downtie to update | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * scope: the scope the downtime should be changed to (e.g. "env:staging") | |||||
| * * start: POSIX timestamp for when the downtime should start | |||||
| * * end: POSIX timestamp for when the downtime should end | |||||
| * * message: a string message to accompany the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var properties = { | |||||
| * scope: "env:staging" | |||||
| * }; | |||||
| * dogapi.downtime.update(1234, properties, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(downtimeId, properties, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| } | } | ||||
| var params = { | |||||
| body: {} | |||||
| const params = { | |||||
| body: {} | |||||
| }; | }; | ||||
| if(typeof properties === "object"){ | |||||
| if(properties.scope){ | |||||
| params.body.scope = properties.scope; | |||||
| } | |||||
| if(properties.start){ | |||||
| params.body.start = parseInt(properties.start); | |||||
| } | |||||
| if(properties.end){ | |||||
| params.body.end = parseInt(properties.end); | |||||
| } | |||||
| if(properties.message){ | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| if (typeof properties === 'object') { | |||||
| if (properties.scope) { | |||||
| params.body.scope = properties.scope; | |||||
| } | |||||
| if (properties.start) { | |||||
| params.body.start = parseInt(properties.start); | |||||
| } | |||||
| if (properties.end) { | |||||
| params.body.end = parseInt(properties.end); | |||||
| } | |||||
| if (properties.message) { | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| } | } | ||||
| client.request("PUT", util.format("/downtime/%s", downtimeId), params, callback); | |||||
| } | |||||
| client.request('PUT', util.format('/downtime/%s', downtimeId), params, callback); | |||||
| } | |||||
| /*section: downtime | |||||
| *comment: delete a scheduled downtime | |||||
| *params: | |||||
| * downtimeId: the id of the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(downtimeId, callback){ | |||||
| client.request("DELETE", util.format("/downtime/%s", downtimeId), callback); | |||||
| } | |||||
| /* section: downtime | |||||
| *comment: delete a scheduled downtime | |||||
| *params: | |||||
| * downtimeId: the id of the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(downtimeId, callback) { | |||||
| client.request('DELETE', util.format('/downtime/%s', downtimeId), callback); | |||||
| } | |||||
| /*section: downtime | |||||
| *comment: get a scheduled downtimes details | |||||
| *params: | |||||
| * downtimeId: the id of the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(downtimeId, callback){ | |||||
| client.request("GET", util.format("/downtime/%s", downtimeId), callback); | |||||
| } | |||||
| /* section: downtime | |||||
| *comment: get a scheduled downtimes details | |||||
| *params: | |||||
| * downtimeId: the id of the downtime | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(downtimeId, callback) { | |||||
| client.request('GET', util.format('/downtime/%s', downtimeId), callback); | |||||
| } | |||||
| /*section: downtime | |||||
| *comment: get all downtimes details | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback){ | |||||
| client.request("GET", "/downtime", callback); | |||||
| } | |||||
| /* section: downtime | |||||
| *comment: get all downtimes details | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.downtime.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback) { | |||||
| client.request('GET', '/downtime', callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| update: update, | |||||
| remove: remove, | |||||
| get: get, | |||||
| getAll: getAll, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi downtime create <scope> [--start <start>] [--end <end>] [--message <message>]", | |||||
| " dogapi downtime update <downtime-id> [--scope <scope>] [--start <start>] [--end <end>] [--message <message>]", | |||||
| " dogapi downtime remove <downtime-id>", | |||||
| " dogapi downtime get <downtime-id>", | |||||
| " dogapi downtime getall", | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| update, | |||||
| remove, | |||||
| get, | |||||
| getAll, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi downtime create <scope> [--start <start>] [--end <end>] [--message <message>]', | |||||
| ' dogapi downtime update <downtime-id> [--scope <scope>] [--start <start>] [--end <end>] [--message <message>]', | |||||
| ' dogapi downtime remove <downtime-id>', | |||||
| ' dogapi downtime get <downtime-id>', | |||||
| ' dogapi downtime getall' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Downtime:", | |||||
| " Subcommands:", | |||||
| " create <scope> create a new downtime with the provided scope (e.g. \"env:staging\")", | |||||
| " update <downtime-id> update an existing downtime with the provided id", | |||||
| " remove <downtime-id> remove the downtime with the provided id", | |||||
| " get <downtime-id> get the details of the downtime with the provided id", | |||||
| " getall get the details of all downtimes", | |||||
| "", | |||||
| " Options:", | |||||
| " --start <start> POSIX timestamp for when the downtime should start", | |||||
| " --end <end> POSIX timestamp for when the downtime should end", | |||||
| " --message <message> a string message to accompany the downtime", | |||||
| " --scope <scope> the scope of the downtime (e.g. \"env:staging\")" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Downtime:', | |||||
| ' Subcommands:', | |||||
| ' create <scope> create a new downtime with the provided scope (e.g. "env:staging")', | |||||
| ' update <downtime-id> update an existing downtime with the provided id', | |||||
| ' remove <downtime-id> remove the downtime with the provided id', | |||||
| ' get <downtime-id> get the details of the downtime with the provided id', | |||||
| ' getall get the details of all downtimes', | |||||
| '', | |||||
| ' Options:', | |||||
| ' --start <start> POSIX timestamp for when the downtime should start', | |||||
| ' --end <end> POSIX timestamp for when the downtime should end', | |||||
| ' --message <message> a string message to accompany the downtime', | |||||
| ' --scope <scope> the scope of the downtime (e.g. "env:staging")' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "get"){ | |||||
| get(args._[4], callback); | |||||
| } else if(subcommand === "getall"){ | |||||
| getAll(callback); | |||||
| } else if(subcommand === "remove"){ | |||||
| remove(args._[4], callback); | |||||
| } else if(subcommand === "create"){ | |||||
| var scope = args._[4]; | |||||
| var properties = {}; | |||||
| if(args["start"]){ | |||||
| properties.start = parseInt(args["start"]); | |||||
| } | |||||
| if(args["end"]){ | |||||
| properties.end = parseInt(args["end"]); | |||||
| } | |||||
| if(args["message"]){ | |||||
| properties.message = args["message"]; | |||||
| } | |||||
| create(scope, properties, callback); | |||||
| } else if(subcommand === "update"){ | |||||
| var downtimeId = args._[4]; | |||||
| var properties = {}; | |||||
| if(args["scope"]){ | |||||
| properties.scope = args["scope"]; | |||||
| } | |||||
| if(args["start"]){ | |||||
| properties.start = parseInt(args["start"]); | |||||
| } | |||||
| if(args["end"]){ | |||||
| properties.end = parseInt(args["end"]); | |||||
| } | |||||
| if(args["message"]){ | |||||
| properties.message = args["message"]; | |||||
| } | |||||
| update(downtimeId, properties, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false); | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'get') { | |||||
| get(args._[4], callback); | |||||
| } else if (subcommand === 'getall') { | |||||
| getAll(callback); | |||||
| } else if (subcommand === 'remove') { | |||||
| remove(args._[4], callback); | |||||
| } else if (subcommand === 'create') { | |||||
| const scope = args._[4]; | |||||
| const properties = {}; | |||||
| if (args.start) { | |||||
| properties.start = parseInt(args.start); | |||||
| } | |||||
| if (args.end) { | |||||
| properties.end = parseInt(args.end); | |||||
| } | |||||
| if (args.message) { | |||||
| properties.message = args.message; | |||||
| } | |||||
| create(scope, properties, callback); | |||||
| } else if (subcommand === 'update') { | |||||
| const downtimeId = args._[4]; | |||||
| const properties = {}; | |||||
| if (args.scope) { | |||||
| properties.scope = args.scope; | |||||
| } | |||||
| if (args.start) { | |||||
| properties.start = parseInt(args.start); | |||||
| } | |||||
| if (args.end) { | |||||
| properties.end = parseInt(args.end); | |||||
| } | |||||
| if (args.message) { | |||||
| properties.message = args.message; | |||||
| } | } | ||||
| update(downtimeId, properties, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi downtime --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,170 +1,172 @@ | |||||
| var client = require("../client"); | |||||
| var extend = require("extend"); | |||||
| var json = require("../json"); | |||||
| var querystring = require("querystring"); | |||||
| const querystring = require('querystring'); | |||||
| const extend = require('extend'); | |||||
| const json = require('../json'); // TODO inline lib | |||||
| /*section: embed | |||||
| *comment: create an embed graph of a metric query | |||||
| *params: | |||||
| * graph_json: The request array to pass create in the embed | |||||
| * options: optional, object of extra parameters to pass to the embed create (see options[*] params) | |||||
| * options["timeframe"]: optional, one of ("1_hour", "4_hours", "1_day", "2_days", and "1_week") | |||||
| * options["size"]: optional, one of ("small", "medium", "large", "xlarge") | |||||
| * options["legend"]: optional, "yes" or "no" | |||||
| * options["title"]: optional, the title of the embed | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var query = "system.cpu.idle{*}"; | |||||
| * var graphJSON = { | |||||
| * viz: "timeseries", | |||||
| * requests: [ | |||||
| * { | |||||
| * q: query, | |||||
| * aggregator: "avg", | |||||
| * conditional_formats: [], | |||||
| * type: "area" | |||||
| * } | |||||
| * ] | |||||
| * } | |||||
| * var options = { | |||||
| * timeframe: "1_hour", | |||||
| * size: "xlarge", | |||||
| * legend: "yes", | |||||
| * title: "my awesome embed" | |||||
| * }; | |||||
| * dogapi.embed.create(graphJSON, options, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(graphJSON, options, callback){ | |||||
| if(callback === undefined && typeof options === "function"){ | |||||
| callback = options; | |||||
| options = {}; | |||||
| module.exports = function(client) { | |||||
| /* section: embed | |||||
| *comment: create an embed graph of a metric query | |||||
| *params: | |||||
| * graph_json: The request array to pass create in the embed | |||||
| * options: optional, object of extra parameters to pass to the embed create (see options[*] params) | |||||
| * options["timeframe"]: optional, one of ("1_hour", "4_hours", "1_day", "2_days", and "1_week") | |||||
| * options["size"]: optional, one of ("small", "medium", "large", "xlarge") | |||||
| * options["legend"]: optional, "yes" or "no" | |||||
| * options["title"]: optional, the title of the embed | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const query = "system.cpu.idle{*}"; | |||||
| * const graphJSON = { | |||||
| * viz: "timeseries", | |||||
| * requests: [ | |||||
| * { | |||||
| * q: query, | |||||
| * aggregator: "avg", | |||||
| * conditional_formats: [], | |||||
| * type: "area" | |||||
| * } | |||||
| * ] | |||||
| * } | |||||
| * const options = { | |||||
| * timeframe: "1_hour", | |||||
| * size: "xlarge", | |||||
| * legend: "yes", | |||||
| * title: "my awesome embed" | |||||
| * }; | |||||
| * dogapi.embed.create(graphJSON, options, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(graphJSON, options, callback) { | |||||
| if (callback === undefined && typeof options === 'function') { | |||||
| callback = options; | |||||
| options = {}; | |||||
| } | } | ||||
| var body = { | |||||
| graph_json: JSON.stringify(graphJSON) | |||||
| const body = { | |||||
| graph_json: JSON.stringify(graphJSON) | |||||
| }; | }; | ||||
| // Use `extend` to merge `options` into `body` | // Use `extend` to merge `options` into `body` | ||||
| // DEV: `extend` will ignore any properties whose value is `undefined` | // DEV: `extend` will ignore any properties whose value is `undefined` | ||||
| extend(body, options || {}); | extend(body, options || {}); | ||||
| // Create the request | // Create the request | ||||
| var params = { | |||||
| body: querystring.stringify(body), | |||||
| contentType: "application/x-www-form-urlencoded" | |||||
| const params = { | |||||
| body: querystring.stringify(body), | |||||
| contentType: 'application/x-www-form-urlencoded' | |||||
| }; | }; | ||||
| client.request("POST", "/graph/embed", params, callback); | |||||
| } | |||||
| client.request('POST', '/graph/embed', params, callback); | |||||
| } | |||||
| /*section: embed | |||||
| *comment: delete an embed with a specific id | |||||
| *params: | |||||
| * embedId: the id of the embed to delete | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var embedid = "foo"; | |||||
| * dogapi.embed.revoke(embedid, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function revoke(embedId, callback){ | |||||
| client.request("GET", "/graph/embed/" + embedId + "/revoke", callback); | |||||
| } | |||||
| /* section: embed | |||||
| *comment: delete an embed with a specific id | |||||
| *params: | |||||
| * embedId: the id of the embed to delete | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const embedid = "foo"; | |||||
| * dogapi.embed.revoke(embedid, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function revoke(embedId, callback) { | |||||
| client.request('GET', `/graph/embed/${embedId}/revoke`, callback); | |||||
| } | |||||
| /* section: embed | |||||
| *comment: get all embeds from datadog | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * dogapi.embed.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback) { | |||||
| client.request('GET', '/graph/embed', callback); | |||||
| } | |||||
| /*section: embed | |||||
| *comment: get all embeds from datadog | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * dogapi.embed.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback) { | |||||
| client.request("GET", "/graph/embed", callback); | |||||
| } | |||||
| /* section: embed | |||||
| *comment: get a single embed | |||||
| *params: | |||||
| * embedId: the id of the embed to get | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const embedId = "foo"; | |||||
| * dogapi.embed.get(embedId, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(embedId, callback) { | |||||
| client.request('GET', `/graph/embed/${embedId}`, callback); | |||||
| } | |||||
| /*section: embed | |||||
| *comment: get a single embed | |||||
| *params: | |||||
| * embedId: the id of the embed to get | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var embedId = "foo"; | |||||
| * dogapi.embed.get(embedId, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(embedId, callback) { | |||||
| client.request("GET", "/graph/embed/" + embedId, callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| revoke: revoke, | |||||
| getAll: getAll, | |||||
| get: get, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi embed create <embed_json> [--timeframe <timeframe>] [--size <size>] [--legend <legend>] [--title <title>]", | |||||
| " dogapi embed revoke <embed_id>", | |||||
| " dogapi embed get <embed_id>", | |||||
| " dogapi embed getall" | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| revoke, | |||||
| getAll, | |||||
| get, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi embed create <embed_json> [--timeframe <timeframe>] [--size <size>] [--legend <legend>] [--title <title>]', | |||||
| ' dogapi embed revoke <embed_id>', | |||||
| ' dogapi embed get <embed_id>', | |||||
| ' dogapi embed getall' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Embed:", | |||||
| " Subcommands:", | |||||
| " create <embed_json> --timeframe <timeframe> --size <size> --legend <legend> --title <title> | create a new graph embed", | |||||
| " revoke <embed_id> revoke/delete an embed", | |||||
| " get <embed_id> gets a single embed object", | |||||
| " getall gets all embed objects", | |||||
| " Options:", | |||||
| " --events <event-query> a query for event bands to add to the snapshot", | |||||
| " --timeframe <timeframe> The timeframe for the embed (1_hour, 4_hours, 1_day, 2_days, and 1_week)", | |||||
| " --size <size> The size of the embed to create (small, medium, large, xlarge)", | |||||
| " --legend <legend> Whether or not to have a legend (yes, no)", | |||||
| " --title <title> The title of the embed to create" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Embed:', | |||||
| ' Subcommands:', | |||||
| ' create <embed_json> --timeframe <timeframe> --size <size> --legend <legend> --title <title> | create a new graph embed', | |||||
| ' revoke <embed_id> revoke/delete an embed', | |||||
| ' get <embed_id> gets a single embed object', | |||||
| ' getall gets all embed objects', | |||||
| ' Options:', | |||||
| ' --events <event-query> a query for event bands to add to the snapshot', | |||||
| ' --timeframe <timeframe> The timeframe for the embed (1_hour, 4_hours, 1_day, 2_days, and 1_week)', | |||||
| ' --size <size> The size of the embed to create (small, medium, large, xlarge)', | |||||
| ' --legend <legend> Whether or not to have a legend (yes, no)', | |||||
| ' --title <title> The title of the embed to create' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback) { | |||||
| if (args._.length > 4 && subcommand === "create") { | |||||
| var graph_json = json.parse(args._[4]); | |||||
| var options = { | |||||
| timeframe: args["timeframe"], | |||||
| size: args["size"], | |||||
| legend: args["legend"], | |||||
| title: args["title"] | |||||
| }; | |||||
| create(graph_json, options, callback); | |||||
| } else if (args._.length > 4 && subcommand === "revoke") { | |||||
| var embedId = args._[4]; | |||||
| revoke(embedId, callback); | |||||
| } else if (args._.length > 4 && subcommand === "get") { | |||||
| var embedId = args._[4]; | |||||
| get(embedId, callback); | |||||
| } else if (subcommand === "getall") { | |||||
| getAll(callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi embed --help` for help", false); | |||||
| } | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (args._.length > 4 && subcommand === 'create') { | |||||
| const graph_json = json.parse(args._[4]); | |||||
| const options = { | |||||
| timeframe: args.timeframe, | |||||
| size: args.size, | |||||
| legend: args.legend, | |||||
| title: args.title | |||||
| }; | |||||
| create(graph_json, options, callback); | |||||
| } else if (args._.length > 4 && subcommand === 'revoke') { | |||||
| const embedId = args._[4]; | |||||
| revoke(embedId, callback); | |||||
| } else if (args._.length > 4 && subcommand === 'get') { | |||||
| const embedId = args._[4]; | |||||
| get(embedId, callback); | |||||
| } else if (subcommand === 'getall') { | |||||
| getAll(callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi embed --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,209 +1,213 @@ | |||||
| var client = require("../client"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| /*section: event | |||||
| *comment: | | |||||
| * create a new event | |||||
| *params: | |||||
| * title: the title of the event | |||||
| * text: the body of the event | |||||
| * properties: | | |||||
| * an optional object continaing any of the following additional optional properties | |||||
| * * date_happened: POSIX timestamp of when it happened | |||||
| * * priority: "normal" or "low" [defualt: "normal"] | |||||
| * * host: the host name to associate with the event | |||||
| * * tags: array of "tag:value"'s to associate with the event | |||||
| * * alert_type: "error", "warning", "info" or "success" [defualt: "info"] | |||||
| * * aggregation_key: an arbitrary string used to aggregate like events | |||||
| * * source_type_name: options: "nagios", "hudson", "jenkins", "user", "my apps", "feed", "chef", "puppet", "git", "bitbucket", "fabric", "capistrano" | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var title = "some new event"; | |||||
| * var text = "IT HAPPENED!"; | |||||
| * dogapi.event.create(title, text, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * title = "another event"; | |||||
| * text = "IT HAPPENED AGAIN!"; | |||||
| * var properties = { | |||||
| * tags: ["some:tag"], | |||||
| * alert_type: "error" | |||||
| * }; | |||||
| * dogapi.event.create(title, text, properties, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(title, text, properties, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| module.exports = function(client) { | |||||
| /* section: event | |||||
| *comment: | | |||||
| * create a new event | |||||
| *params: | |||||
| * title: the title of the event | |||||
| * text: the body of the event | |||||
| * properties: | | |||||
| * an optional object continaing any of the following additional optional properties | |||||
| * * date_happened: POSIX timestamp of when it happened | |||||
| * * priority: "normal" or "low" [defualt: "normal"] | |||||
| * * host: the host name to associate with the event | |||||
| * * tags: array of "tag:value"'s to associate with the event | |||||
| * * alert_type: "error", "warning", "info" or "success" [defualt: "info"] | |||||
| * * aggregation_key: an arbitrary string used to aggregate like events | |||||
| * * source_type_name: options: "nagios", "hudson", "jenkins", "user", "my apps", "feed", "chef", "puppet", "git", "bitbucket", "fabric", "capistrano" | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const title = "some new event"; | |||||
| * const text = "IT HAPPENED!"; | |||||
| * dogapi.event.create(title, text, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * title = "another event"; | |||||
| * text = "IT HAPPENED AGAIN!"; | |||||
| * const properties = { | |||||
| * tags: ["some:tag"], | |||||
| * alert_type: "error" | |||||
| * }; | |||||
| * dogapi.event.create(title, text, properties, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(title, text, properties, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| } | } | ||||
| if(typeof properties !== "object"){ | |||||
| properties = {}; | |||||
| if (typeof properties !== 'object') { | |||||
| properties = {}; | |||||
| } | } | ||||
| properties.title = title; | properties.title = title; | ||||
| properties.text = text; | properties.text = text; | ||||
| var params = { | |||||
| body: properties | |||||
| const params = { | |||||
| body: properties | |||||
| }; | }; | ||||
| client.request("POST", "/events", params, callback); | |||||
| } | |||||
| client.request('POST', '/events', params, callback); | |||||
| } | |||||
| /*section: event | |||||
| *comment: | | |||||
| * get event details from the provided event id | |||||
| *params: | |||||
| * eventId: | | |||||
| * the id of the event to fetch | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.event.get(10005, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(eventId, callback){ | |||||
| client.request("GET", util.format("/events/%s", eventId), callback); | |||||
| } | |||||
| /* section: event | |||||
| *comment: | | |||||
| * get event details from the provided event id | |||||
| *params: | |||||
| * eventId: | | |||||
| * the id of the event to fetch | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.event.get(10005, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(eventId, callback) { | |||||
| client.request('GET', util.format('/events/%s', eventId), callback); | |||||
| } | |||||
| /*section: event | |||||
| *comment: | | |||||
| * query the event stream | |||||
| *params: | |||||
| * start: POSIX timestamp for start of query | |||||
| * end: POSIX timestamp for end of query | |||||
| * parameters: | | |||||
| * optional parameters to use for the query | |||||
| * * priority: "low" or "normal" | |||||
| * * sources: comma separated list of sources (e.g. "jenkins,user") | |||||
| * * tags: comma separated list of tags (e.g. "tag:value1,tag:value2") | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var now = parseInt(new Date().getTime() / 1000); | |||||
| * var then = now - 3600; // an hour ago | |||||
| * var parameters = { | |||||
| * tags: "some:tag", | |||||
| * sources: "jenkins" | |||||
| * }; | |||||
| * dogapi.event.query(then, now, parameters, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function query(start, end, parameters, callback){ | |||||
| if(arguments.length < 4 && typeof argument[2] === "function"){ | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| /* section: event | |||||
| *comment: | | |||||
| * query the event stream | |||||
| *params: | |||||
| * start: POSIX timestamp for start of query | |||||
| * end: POSIX timestamp for end of query | |||||
| * parameters: | | |||||
| * optional parameters to use for the query | |||||
| * * priority: "low" or "normal" | |||||
| * * sources: comma separated list of sources (e.g. "jenkins,user") | |||||
| * * tags: comma separated list of tags (e.g. "tag:value1,tag:value2") | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const now = parseInt(new Date().getTime() / 1000); | |||||
| * const then = now - 3600; // an hour ago | |||||
| * const parameters = { | |||||
| * tags: "some:tag", | |||||
| * sources: "jenkins" | |||||
| * }; | |||||
| * dogapi.event.query(then, now, parameters, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function query(start, end, parameters, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| } | } | ||||
| if(typeof parameters !== "object"){ | |||||
| parameters = {} | |||||
| if (typeof parameters !== 'object') { | |||||
| parameters = {}; | |||||
| } | } | ||||
| parameters.start = start; | parameters.start = start; | ||||
| parameters.end = end; | parameters.end = end; | ||||
| var params = { | |||||
| query: parameters | |||||
| const params = { | |||||
| query: parameters | |||||
| }; | }; | ||||
| client.request("GET", "/events", params, callback); | |||||
| } | |||||
| client.request('GET', '/events', params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| get: get, | |||||
| query: query, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi event get <event-id>", | |||||
| " dogapi event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]", | |||||
| " dogapi event create <title> <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]" | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| get, | |||||
| query, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi event get <event-id>', | |||||
| ' dogapi event query <from> <to> [--priority <priority>] [--sources <sources>] [--tags <tags>]', | |||||
| ' dogapi event create <title> <text> [--time <timestamp>] [--priority <priority>] [--host <host>] [--tags <tags>] [--type <type>] [--agg-key <agg-key>] [--source <source>]' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Event:", | |||||
| " Subcommands:", | |||||
| " get <event-id> get the event with the provided <event-id>", | |||||
| " query <from> <to> query the event stream between <from> and <to> POSIX timestamps", | |||||
| " create <title> <text> create a new event with <title> and <text>", | |||||
| " Options:", | |||||
| " --priority <priority> the priority of the event \"normal\" or \"low\"", | |||||
| " --sources <sources> a comma separated list of sources (e.g. \"users,jenkins,chef\")", | |||||
| " --tags <tags> a comma separated list of \"tag:value\"'s", | |||||
| " --time <time> a POSIX timestamp for when the event happened", | |||||
| " --host <host> the host to associate the event to", | |||||
| " --type <type> the event type \"error\", \"warning\", \"info\" or \"success\"", | |||||
| " --agg-key <agg-key> an aggregation key to use to associate like events", | |||||
| " --source <source> the source to associate with this event (e.g. \"users\", \"jenkins\", etc)" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Event:', | |||||
| ' Subcommands:', | |||||
| ' get <event-id> get the event with the provided <event-id>', | |||||
| ' query <from> <to> query the event stream between <from> and <to> POSIX timestamps', | |||||
| ' create <title> <text> create a new event with <title> and <text>', | |||||
| ' Options:', | |||||
| ' --priority <priority> the priority of the event "normal" or "low"', | |||||
| ' --sources <sources> a comma separated list of sources (e.g. "users,jenkins,chef")', | |||||
| ' --tags <tags> a comma separated list of "tag:value"\'s', | |||||
| ' --time <time> a POSIX timestamp for when the event happened', | |||||
| ' --host <host> the host to associate the event to', | |||||
| ' --type <type> the event type "error", "warning", "info" or "success"', | |||||
| ' --agg-key <agg-key> an aggregation key to use to associate like events', | |||||
| ' --source <source> the source to associate with this event (e.g. "users", "jenkins", etc)' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "get" && args._.length > 4){ | |||||
| get(parseInt(args._[4]), callback); | |||||
| } else if(subcommand === "query" && args._.length > 5){ | |||||
| var from = parseInt(args._[4]); | |||||
| var to = parseInt(args._[5]); | |||||
| var parameters = {}; | |||||
| if(args["sources"]){ | |||||
| parameters.sources = args["sources"]; | |||||
| } | |||||
| if(args["tags"]){ | |||||
| parameters.tags = args["tags"]; | |||||
| } | |||||
| query(from, to, parameters, callback); | |||||
| } else if(subcommand === "create" && args._.length > 5){ | |||||
| var title = args._[4]; | |||||
| var text = args._[5]; | |||||
| var properties = {}; | |||||
| if(args["priority"]){ | |||||
| properties.priority = args["priority"]; | |||||
| } | |||||
| if(args["host"]){ | |||||
| properties.host = args["host"]; | |||||
| } | |||||
| if(args["time"]){ | |||||
| properties.date_happened = parseInt(args["time"]); | |||||
| } | |||||
| if(args["tags"]){ | |||||
| properties.tags = args["tags"].split(","); | |||||
| } | |||||
| if(args["agg-key"]){ | |||||
| properties.aggregation_key = args["agg-key"]; | |||||
| } | |||||
| if(args["source"]){ | |||||
| properties.source_type_name = args["source"]; | |||||
| } | |||||
| create(title, text, properties, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi event --help` for help", false); | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'get' && args._.length > 4) { | |||||
| get(parseInt(args._[4]), callback); | |||||
| } else if (subcommand === 'query' && args._.length > 5) { | |||||
| const from = parseInt(args._[4]); | |||||
| const to = parseInt(args._[5]); | |||||
| const parameters = {}; | |||||
| if (args.sources) { | |||||
| parameters.sources = args.sources; | |||||
| } | } | ||||
| if (args.tags) { | |||||
| parameters.tags = args.tags; | |||||
| } | |||||
| query(from, to, parameters, callback); | |||||
| } else if (subcommand === 'create' && args._.length > 5) { | |||||
| const title = args._[4]; | |||||
| const text = args._[5]; | |||||
| const properties = {}; | |||||
| if (args.priority) { | |||||
| properties.priority = args.priority; | |||||
| } | |||||
| if (args.host) { | |||||
| properties.host = args.host; | |||||
| } | |||||
| if (args.time) { | |||||
| properties.date_happened = parseInt(args.time); | |||||
| } | |||||
| if (args.tags) { | |||||
| properties.tags = args.tags.split(','); | |||||
| } | |||||
| if (args['agg-key']) { | |||||
| properties.aggregation_key = args['agg-key']; | |||||
| } | |||||
| if (args.source) { | |||||
| properties.source_type_name = args.source; | |||||
| } | |||||
| create(title, text, properties, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi event --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,75 +1,79 @@ | |||||
| var client = require("../client"); | |||||
| var embed = require("./embed"); | |||||
| const Embed = require('./embed'); | |||||
| /*section: graph | |||||
| *comment: take a snapshot of a metric query | |||||
| *params: | |||||
| * query: the metric query to use for the snapshot | |||||
| * from: POSIX timestamp for the beginning of the query | |||||
| * to: POSIX timestamp for the end of the query | |||||
| * eventQuery: optional, an event query to overlay event bands on the snapshot | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var query = "system.cpu.idle{*}"; | |||||
| * var to = dogapi.now(); | |||||
| * var from = to - 3600; // an hour ago | |||||
| * dogapi.graph.snapshot(query, from, to, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function snapshot(query, from, to, eventQuery, callback){ | |||||
| if(arguments.length < 5 && typeof arguments[3] === "function"){ | |||||
| callback = eventQuery; | |||||
| eventQuery = undefined; | |||||
| module.exports = function(client) { | |||||
| const embed = Embed(client); | |||||
| /* section: graph | |||||
| *comment: take a snapshot of a metric query | |||||
| *params: | |||||
| * query: the metric query to use for the snapshot | |||||
| * from: POSIX timestamp for the beginning of the query | |||||
| * to: POSIX timestamp for the end of the query | |||||
| * eventQuery: optional, an event query to overlay event bands on the snapshot | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const query = "system.cpu.idle{*}"; | |||||
| * const to = dogapi.now(); | |||||
| * const from = to - 3600; // an hour ago | |||||
| * dogapi.graph.snapshot(query, from, to, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function snapshot(query, from, to, eventQuery, callback) { | |||||
| if (arguments.length < 5 && typeof arguments[3] === 'function') { | |||||
| callback = eventQuery; | |||||
| eventQuery = undefined; | |||||
| } | } | ||||
| var params = { | |||||
| query: { | |||||
| metric_query: query, | |||||
| start: parseInt(from), | |||||
| end: parseInt(to) | |||||
| } | |||||
| const params = { | |||||
| query: { | |||||
| metric_query: query, | |||||
| start: parseInt(from), | |||||
| end: parseInt(to) | |||||
| } | |||||
| }; | }; | ||||
| if(eventQuery){ | |||||
| params.query.event_query = eventQuery; | |||||
| if (eventQuery) { | |||||
| params.query.event_query = eventQuery; | |||||
| } | } | ||||
| client.request("GET", "/graph/snapshot", params, callback); | |||||
| } | |||||
| client.request('GET', '/graph/snapshot', params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| snapshot: snapshot, | |||||
| return { | |||||
| snapshot, | |||||
| createEmbed: embed.create, | createEmbed: embed.create, | ||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi graph snapshot <query> <from> <to> [--events <event-query>]" | |||||
| ]; | |||||
| getUsage() { | |||||
| return [' dogapi graph snapshot <query> <from> <to> [--events <event-query>]']; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Graph:", | |||||
| " Subcommands:", | |||||
| " snapshot <query> <from> <to> --events <event-query> | take a snapshot of a graph", | |||||
| " Options:", | |||||
| " --events <event-query> a query for event bands to add to the snapshot" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Graph:', | |||||
| ' Subcommands:', | |||||
| ' snapshot <query> <from> <to> --events <event-query> | take a snapshot of a graph', | |||||
| ' Options:', | |||||
| ' --events <event-query> a query for event bands to add to the snapshot' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if (args._.length > 5 && subcommand === "snapshot"){ | |||||
| var query = args._[4]; | |||||
| var from = parseInt(args._[5]); | |||||
| var to = parseInt(args._[6]); | |||||
| var eventQuery = args["events"]; | |||||
| snapshot(query, from, to, eventQuery, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); | |||||
| } | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (args._.length > 5 && subcommand === 'snapshot') { | |||||
| const query = args._[4]; | |||||
| const from = parseInt(args._[5]); | |||||
| const to = parseInt(args._[6]); | |||||
| const eventQuery = args.events; | |||||
| snapshot(query, from, to, eventQuery, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi graph --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,108 +1,109 @@ | |||||
| var client = require("../client"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| /*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 = {}; | |||||
| module.exports = function(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 | |||||
| * const dogapi = require("dogapi"); | |||||
| * const 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 = {}; | |||||
| if(typeof options === "object"){ | |||||
| params.body = {}; // create body property | |||||
| if(options.end){ | |||||
| params.body.end = parseInt(options.end); | |||||
| } | |||||
| if(options.override){ | |||||
| params.body.override = options.override; | |||||
| } | |||||
| const params = {}; | |||||
| if (typeof options === 'object') { | |||||
| params.body = {}; // create body property | |||||
| if (options.end) { | |||||
| params.body.end = parseInt(options.end); | |||||
| } | |||||
| if (options.override) { | |||||
| params.body.override = options.override; | |||||
| } | |||||
| } else { | } else { | ||||
| params.body = ""; // create empty body | |||||
| params.body = ''; // create empty body | |||||
| } | } | ||||
| client.request("POST", util.format("/host/%s/mute", hostname), params, callback); | |||||
| } | |||||
| client.request('POST', util.format('/host/%s/mute', hostname), 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: ""}; // create empty body | |||||
| client.request("POST", util.format("/host/%s/unmute", hostname), 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 | |||||
| * const dogapi = require("dogapi"); | |||||
| * const 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) { | |||||
| const params = {body: ''}; // create empty body | |||||
| client.request('POST', util.format('/host/%s/unmute', hostname), params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| mute: mute, | |||||
| unmute: unmute, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi host mute <host> [--end <end>] [--override]", | |||||
| " dogapi host unmute <host>" | |||||
| ]; | |||||
| return { | |||||
| mute, | |||||
| unmute, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi host mute <host> [--end <end>] [--override]', | |||||
| ' dogapi 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" | |||||
| ]; | |||||
| getHelp() { | |||||
| 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); | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'mute') { | |||||
| const hostname = args._[4]; | |||||
| const options = {}; | |||||
| if (args.end) { | |||||
| options.end = parseInt(args.end); | |||||
| } | |||||
| if (args.override) { | |||||
| options.override = args.override; | |||||
| } | } | ||||
| mute(hostname, options, callback); | |||||
| } else if (subcommand === 'unmute') { | |||||
| const hostname = args._[4]; | |||||
| unmute(hostname, callback); | |||||
| } else { | |||||
| return callback('unknown subcommand or arguments try `dogapi host --help` for help', false); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,23 +1,17 @@ | |||||
| var api = { | |||||
| comment: require("./comment"), | |||||
| downtime: require("./downtime"), | |||||
| embed: require("./embed"), | |||||
| event: require("./event"), | |||||
| graph: require("./graph"), | |||||
| host: require("./host"), | |||||
| infrastructure: require("./infrastructure"), | |||||
| metric: require("./metric"), | |||||
| monitor: require("./monitor"), | |||||
| screenboard: require("./screenboard"), | |||||
| search: require("./search"), | |||||
| serviceCheck: require("./serviceCheck"), | |||||
| tag: require("./tag"), | |||||
| timeboard: require("./timeboard"), | |||||
| user: require("./user"), | |||||
| }; | |||||
| module.exports = function(obj){ | |||||
| for(var key in api){ | |||||
| obj[key] = api[key]; | |||||
| } | |||||
| module.exports = { | |||||
| comment: require('./comment'), | |||||
| downtime: require('./downtime'), | |||||
| embed: require('./embed'), | |||||
| event: require('./event'), | |||||
| graph: require('./graph'), | |||||
| host: require('./host'), | |||||
| infrastructure: require('./infrastructure'), | |||||
| metric: require('./metric'), | |||||
| monitor: require('./monitor'), | |||||
| screenboard: require('./screenboard'), | |||||
| search: require('./search'), | |||||
| serviceCheck: require('./service-check'), | |||||
| tag: require('./tag'), | |||||
| timeboard: require('./timeboard'), | |||||
| user: require('./user') | |||||
| }; | }; | ||||
| @ -1,52 +1,49 @@ | |||||
| var client = require("../client"); | |||||
| /*section: infrastructure | |||||
| *comment: | | |||||
| * search for metrics or hosts | |||||
| *params: | |||||
| * query: | | |||||
| * the query to use for search see [datadog docs](http://docs.datadoghq.com/api/#search) | |||||
| * for examples of the query (e.g. "hosts:database", "metrics:system" or "test") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.infrastructure.search("hosts:database", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function search(query, callback){ | |||||
| var params = { | |||||
| query: { | |||||
| q: query | |||||
| } | |||||
| module.exports = function(client) { | |||||
| /* section: infrastructure | |||||
| *comment: | | |||||
| * search for metrics or hosts | |||||
| *params: | |||||
| * query: | | |||||
| * the query to use for search see [datadog docs](http://docs.datadoghq.com/api/#search) | |||||
| * for examples of the query (e.g. "hosts:database", "metrics:system" or "test") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.infrastructure.search("hosts:database", function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function search(query, callback) { | |||||
| const params = { | |||||
| query: { | |||||
| q: query | |||||
| } | |||||
| }; | }; | ||||
| client.request("GET", "/search", params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| search: search, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi infrastructure search <query>" | |||||
| ] | |||||
| client.request('GET', '/search', params, callback); | |||||
| } | |||||
| return { | |||||
| search, | |||||
| getUsage() { | |||||
| return [' dogapi infrastructure search <query>']; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Infrastructure:", | |||||
| " Subcommands:", | |||||
| " search <query> query for hosts or metrics with <query> (see http://docs.datadoghq.com/api/#search)", | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Infrastructure:', | |||||
| ' Subcommands:', | |||||
| ' search <query> query for hosts or metrics with <query> (see http://docs.datadoghq.com/api/#search)' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| var query = args._[4]; | |||||
| search(query, callback); | |||||
| handleCli(subcommand, args, callback) { | |||||
| const query = args._[4]; | |||||
| search(query, callback); | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,220 +1,222 @@ | |||||
| var client = require("../client"); | |||||
| /*section: metric | |||||
| *comment: | | |||||
| * submit a new metric | |||||
| *params: | |||||
| * metric: the metric name | |||||
| * points: | | |||||
| * a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) | |||||
| * or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) | |||||
| * extra: | | |||||
| * optional, object which can contain the following keys | |||||
| * * host: the host source of the metric | |||||
| * * tags: array of "tag:value"'s to use for the metric | |||||
| * * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.metric.send("my.metric", 1000, function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * var now = parseInt(new Date().getTime() / 1000); | |||||
| * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function send(metric, points, extra, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = extra; | |||||
| extra = {}; | |||||
| } | |||||
| extra = extra || {}; | |||||
| var series = [ | |||||
| { | |||||
| metric: metric, | |||||
| points: points, | |||||
| host: extra.host, | |||||
| tags: extra.tags, | |||||
| // DEV: For backwards compatibility, allow `metric_type` | |||||
| type: extra.type || extra.metric_type | |||||
| module.exports = function(client) { | |||||
| /* section: metric | |||||
| *comment: | | |||||
| * send a list of metrics | |||||
| *params: | |||||
| * metrics: | | |||||
| * an array of metrics where each element is an object with the following keys | |||||
| * * metric: the name of the metric | |||||
| * * points: a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) | |||||
| * * tags: an array of "tag:value"'s | |||||
| * * host: the source hostname to use for the metrics | |||||
| * * metric_type|type: the type of metric to use ("gauge" or "count") [default: gauge] | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const now = parseInt(new Date().getTime() / 1000); | |||||
| * const metrics = [ | |||||
| * { | |||||
| * metric: "my.metric", | |||||
| * points: [[now, 1000]], | |||||
| * tags: ["tag:value"] | |||||
| * }, | |||||
| * { | |||||
| * metric: "another.metric", | |||||
| * points: [50, 1000] | |||||
| * }, | |||||
| * { | |||||
| * metric: "another.metric", | |||||
| * points: 1000 | |||||
| * } | |||||
| * ]; | |||||
| * dogapi.metric.send_all(metrics, function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function send_all(metrics, callback) { | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| for (let i = 0; i < metrics.length; ++i) { | |||||
| // Try to normalize `points` | |||||
| // DEV: We need `points` to be an array of arrays regardless of what they give us | |||||
| // Always wrap points in an array, this way we will get: | |||||
| // 500 => [500] | |||||
| // [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]] | |||||
| // [[<timestamp>, 500]] => [[<timestamp>, 500]] | |||||
| let points = metrics[i].points; | |||||
| if (!Array.isArray(metrics[i].points)) { | |||||
| points = [points]; | |||||
| } | |||||
| points = points.map(function(point) { | |||||
| // Make sure each point is an array, if not make array with current timestamp | |||||
| // 500 => [<timestamp>, 500] | |||||
| // [<timestamp>, 500] => unchanged | |||||
| if (!Array.isArray(point)) { | |||||
| point = [now, point]; | |||||
| } | } | ||||
| ]; | |||||
| return point; | |||||
| }); | |||||
| send_all(series, callback); | |||||
| } | |||||
| metrics[i].points = points; | |||||
| /*section: metric | |||||
| *comment: | | |||||
| * send a list of metrics | |||||
| *params: | |||||
| * metrics: | | |||||
| * an array of metrics where each element is an object with the following keys | |||||
| * * metric: the name of the metric | |||||
| * * points: a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) | |||||
| * * tags: an array of "tag:value"'s | |||||
| * * host: the source hostname to use for the metrics | |||||
| * * metric_type|type: the type of metric to use ("gauge" or "count") [default: gauge] | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var now = parseInt(new Date().getTime() / 1000); | |||||
| * var metrics = [ | |||||
| * { | |||||
| * metric: "my.metric", | |||||
| * points: [[now, 1000]], | |||||
| * tags: ["tag:value"] | |||||
| * }, | |||||
| * { | |||||
| * metric: "another.metric", | |||||
| * points: [50, 1000] | |||||
| * }, | |||||
| * { | |||||
| * metric: "another.metric", | |||||
| * points: 1000 | |||||
| * } | |||||
| * ]; | |||||
| * dogapi.metric.send_all(metrics, function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function send_all(metrics, callback){ | |||||
| var now = parseInt(new Date().getTime() / 1000); | |||||
| for(var i = 0; i < metrics.length; ++i){ | |||||
| // Try to normalize `points` | |||||
| // DEV: We need `points` to be an array of arrays regardless of what they give us | |||||
| // Always wrap points in an array, this way we will get: | |||||
| // 500 => [500] | |||||
| // [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]] | |||||
| // [[<timestamp>, 500]] => [[<timestamp>, 500]] | |||||
| var points = metrics[i].points; | |||||
| if(!Array.isArray(metrics[i].points)){ | |||||
| points = [points]; | |||||
| } | |||||
| points = points.map(function(point){ | |||||
| // Make sure each point is an array, if not make array with current timestamp | |||||
| // 500 => [<timestamp>, 500] | |||||
| // [<timestamp>, 500] => unchanged | |||||
| if(!Array.isArray(point)){ | |||||
| var now = parseInt(new Date().getTime() / 1000); | |||||
| point = [now, point]; | |||||
| } | |||||
| return point; | |||||
| }); | |||||
| // DEV: Change `metric_type` to `type` for backwards compatibility | |||||
| metrics[i].type = metrics[i].type || metrics[i].metric_type; | |||||
| // Remove `metric_type` if it was set | |||||
| // DEV: This will not cause an error if `metric_type` does not exist | |||||
| delete metrics[i].metric_type; | |||||
| } | |||||
| metrics[i].points = points; | |||||
| const params = { | |||||
| body: { | |||||
| series: metrics | |||||
| } | |||||
| }; | |||||
| client.request('POST', '/series', params, callback); | |||||
| } | |||||
| // DEV: Change `metric_type` to `type` for backwards compatibility | |||||
| metrics[i].type = metrics[i].type || metrics[i].metric_type; | |||||
| // Remove `metric_type` if it was set | |||||
| // DEV: This will not cause an error if `metric_type` does not exist | |||||
| delete metrics[i].metric_type; | |||||
| /* section: metric | |||||
| *comment: | | |||||
| * submit a new metric | |||||
| *params: | |||||
| * metric: the metric name | |||||
| * points: | | |||||
| * a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) | |||||
| * or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) | |||||
| * extra: | | |||||
| * optional, object which can contain the following keys | |||||
| * * host: the host source of the metric | |||||
| * * tags: array of "tag:value"'s to use for the metric | |||||
| * * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] | |||||
| * callback: | | |||||
| * function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.metric.send("my.metric", 1000, function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * dogapi.metric.send("my.metric", [500, 1000], function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * const now = parseInt(new Date().getTime() / 1000); | |||||
| * dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function send(metric, points, extra, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = extra; | |||||
| extra = {}; | |||||
| } | } | ||||
| extra = extra || {}; | |||||
| const series = [ | |||||
| { | |||||
| metric, | |||||
| points, | |||||
| host: extra.host, | |||||
| tags: extra.tags, | |||||
| // DEV: For backwards compatibility, allow `metric_type` | |||||
| type: extra.type || extra.metric_type | |||||
| } | |||||
| ]; | |||||
| var params = { | |||||
| body: { | |||||
| series: metrics | |||||
| } | |||||
| }; | |||||
| client.request("POST", "/series", params, callback); | |||||
| } | |||||
| send_all(series, callback); | |||||
| } | |||||
| /*section: metric | |||||
| *comment: | | |||||
| * make a metric query | |||||
| *params: | |||||
| * from: POSIX timestamp for start of query | |||||
| * to: POSIX timestamp for end of query | |||||
| * query: the string query to perform (e.g. "system.cpu.idle{*}by{host}") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var now = parseInt(new Date().getTime() / 1000); | |||||
| * var then = now - 3600; // one hour ago | |||||
| * var query = "system.cpu.idle{*}by{host}"; | |||||
| * dogapi.metric.query(then, now, query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function query(from, to, query, callback){ | |||||
| var params = { | |||||
| query: { | |||||
| from: from, | |||||
| to: to, | |||||
| query: query | |||||
| } | |||||
| /* section: metric | |||||
| *comment: | | |||||
| * make a metric query | |||||
| *params: | |||||
| * from: POSIX timestamp for start of query | |||||
| * to: POSIX timestamp for end of query | |||||
| * q: the string query to perform (e.g. "system.cpu.idle{*}by{host}") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const now = parseInt(new Date().getTime() / 1000); | |||||
| * const then = now - 3600; // one hour ago | |||||
| * const query = "system.cpu.idle{*}by{host}"; | |||||
| * dogapi.metric.query(then, now, query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function query(from, to, q, callback) { | |||||
| const params = { | |||||
| query: { | |||||
| from, | |||||
| to, | |||||
| query: q | |||||
| } | |||||
| }; | }; | ||||
| client.request("GET", "/query", params, callback); | |||||
| } | |||||
| client.request('GET', '/query', params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| send: send, | |||||
| send_all: send_all, | |||||
| query: query, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi metric send <metric> <point> [--tags <tags>] [--host <host>] [--type <type>]", | |||||
| " dogapi metric query <from> <to> <query>" | |||||
| ] | |||||
| return { | |||||
| send, | |||||
| send_all, | |||||
| query, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi metric send <metric> <point> [--tags <tags>] [--host <host>] [--type <type>]', | |||||
| ' dogapi metric query <from> <to> <query>' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Metric:", | |||||
| " Subcommands:", | |||||
| " send <metric> <point> add a new datapoint for <metric> for right now", | |||||
| " query <from> <to> <query> query for <query> between <from> and <to> POSIX timestamps", | |||||
| "", | |||||
| " Options:", | |||||
| " --tags <tags> a comma separated list of \"tag:value\"'s", | |||||
| " --host <host> the hostname that should be associated with this metric", | |||||
| " --type <type> the type of metric \"gauge\" or \"count\"" | |||||
| ] | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Metric:', | |||||
| ' Subcommands:', | |||||
| ' send <metric> <point> add a new datapoint for <metric> for right now', | |||||
| ' query <from> <to> <query> query for <query> between <from> and <to> POSIX timestamps', | |||||
| '', | |||||
| ' Options:', | |||||
| ' --tags <tags> a comma separated list of "tag:value"\'s', | |||||
| ' --host <host> the hostname that should be associated with this metric', | |||||
| ' --type <type> the type of metric "gauge" or "count"' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(args._.length > 5 && subcommand === "send"){ | |||||
| var extra = {}; | |||||
| if(args.tags){ | |||||
| extra.tags = args.tags.split(","); | |||||
| } | |||||
| extra.host = args.host; | |||||
| extra.type = args.type; | |||||
| send(args._[4], args._[5], extra, callback); | |||||
| } else if(subcommand === "query" && args._.length > 6){ | |||||
| var from = parseInt(args._[4]); | |||||
| var to = parseInt(args._[5]); | |||||
| var q = args._[6]; | |||||
| query(from, to, q, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (args._.length > 5 && subcommand === 'send') { | |||||
| const extra = {}; | |||||
| if (args.tags) { | |||||
| extra.tags = args.tags.split(','); | |||||
| } | } | ||||
| extra.host = args.host; | |||||
| extra.type = args.type; | |||||
| send(args._[4], args._[5], extra, callback); | |||||
| } else if (subcommand === 'query' && args._.length > 6) { | |||||
| const from = parseInt(args._[4]); | |||||
| const to = parseInt(args._[5]); | |||||
| const q = args._[6]; | |||||
| query(from, to, q, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi metric --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,454 +1,451 @@ | |||||
| var client = require("../client"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| /*section: monitor | |||||
| *comment: create a new monitor | |||||
| *params: | |||||
| * type: one of "metric alert" or "service check" | |||||
| * query: the monitor query to use, you probably want to read datadog's [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * name: the name of the monitor | |||||
| * * message: the message for the monitor | |||||
| * * tags: a list of strings as tags to associate with the monitor | |||||
| * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var metricType = "metric alert"; | |||||
| * var query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; | |||||
| * dogapi.monitor.create(metricType, query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(type, query, properties, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| module.exports = function(client) { | |||||
| /* section: monitor | |||||
| *comment: create a new monitor | |||||
| *params: | |||||
| * type: one of "metric alert" or "service check" | |||||
| * query: the monitor query to use, you probably want to read datadog's [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * name: the name of the monitor | |||||
| * * message: the message for the monitor | |||||
| * * tags: a list of strings as tags to associate with the monitor | |||||
| * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const metricType = "metric alert"; | |||||
| * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; | |||||
| * dogapi.monitor.create(metricType, query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(type, query, properties, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| type: type, | |||||
| query: query | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| type, | |||||
| query | |||||
| } | |||||
| }; | }; | ||||
| if(typeof properties === "object"){ | |||||
| if(properties.name){ | |||||
| params.body.name = properties.name; | |||||
| } | |||||
| if(properties.message){ | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| if(properties.tags){ | |||||
| params.body.tags = properties.tags; | |||||
| } | |||||
| if(typeof properties.options === "object"){ | |||||
| params.body.options = properties.options; | |||||
| } | |||||
| if (typeof properties === 'object') { | |||||
| if (properties.name) { | |||||
| params.body.name = properties.name; | |||||
| } | |||||
| if (properties.message) { | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| if (properties.tags) { | |||||
| params.body.tags = properties.tags; | |||||
| } | |||||
| if (typeof properties.options === 'object') { | |||||
| params.body.options = properties.options; | |||||
| } | |||||
| } | } | ||||
| client.request("POST", "/monitor", params, callback); | |||||
| } | |||||
| client.request('POST', '/monitor', params, callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: get an existing monitor's details | |||||
| *params: | |||||
| * monitorId: the id of the monitor | |||||
| * groupStates: an array containing any of the following "all", "alert", "warn", or "no data" | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(monitorId, groupStates, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = groupStates; | |||||
| groupStates = undefined; | |||||
| /* section: monitor | |||||
| *comment: get an existing monitor's details | |||||
| *params: | |||||
| * monitorId: the id of the monitor | |||||
| * groupStates: an array containing any of the following "all", "alert", "warn", or "no data" | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(monitorId, groupStates, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = groupStates; | |||||
| groupStates = undefined; | |||||
| } | } | ||||
| var params = {}; | |||||
| if(groupStates){ | |||||
| params.query = { | |||||
| group_states: groupStates.join(",") | |||||
| }; | |||||
| const params = {}; | |||||
| if (groupStates) { | |||||
| params.query = { | |||||
| group_states: groupStates.join(',') | |||||
| }; | |||||
| } | } | ||||
| client.request("GET", util.format("/monitor/%s", monitorId), params, callback); | |||||
| } | |||||
| client.request('GET', util.format('/monitor/%s', monitorId), params, callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: get all monitors | |||||
| *params: | |||||
| * options: | | |||||
| * optional, an object containing any of the following | |||||
| * * group_states: an array containing any of the following "all", "alert", "warn", or "no data" | |||||
| * * tags: an array of "tag:value"'s to filter on | |||||
| * * monitor_tags: a comma separated list indicating what service and/or custom tags | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(options, callback){ | |||||
| if(arguments.length < 2 && typeof arguments[0] === "function"){ | |||||
| callback = options; | |||||
| options = {}; | |||||
| /* section: monitor | |||||
| *comment: get all monitors | |||||
| *params: | |||||
| * options: | | |||||
| * optional, an object containing any of the following | |||||
| * * group_states: an array containing any of the following "all", "alert", "warn", or "no data" | |||||
| * * tags: an array of "tag:value"'s to filter on | |||||
| * * monitor_tags: a comma separated list indicating what service and/or custom tags | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(options, callback) { | |||||
| if (arguments.length < 2 && typeof arguments[0] === 'function') { | |||||
| callback = options; | |||||
| options = {}; | |||||
| } | } | ||||
| var params = {}; | |||||
| if(typeof options === "object"){ | |||||
| params.query = {}; | |||||
| if(options.group_states){ | |||||
| params.query.group_states = options.group_states.join(","); | |||||
| } | |||||
| if(options.tags){ | |||||
| params.query.tags = options.tags.join(","); | |||||
| } | |||||
| if(options.monitor_tags){ | |||||
| params.query.monitor_tags = options.monitor_tags.join(","); | |||||
| } | |||||
| const params = {}; | |||||
| if (typeof options === 'object') { | |||||
| params.query = {}; | |||||
| if (options.group_states) { | |||||
| params.query.group_states = options.group_states.join(','); | |||||
| } | |||||
| if (options.tags) { | |||||
| params.query.tags = options.tags.join(','); | |||||
| } | |||||
| if (options.monitor_tags) { | |||||
| params.query.monitor_tags = options.monitor_tags.join(','); | |||||
| } | |||||
| } | } | ||||
| client.request("GET", "/monitor", params, callback); | |||||
| } | |||||
| client.request('GET', '/monitor', params, callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: update a monitor's details | |||||
| *params: | |||||
| * monitorId: the id of the monitor to edit | |||||
| * query: the query that the monitor should have, see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs for more info | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * name: the name of the monitor | |||||
| * * message: the message for the monitor | |||||
| * * tags: a list of strings as tags to associate with the monitor | |||||
| * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; | |||||
| * dogapi.monitor.update(1234, query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(monitorId, query, properties, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| /* section: monitor | |||||
| *comment: update a monitor's details | |||||
| *params: | |||||
| * monitorId: the id of the monitor to edit | |||||
| * query: the query that the monitor should have, see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs for more info | |||||
| * properties: | | |||||
| * optional, an object containing any of the following | |||||
| * * name: the name of the monitor | |||||
| * * message: the message for the monitor | |||||
| * * tags: a list of strings as tags to associate with the monitor | |||||
| * * options: an object, to see available options please see the [monitor create](http://docs.datadoghq.com/api/#monitor-create) docs | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100"; | |||||
| * dogapi.monitor.update(1234, query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(monitorId, query, properties, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = properties; | |||||
| properties = {}; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| query: query | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| query | |||||
| } | |||||
| }; | }; | ||||
| if(typeof properties === "object"){ | |||||
| if(properties.name){ | |||||
| params.body.name = properties.name; | |||||
| } | |||||
| if(properties.message){ | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| if(properties.tags){ | |||||
| params.body.tags = properties.tags; | |||||
| } | |||||
| if(typeof properties.options === "object"){ | |||||
| params.body.options = properties.options; | |||||
| } | |||||
| if (typeof properties === 'object') { | |||||
| if (properties.name) { | |||||
| params.body.name = properties.name; | |||||
| } | |||||
| if (properties.message) { | |||||
| params.body.message = properties.message; | |||||
| } | |||||
| if (properties.tags) { | |||||
| params.body.tags = properties.tags; | |||||
| } | |||||
| if (typeof properties.options === 'object') { | |||||
| params.body.options = properties.options; | |||||
| } | |||||
| } | } | ||||
| client.request("PUT", util.format("/monitor/%s", monitorId), params, callback); | |||||
| } | |||||
| client.request('PUT', util.format('/monitor/%s', monitorId), params, callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: delete an existing monitor | |||||
| *params: | |||||
| * monitorId: the id of the monitor to remove | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(monitorId, callback){ | |||||
| client.request("DELETE", util.format("/monitor/%s", monitorId), callback); | |||||
| } | |||||
| /* section: monitor | |||||
| *comment: delete an existing monitor | |||||
| *params: | |||||
| * monitorId: the id of the monitor to remove | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(monitorId, callback) { | |||||
| client.request('DELETE', util.format('/monitor/%s', monitorId), callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: mute an existing monitor | |||||
| *params: | |||||
| * monitorId: the id of the monitor to mute | |||||
| * options: | | |||||
| * optional, an object containing any of the following | |||||
| * * scope: the scope to mute (e.g. "role:db") | |||||
| * * end: POSIX timestamp indicating when the mute should end | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.mute(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function mute(monitorId, options, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = options; | |||||
| options = {}; | |||||
| /* section: monitor | |||||
| *comment: mute an existing monitor | |||||
| *params: | |||||
| * monitorId: the id of the monitor to mute | |||||
| * options: | | |||||
| * optional, an object containing any of the following | |||||
| * * scope: the scope to mute (e.g. "role:db") | |||||
| * * end: POSIX timestamp indicating when the mute should end | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.mute(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function mute(monitorId, options, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = options; | |||||
| options = {}; | |||||
| } | } | ||||
| var params = {}; | |||||
| if(typeof options === "object"){ | |||||
| params.body = {}; | |||||
| if(options.scope){ | |||||
| params.body.scope = options.scope; | |||||
| } | |||||
| if(options.end){ | |||||
| params.body.end = parseInt(options.end); | |||||
| } | |||||
| const params = {}; | |||||
| if (typeof options === 'object') { | |||||
| params.body = {}; | |||||
| if (options.scope) { | |||||
| params.body.scope = options.scope; | |||||
| } | |||||
| if (options.end) { | |||||
| params.body.end = parseInt(options.end); | |||||
| } | |||||
| } else { | } else { | ||||
| params.body = ""; // create empty body | |||||
| params.body = ''; // create empty body | |||||
| } | } | ||||
| client.request("POST", util.format("/monitor/%s/mute", monitorId), params, callback); | |||||
| } | |||||
| client.request('POST', util.format('/monitor/%s/mute', monitorId), params, callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: mute all monitors | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.muteAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function muteAll(callback){ | |||||
| client.request("POST", "/monitor/mute_all", callback); | |||||
| } | |||||
| /* section: monitor | |||||
| *comment: mute all monitors | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.muteAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function muteAll(callback) { | |||||
| client.request('POST', '/monitor/mute_all', callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: unmute an existing monitor | |||||
| *params: | |||||
| * monitorId: the id of the monitor to unmute | |||||
| * scope: optional, a scope to apply the unmute to (e.g. "role:db") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.unmute(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function unmute(monitorId, scope, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = scope; | |||||
| scope = undefined; | |||||
| /* section: monitor | |||||
| *comment: unmute an existing monitor | |||||
| *params: | |||||
| * monitorId: the id of the monitor to unmute | |||||
| * scope: optional, a scope to apply the unmute to (e.g. "role:db") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.unmute(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function unmute(monitorId, scope, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = scope; | |||||
| scope = undefined; | |||||
| } | } | ||||
| var params = {}; | |||||
| if(scope){ | |||||
| params.body = { | |||||
| scope: scope | |||||
| }; | |||||
| const params = {}; | |||||
| if (scope) { | |||||
| params.body = { | |||||
| scope | |||||
| }; | |||||
| } else { | } else { | ||||
| params.body = ""; // create empty body | |||||
| params.body = ''; // create empty body | |||||
| } | } | ||||
| client.request("POST", util.format("/monitor/%s/unmute", monitorId), params, callback); | |||||
| } | |||||
| client.request('POST', util.format('/monitor/%s/unmute', monitorId), params, callback); | |||||
| } | |||||
| /*section: monitor | |||||
| *comment: unmute all monitors | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.unmuteAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function unmuteAll(callback){ | |||||
| client.request("POST", "/monitor/unmute_all", callback); | |||||
| } | |||||
| /* section: monitor | |||||
| *comment: unmute all monitors | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.monitor.unmuteAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function unmuteAll(callback) { | |||||
| client.request('POST', '/monitor/unmute_all', callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| get: get, | |||||
| update: update, | |||||
| remove: remove, | |||||
| getAll: getAll, | |||||
| mute: mute, | |||||
| muteAll: muteAll, | |||||
| unmute: unmute, | |||||
| unmuteAll: unmuteAll, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi monitor create <type> <query> [--name <name>] [--message <message>]", | |||||
| " dogapi monitor get <monitor-id> [--states <states>]", | |||||
| " dogapi monitor getall [--states <states>] [--tags <tags>]", | |||||
| " dogapi monitor mute <monitor-id> [--scope <scope>] [--end <end>]", | |||||
| " dogapi monitor muteall", | |||||
| " dogapi monitor remove <monitor-id>", | |||||
| " dogapi monitor unmute <monitor-id> [--scope <scope>]", | |||||
| " dogapi monitor unmuteall", | |||||
| " dogapi monitor update <monitor-id> <query> [--name <name>] [--message <message>]" | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| get, | |||||
| update, | |||||
| remove, | |||||
| getAll, | |||||
| mute, | |||||
| muteAll, | |||||
| unmute, | |||||
| unmuteAll, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi monitor create <type> <query> [--name <name>] [--message <message>]', | |||||
| ' dogapi monitor get <monitor-id> [--states <states>]', | |||||
| ' dogapi monitor getall [--states <states>] [--tags <tags>]', | |||||
| ' dogapi monitor mute <monitor-id> [--scope <scope>] [--end <end>]', | |||||
| ' dogapi monitor muteall', | |||||
| ' dogapi monitor remove <monitor-id>', | |||||
| ' dogapi monitor unmute <monitor-id> [--scope <scope>]', | |||||
| ' dogapi monitor unmuteall', | |||||
| ' dogapi monitor update <monitor-id> <query> [--name <name>] [--message <message>]' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Monitor:", | |||||
| " Subcommands:", | |||||
| " create <type> <query> create a new monitor", | |||||
| " get <monitor-id> get a monitors details", | |||||
| " getall get a list of all monitors", | |||||
| " mute <monitor-id> mute the monitor with the id <monitor-id>", | |||||
| " muteall mute all monitors", | |||||
| " remove <monitor-id> delete the monitor with the id <monitor-id>", | |||||
| " unmute <monitor-id> unmute the monitor with the id <monitor-id>", | |||||
| " unmuteall unmute all monitors", | |||||
| " update <monitor-id> <query> update an existing monitor", | |||||
| "", | |||||
| " Options:", | |||||
| " --states <states> a comma separated list containing any of \"all\", \"alert\", \"warn\", or \"no data\"", | |||||
| " --tags <tags> a comma separated list of \"tag:value\"'s", | |||||
| " --scope <scope> the scope of the monitor to mute (e.g. \"role:db\")", | |||||
| " --end <end> POSIX timestamp for when the mute should end", | |||||
| " --name <name> the name for the monitor", | |||||
| " --message <message> the message for the monitor" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Monitor:', | |||||
| ' Subcommands:', | |||||
| ' create <type> <query> create a new monitor', | |||||
| ' get <monitor-id> get a monitors details', | |||||
| ' getall get a list of all monitors', | |||||
| ' mute <monitor-id> mute the monitor with the id <monitor-id>', | |||||
| ' muteall mute all monitors', | |||||
| ' remove <monitor-id> delete the monitor with the id <monitor-id>', | |||||
| ' unmute <monitor-id> unmute the monitor with the id <monitor-id>', | |||||
| ' unmuteall unmute all monitors', | |||||
| ' update <monitor-id> <query> update an existing monitor', | |||||
| '', | |||||
| ' Options:', | |||||
| ' --states <states> a comma separated list containing any of "all", "alert", "warn", or "no data"', | |||||
| ' --tags <tags> a comma separated list of "tag:value"\'s', | |||||
| ' --scope <scope> the scope of the monitor to mute (e.g. "role:db")', | |||||
| ' --end <end> POSIX timestamp for when the mute should end', | |||||
| ' --name <name> the name for the monitor', | |||||
| ' --message <message> the message for the monitor' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| var states = []; | |||||
| if(args["states"]){ | |||||
| states = args["states"].split(","); | |||||
| } | |||||
| handleCli(subcommand, args, callback) { | |||||
| const states = args.states ? args.states.split(',') : []; | |||||
| const tags = args.tags ? args.tags.split(',') : []; | |||||
| var tags = []; | |||||
| if(args["tags"]){ | |||||
| tags = args["tags"].split(","); | |||||
| } | |||||
| var name = args["name"]; | |||||
| var message = args["message"]; | |||||
| const name = args.name; | |||||
| const message = args.message; | |||||
| if(subcommand === "get"){ | |||||
| var monitorId = args._[4]; | |||||
| get(monitorId, states, callback); | |||||
| } else if(subcommand === "getall"){ | |||||
| var options = {}; | |||||
| if(states.length){ | |||||
| options.group_states = states; | |||||
| } | |||||
| if(tags.length){ | |||||
| options.tags = tags; | |||||
| } | |||||
| getAll(options, callback); | |||||
| } else if(subcommand === "mute"){ | |||||
| var monitorId = args._[4]; | |||||
| var options = {}; | |||||
| if(args["scope"]){ | |||||
| options.scope = args["scope"]; | |||||
| } | |||||
| if(args["end"]){ | |||||
| options.end = args["end"]; | |||||
| } | |||||
| mute(monitorId, options, callback); | |||||
| } else if(subcommand === "unmute"){ | |||||
| var monitorId = args._[4]; | |||||
| var scope = args["scope"]; | |||||
| unmute(monitorId, scope, callback); | |||||
| } else if(subcommand === "unmuteall"){ | |||||
| unmuteAll(callback); | |||||
| } else if(subcommand === "muteall"){ | |||||
| muteAll(callback); | |||||
| } else if(subcommand === "remove"){ | |||||
| var monitorId = args._[4]; | |||||
| remove(monitorId, callback); | |||||
| } else if(subcommand === "create" && args._.length > 5){ | |||||
| var type = args._[4]; | |||||
| var query = args._[5]; | |||||
| var properties = {}; | |||||
| if(name){ | |||||
| properties.name = name; | |||||
| } | |||||
| if(message){ | |||||
| properties.message = message; | |||||
| } | |||||
| create(type, query, properties, callback); | |||||
| } else if(subcommand === "update" && args._.length > 5){ | |||||
| var monitorId = args._[4]; | |||||
| var query = args._[5]; | |||||
| var properties = {}; | |||||
| if(name){ | |||||
| properties.name = name; | |||||
| } | |||||
| if(message){ | |||||
| properties.message = message; | |||||
| } | |||||
| update(monitorId, query, properties, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi monitor --help` for help", false); | |||||
| if (subcommand === 'get') { | |||||
| const monitorId = args._[4]; | |||||
| get(monitorId, states, callback); | |||||
| } else if (subcommand === 'getall') { | |||||
| const options = {}; | |||||
| if (states.length > 0) { | |||||
| options.group_states = states; | |||||
| } | |||||
| if (tags.length > 0) { | |||||
| options.tags = tags; | |||||
| } | |||||
| getAll(options, callback); | |||||
| } else if (subcommand === 'mute') { | |||||
| const monitorId = args._[4]; | |||||
| const options = {}; | |||||
| if (args.scope) { | |||||
| options.scope = args.scope; | |||||
| } | |||||
| if (args.end) { | |||||
| options.end = args.end; | |||||
| } | |||||
| mute(monitorId, options, callback); | |||||
| } else if (subcommand === 'unmute') { | |||||
| const monitorId = args._[4]; | |||||
| const scope = args.scope; | |||||
| unmute(monitorId, scope, callback); | |||||
| } else if (subcommand === 'unmuteall') { | |||||
| unmuteAll(callback); | |||||
| } else if (subcommand === 'muteall') { | |||||
| muteAll(callback); | |||||
| } else if (subcommand === 'remove') { | |||||
| const monitorId = args._[4]; | |||||
| remove(monitorId, callback); | |||||
| } else if (subcommand === 'create' && args._.length > 5) { | |||||
| const type = args._[4]; | |||||
| const query = args._[5]; | |||||
| const properties = {}; | |||||
| if (name) { | |||||
| properties.name = name; | |||||
| } | |||||
| if (message) { | |||||
| properties.message = message; | |||||
| } | |||||
| create(type, query, properties, callback); | |||||
| } else if (subcommand === 'update' && args._.length > 5) { | |||||
| const monitorId = args._[4]; | |||||
| const query = args._[5]; | |||||
| const properties = {}; | |||||
| if (name) { | |||||
| properties.name = name; | |||||
| } | |||||
| if (message) { | |||||
| properties.message = message; | |||||
| } | } | ||||
| update(monitorId, query, properties, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi monitor --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,351 +1,353 @@ | |||||
| var client = require("../client"); | |||||
| var json = require("../json"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| const json = require('../json'); | |||||
| /*section: screenboard | |||||
| *comment: create a new screenboard | |||||
| *params: | |||||
| * boardTitle: the name of the screenboard | |||||
| * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info | |||||
| * options: | | |||||
| * optional, a object which can contain any of the following keys | |||||
| * * description: description of the screenboard | |||||
| * * templateVariables: | | |||||
| * an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * * width: the width of the screenboard in pixels | |||||
| * * height: the height of the screenboard in pixels | |||||
| * * readOnly: the read-only status of the screenboard | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var boardTitle = "my screenboard"; | |||||
| * var widgets = [ | |||||
| * { | |||||
| * type: "image", | |||||
| * height: 20, | |||||
| * width: 32, | |||||
| * y: 7, | |||||
| * x: 32, | |||||
| * url: "https://path/to/image.jpg" | |||||
| * } | |||||
| * ]; | |||||
| * var options = { | |||||
| * templateVariables: [ | |||||
| * { | |||||
| * name: "host1", | |||||
| * prefix: "host", | |||||
| * "default": "host:my-host" | |||||
| * } | |||||
| * ], | |||||
| * description: "it is super awesome" | |||||
| * }; | |||||
| * dogapi.screenboard.create( | |||||
| * boardTitle, widgets, options, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function create(boardTitle, widgets, options, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = options; | |||||
| options = {}; | |||||
| module.exports = function(client) { | |||||
| /* section: screenboard | |||||
| *comment: create a new screenboard | |||||
| *params: | |||||
| * boardTitle: the name of the screenboard | |||||
| * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info | |||||
| * options: | | |||||
| * optional, a object which can contain any of the following keys | |||||
| * * description: description of the screenboard | |||||
| * * templateVariables: | | |||||
| * an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * * width: the width of the screenboard in pixels | |||||
| * * height: the height of the screenboard in pixels | |||||
| * * readOnly: the read-only status of the screenboard | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const boardTitle = "my screenboard"; | |||||
| * const widgets = [ | |||||
| * { | |||||
| * type: "image", | |||||
| * height: 20, | |||||
| * width: 32, | |||||
| * y: 7, | |||||
| * x: 32, | |||||
| * url: "https://path/to/image.jpg" | |||||
| * } | |||||
| * ]; | |||||
| * const options = { | |||||
| * templateVariables: [ | |||||
| * { | |||||
| * name: "host1", | |||||
| * prefix: "host", | |||||
| * "default": "host:my-host" | |||||
| * } | |||||
| * ], | |||||
| * description: "it is super awesome" | |||||
| * }; | |||||
| * dogapi.screenboard.create( | |||||
| * boardTitle, widgets, options, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function create(boardTitle, widgets, options, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = options; | |||||
| options = {}; | |||||
| } | } | ||||
| if(typeof options !== "object"){ | |||||
| options = {}; | |||||
| if (typeof options !== 'object') { | |||||
| options = {}; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| board_title: boardTitle, | |||||
| widgets: widgets | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| board_title: boardTitle, | |||||
| widgets | |||||
| } | |||||
| }; | }; | ||||
| if(options.description){ | |||||
| params.body.description = options.description; | |||||
| if (options.description) { | |||||
| params.body.description = options.description; | |||||
| } | } | ||||
| if(options.templateVariables){ | |||||
| params.body.template_variables = options.templateVariables; | |||||
| if (options.templateVariables) { | |||||
| params.body.template_variables = options.templateVariables; | |||||
| } | } | ||||
| if(options.width){ | |||||
| params.body.width = options.width; | |||||
| if (options.width) { | |||||
| params.body.width = options.width; | |||||
| } | } | ||||
| if(options.height){ | |||||
| params.body.height = options.height; | |||||
| if (options.height) { | |||||
| params.body.height = options.height; | |||||
| } | } | ||||
| if(options.readOnly){ | |||||
| params.body.read_only = options.readOnly; | |||||
| if (options.readOnly) { | |||||
| params.body.read_only = options.readOnly; | |||||
| } | } | ||||
| client.request("POST", "/screen", params, callback); | |||||
| } | |||||
| client.request('POST', '/screen', params, callback); | |||||
| } | |||||
| /*section: screenboard | |||||
| *comment: update an existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to update | |||||
| * boardTitle: the name of the screenboard | |||||
| * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info | |||||
| * options: | | |||||
| * optional, a object which can contain any of the following keys | |||||
| * * description: description of the screenboard | |||||
| * * templateVariables: | | |||||
| * an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * * width: the width of the screenboard in pixels | |||||
| * * height: the height of the screenboard in pixels | |||||
| * * readOnly: the read-only status of the screenboard | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var boardTitle = "my screenboard"; | |||||
| * var widgets = [ | |||||
| * { | |||||
| * type: "image", | |||||
| * height: 20, | |||||
| * width: 32, | |||||
| * y: 7, | |||||
| * x: 32, | |||||
| * url: "https://path/to/image.jpg" | |||||
| * } | |||||
| * ]; | |||||
| * var options = { | |||||
| * description: "it is super awesome" | |||||
| * }; | |||||
| * dogapi.screenboard.update( | |||||
| * 1234, boardTitle, widgets, options, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function update(boardId, boardTitle, widgets, options, callback) { | |||||
| if(arguments.length < 5 && typeof arguments[3] === "function"){ | |||||
| /* section: screenboard | |||||
| *comment: update an existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to update | |||||
| * boardTitle: the name of the screenboard | |||||
| * widgets: an array of widgets, see http://docs.datadoghq.com/api/screenboards/ for more info | |||||
| * options: | | |||||
| * optional, a object which can contain any of the following keys | |||||
| * * description: description of the screenboard | |||||
| * * templateVariables: | | |||||
| * an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * * width: the width of the screenboard in pixels | |||||
| * * height: the height of the screenboard in pixels | |||||
| * * readOnly: the read-only status of the screenboard | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const boardTitle = "my screenboard"; | |||||
| * const widgets = [ | |||||
| * { | |||||
| * type: "image", | |||||
| * height: 20, | |||||
| * width: 32, | |||||
| * y: 7, | |||||
| * x: 32, | |||||
| * url: "https://path/to/image.jpg" | |||||
| * } | |||||
| * ]; | |||||
| * const options = { | |||||
| * description: "it is super awesome" | |||||
| * }; | |||||
| * dogapi.screenboard.update( | |||||
| * 1234, boardTitle, widgets, options, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function update(boardId, boardTitle, widgets, options, callback) { | |||||
| if (arguments.length < 5 && typeof arguments[3] === 'function') { | |||||
| callback = options; | callback = options; | ||||
| options = {}; | options = {}; | ||||
| } | |||||
| if(typeof options !== "object"){ | |||||
| } | |||||
| if (typeof options !== 'object') { | |||||
| options = {}; | options = {}; | ||||
| } | |||||
| } | |||||
| var params = { | |||||
| const params = { | |||||
| body: { | body: { | ||||
| board_title: boardTitle, | |||||
| widgets: widgets | |||||
| board_title: boardTitle, | |||||
| widgets | |||||
| } | } | ||||
| }; | |||||
| }; | |||||
| if(options.description){ | |||||
| if (options.description) { | |||||
| params.body.description = options.description; | params.body.description = options.description; | ||||
| } | |||||
| if(options.templateVariables){ | |||||
| } | |||||
| if (options.templateVariables) { | |||||
| params.body.template_variables = options.templateVariables; | params.body.template_variables = options.templateVariables; | ||||
| } | |||||
| if(options.width){ | |||||
| } | |||||
| if (options.width) { | |||||
| params.body.width = options.width; | params.body.width = options.width; | ||||
| } | |||||
| if(options.height){ | |||||
| } | |||||
| if (options.height) { | |||||
| params.body.height = options.height; | params.body.height = options.height; | ||||
| } | |||||
| if(options.readOnly){ | |||||
| } | |||||
| if (options.readOnly) { | |||||
| params.body.read_only = options.readOnly; | params.body.read_only = options.readOnly; | ||||
| } | |||||
| client.request("PUT", util.format("/screen/%s", boardId), params, callback); | |||||
| } | |||||
| } | |||||
| /*section: screenboard | |||||
| *comment: delete an existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to delete | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(boardId, callback){ | |||||
| client.request("DELETE", util.format("/screen/%s", boardId), callback); | |||||
| } | |||||
| client.request('PUT', util.format('/screen/%s', boardId), params, callback); | |||||
| } | |||||
| /*section: screenboard | |||||
| *comment: get the info of a single existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to fetch | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(boardId, callback){ | |||||
| client.request("GET", util.format("/screen/%s", boardId), callback); | |||||
| } | |||||
| /* section: screenboard | |||||
| *comment: delete an existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to delete | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(boardId, callback) { | |||||
| client.request('DELETE', util.format('/screen/%s', boardId), callback); | |||||
| } | |||||
| /*section: screenboard | |||||
| *comment: get all existing screenboards | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback){ | |||||
| client.request("GET", "/screen", callback); | |||||
| } | |||||
| /* section: screenboard | |||||
| *comment: get the info of a single existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to fetch | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(boardId, callback) { | |||||
| client.request('GET', util.format('/screen/%s', boardId), callback); | |||||
| } | |||||
| /*section: screenboard | |||||
| *comment: share an existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to share | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.share(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function share(boardId, callback){ | |||||
| client.request("POST", util.format("/screen/share/%s", boardId), callback); | |||||
| } | |||||
| /* section: screenboard | |||||
| *comment: get all existing screenboards | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.getAll(function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback) { | |||||
| client.request('GET', '/screen', callback); | |||||
| } | |||||
| /* section: screenboard | |||||
| *comment: share an existing screenboard | |||||
| *params: | |||||
| * boardId: the id of the screenboard to share | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.screenboard.share(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function share(boardId, callback) { | |||||
| client.request('POST', util.format('/screen/share/%s', boardId), callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| remove: remove, | |||||
| update: update, | |||||
| get: get, | |||||
| getAll: getAll, | |||||
| share: share, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi screenboard create <boardTitle> <widgets> [--description <description>] [--tmpvars <templateVariables>] [--width <width>] [--height <height>]", | |||||
| " dogapi screenboard remove <boardId>", | |||||
| " dogapi screenboard get <boardId>", | |||||
| " dogapi screenboard getall", | |||||
| " dogapi screenboard share <boardId>" | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| remove, | |||||
| update, | |||||
| get, | |||||
| getAll, | |||||
| share, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi screenboard create <boardTitle> <widgets> [--description <description>] [--tmpvars <templateVariables>] [--width <width>] [--height <height>]', | |||||
| ' dogapi screenboard remove <boardId>', | |||||
| ' dogapi screenboard get <boardId>', | |||||
| ' dogapi screenboard getall', | |||||
| ' dogapi screenboard share <boardId>' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Screenboard:", | |||||
| " Subcommands:", | |||||
| " create <boardTitle> <widgets> create a new screenboard, <widgets> is a json of the graph definition", | |||||
| " update <boardId> <boardTitle> <widgets> update a screenboard", | |||||
| " remove <boardId> remove an existing screenboard", | |||||
| " get <boardId> get an existing screenboard", | |||||
| " getall get all screenboards", | |||||
| " share <boardId> get share info for an existing screenboard", | |||||
| " Options:", | |||||
| " --description <description> a description of the screenboard's content", | |||||
| " --tmpvars <templateVariables> json representation of the template variable definition", | |||||
| " --width <width> width of the screenboard in pixels", | |||||
| " --height <height> height of the screenboard in pixels", | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Screenboard:', | |||||
| ' Subcommands:', | |||||
| ' create <boardTitle> <widgets> create a new screenboard, <widgets> is a json of the graph definition', | |||||
| ' update <boardId> <boardTitle> <widgets> update a screenboard', | |||||
| ' remove <boardId> remove an existing screenboard', | |||||
| ' get <boardId> get an existing screenboard', | |||||
| ' getall get all screenboards', | |||||
| ' share <boardId> get share info for an existing screenboard', | |||||
| ' Options:', | |||||
| " --description <description> a description of the screenboard's content", | |||||
| ' --tmpvars <templateVariables> json representation of the template variable definition', | |||||
| ' --width <width> width of the screenboard in pixels', | |||||
| ' --height <height> height of the screenboard in pixels' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "get"){ | |||||
| get(args._[4], callback); | |||||
| } else if(subcommand === "getall"){ | |||||
| getAll(callback); | |||||
| } else if(subcommand === "remove"){ | |||||
| remove(args._[4], callback); | |||||
| } else if(subcommand === "share"){ | |||||
| share(args._[4], callback); | |||||
| } else if (subcommand === "update"){ | |||||
| var boardId = args._[4]; | |||||
| var boardTitle = args._[5]; | |||||
| var widgets = json.parse(args._[6]); | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'get') { | |||||
| get(args._[4], callback); | |||||
| } else if (subcommand === 'getall') { | |||||
| getAll(callback); | |||||
| } else if (subcommand === 'remove') { | |||||
| remove(args._[4], callback); | |||||
| } else if (subcommand === 'share') { | |||||
| share(args._[4], callback); | |||||
| } else if (subcommand === 'update') { | |||||
| const boardId = args._[4]; | |||||
| const boardTitle = args._[5]; | |||||
| const widgets = json.parse(args._[6]); | |||||
| var options = {}; | |||||
| if(args["description"]) { | |||||
| options.description = args["description"]; | |||||
| } | |||||
| if(args["tmpvars"]){ | |||||
| options.templateVariables = json.parse(args["tmpvars"]); | |||||
| } | |||||
| if(args["width"]){ | |||||
| options.width = parseInt(args["width"]); | |||||
| } | |||||
| if(args["height"]){ | |||||
| options.height = parseInt(args["height"]); | |||||
| } | |||||
| update(boardId, boardTitle, widgets, options, callback); | |||||
| } else if(subcommand === "create"){ | |||||
| var boardTitle = args._[4]; | |||||
| var widgets = json.parse(args._[5]); | |||||
| const options = {}; | |||||
| if (args.description) { | |||||
| options.description = args.description; | |||||
| } | |||||
| if (args.tmpvars) { | |||||
| options.templateVariables = json.parse(args.tmpvars); | |||||
| } | |||||
| if (args.width) { | |||||
| options.width = parseInt(args.width); | |||||
| } | |||||
| if (args.height) { | |||||
| options.height = parseInt(args.height); | |||||
| } | |||||
| var options = {}; | |||||
| if(args["description"]) { | |||||
| options.description = args["description"]; | |||||
| } | |||||
| if(args["tmpvars"]){ | |||||
| options.templateVariables = json.parse(args["tmpvars"]); | |||||
| } | |||||
| if(args["width"]){ | |||||
| options.width = parseInt(args["width"]); | |||||
| } | |||||
| if(args["height"]){ | |||||
| options.height = parseInt(args["height"]); | |||||
| } | |||||
| update(boardId, boardTitle, widgets, options, callback); | |||||
| } else if (subcommand === 'create') { | |||||
| const boardTitle = args._[4]; | |||||
| const widgets = json.parse(args._[5]); | |||||
| create(boardTitle, widgets, options, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi screenboard --help` for help", false); | |||||
| const options = {}; | |||||
| if (args.description) { | |||||
| options.description = args.description; | |||||
| } | |||||
| if (args.tmpvars) { | |||||
| options.templateVariables = json.parse(args.tmpvars); | |||||
| } | } | ||||
| if (args.width) { | |||||
| options.width = parseInt(args.width); | |||||
| } | |||||
| if (args.height) { | |||||
| options.height = parseInt(args.height); | |||||
| } | |||||
| create(boardTitle, widgets, options, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi screenboard --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,53 +1,54 @@ | |||||
| var client = require("../client"); | |||||
| /*section: search | |||||
| *comment: | | |||||
| * search for metrics and hosts from the past 24 hours | |||||
| *params: | |||||
| * query: the seach query to perform (e.g. "app1" or "hosts:app1" or "metrics:response") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var query = "app"; | |||||
| * dogapi.search.query(query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function query(query, callback){ | |||||
| var params = { | |||||
| query: { | |||||
| q: query | |||||
| } | |||||
| module.exports = function(client) { | |||||
| /* section: search | |||||
| *comment: | | |||||
| * search for metrics and hosts from the past 24 hours | |||||
| *params: | |||||
| * query: the seach query to perform (e.g. "app1" or "hosts:app1" or "metrics:response") | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const query = "app"; | |||||
| * dogapi.search.query(query, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function query(q, callback) { | |||||
| const params = { | |||||
| query: { | |||||
| q | |||||
| } | |||||
| }; | }; | ||||
| client.request("GET", "/search", params, callback); | |||||
| } | |||||
| client.request('GET', '/search', params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| query: query, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi search query <query>" | |||||
| ]; | |||||
| return { | |||||
| query, | |||||
| getUsage() { | |||||
| return [' dogapi search query <query>']; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Search:", | |||||
| " Subcommands:", | |||||
| " query <query> search for hosts and metrics from the last 24 hours" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Search:', | |||||
| ' Subcommands:', | |||||
| ' query <query> search for hosts and metrics from the last 24 hours' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "query" && args._.length > 4){ | |||||
| query(args._[4], callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi search --help` for help", false); | |||||
| } | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'query' && args._.length > 4) { | |||||
| query(args._[4], callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi search --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -0,0 +1,88 @@ | |||||
| module.exports = function(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 | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const check = "app.ok"; | |||||
| * const hostName = "some.machine"; | |||||
| * dogapi.serviceCheck.check( | |||||
| * check, hostName, dogapi.WARNING, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function check(checkName, hostName, status, parameters, callback) { | |||||
| if (arguments.length < 5 && typeof arguments[3] === 'function') { | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| } | |||||
| if (typeof parameters !== 'object') { | |||||
| parameters = {}; | |||||
| } | |||||
| parameters.check = checkName; | |||||
| parameters.host_name = hostName; | |||||
| parameters.status = status; | |||||
| const params = { | |||||
| body: parameters | |||||
| }; | |||||
| client.request('POST', '/check_run', params, callback); | |||||
| } | |||||
| return { | |||||
| check, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi servicecheck check <check> <host> <status> [--time <timestamp>] [--message <message>] [--tags <tags>]' | |||||
| ]; | |||||
| }, | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Service Check:', | |||||
| ' Subcommands:', | |||||
| ' check <check> <host> <status> add a new service check for <check> and <host> at level <status> (0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN)', | |||||
| '', | |||||
| ' Options:', | |||||
| ' --time <timestamp> the POSIX timestamp to use for the check', | |||||
| ' --message <message> an optional message to accompany the check', | |||||
| ' --tags <tags> a comma separated list of "tag:value"\'s for the check' | |||||
| ]; | |||||
| }, | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (args._.length > 6) { | |||||
| const parameters = {}; | |||||
| if (args.time) { | |||||
| parameters.time = parseInt(args.time); | |||||
| } | |||||
| if (args.message) { | |||||
| parameters.message = args.message; | |||||
| } | |||||
| if (args.tags) { | |||||
| parameters.tags = args.tags.split(','); | |||||
| } | |||||
| check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); | |||||
| } else { | |||||
| return callback('not enough arguments try `dogapi servicecheck --help` for help', false); | |||||
| } | |||||
| } | |||||
| }; | |||||
| }; | |||||
| @ -1,89 +0,0 @@ | |||||
| 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, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi servicecheck check <check> <host> <status> [--time <timestamp>] [--message <message>] [--tags <tags>]" | |||||
| ]; | |||||
| }, | |||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Service Check:", | |||||
| " Subcommands:", | |||||
| " check <check> <host> <status> add a new service check for <check> and <host> at level <status> (0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN)", | |||||
| "", | |||||
| " Options:", | |||||
| " --time <timestamp> the POSIX timestamp to use for the check", | |||||
| " --message <message> an optional message to accompany the check", | |||||
| " --tags <tags> a comma separated list of \"tag:value\"'s for the check" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(args._.length > 6){ | |||||
| var parameters = {}; | |||||
| if(args["time"]){ | |||||
| parameters.time = parseInt(args["time"]); | |||||
| } | |||||
| if(args["message"]){ | |||||
| paramaters.message = args["message"]; | |||||
| } | |||||
| if(args["tags"]){ | |||||
| parameters.tags = args["tags"].split(","); | |||||
| } | |||||
| check(args._[4], args._[5], parseInt(args._[6]), parameters, callback); | |||||
| } else { | |||||
| callback("not enough arguments try `dogapi servicecheck --help` for help", false); | |||||
| } | |||||
| } | |||||
| }; | |||||
| @ -1,264 +1,259 @@ | |||||
| var client = require("../client"); | |||||
| var util = require('util'); | |||||
| /*section: tag | |||||
| *comment: | | |||||
| * get all host tags | |||||
| *params: | |||||
| * source: | | |||||
| * optional, only show tags for a particular source [default: null] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.getAll(function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(source, callback){ | |||||
| if(arguments.length < 2 && typeof arguments[0] === "function"){ | |||||
| callback = source; | |||||
| source = undefined; | |||||
| module.exports = function(client) { | |||||
| /* section: tag | |||||
| *comment: | | |||||
| * get all host tags | |||||
| *params: | |||||
| * source: | | |||||
| * optional, only show tags for a particular source [default: null] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.getAll(function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(source, callback) { | |||||
| if (arguments.length < 2 && typeof arguments[0] === 'function') { | |||||
| callback = source; | |||||
| source = undefined; | |||||
| } | } | ||||
| var params = { | |||||
| query: { | |||||
| source: source | |||||
| } | |||||
| const params = { | |||||
| query: { | |||||
| source | |||||
| } | |||||
| }; | }; | ||||
| client.request("GET", "/tags/hosts", params, callback); | |||||
| } | |||||
| client.request('GET', '/tags/hosts', params, callback); | |||||
| } | |||||
| /*section: tag | |||||
| *comment: | | |||||
| * get the host tags for a provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * options: | |||||
| * | | |||||
| * optional, an object of options for the query allowing the following | |||||
| * * source: the source of the tags (e.g. chef, puppet, users, etc) [default: null] | |||||
| * * by_source: whether or not to group the results by source [default: false] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.get("host.name", function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(hostname, options, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = options; | |||||
| options = {}; | |||||
| /* section: tag | |||||
| *comment: | | |||||
| * get the host tags for a provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * options: | |||||
| * | | |||||
| * optional, an object of options for the query allowing the following | |||||
| * * source: the source of the tags (e.g. chef, puppet, users, etc) [default: null] | |||||
| * * by_source: whether or not to group the results by source [default: false] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.get("host.name", function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(hostname, options, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = options; | |||||
| options = {}; | |||||
| } | } | ||||
| options = options || {}; | options = options || {}; | ||||
| var params = { | |||||
| query: { | |||||
| } | |||||
| const params = { | |||||
| query: {} | |||||
| }; | }; | ||||
| if(options.source){ | |||||
| params.query.source = options.source; | |||||
| if (options.source) { | |||||
| params.query.source = options.source; | |||||
| } | } | ||||
| if(options.by_source){ | |||||
| params.query.by_source = options.by_source; | |||||
| if (options.by_source) { | |||||
| params.query.by_source = options.by_source; | |||||
| } | } | ||||
| client.request("GET", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| client.request('GET', `/tags/hosts/${hostname}`, params, callback); | |||||
| } | |||||
| /*section: tag | |||||
| *comment: | | |||||
| * assign new host tags to the provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * tags: | | |||||
| * list of `<tag>:<value>` tags to assign to the server | |||||
| * source: | | |||||
| * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.create("host.name", ["role:webserver"], function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(hostname, tags, source, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = source; | |||||
| source = undefined; | |||||
| /* section: tag | |||||
| *comment: | | |||||
| * assign new host tags to the provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * tags: | | |||||
| * list of `<tag>:<value>` tags to assign to the server | |||||
| * source: | | |||||
| * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.create("host.name", ["role:webserver"], function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function create(hostname, tags, source, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = source; | |||||
| source = undefined; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| tags: tags, | |||||
| source: source | |||||
| }, | |||||
| const params = { | |||||
| body: { | |||||
| tags, | |||||
| source | |||||
| } | |||||
| }; | }; | ||||
| client.request("POST", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| client.request('POST', `/tags/hosts/${hostname}`, params, callback); | |||||
| } | |||||
| /*section: tag | |||||
| *comment: | | |||||
| * update the host tags for the provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * tags: | | |||||
| * list of `<tag>:<value>` tags to assign to the server | |||||
| * source: | | |||||
| * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.update("host.name", function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(hostname, tags, source, callback){ | |||||
| if(arguments.length < 4 && typeof arguments[2] === "function"){ | |||||
| callback = source; | |||||
| source = undefined; | |||||
| /* section: tag | |||||
| *comment: | | |||||
| * update the host tags for the provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * tags: | | |||||
| * list of `<tag>:<value>` tags to assign to the server | |||||
| * source: | | |||||
| * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.update("host.name", function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function update(hostname, tags, source, callback) { | |||||
| if (arguments.length < 4 && typeof arguments[2] === 'function') { | |||||
| callback = source; | |||||
| source = undefined; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| tags: tags, | |||||
| source: source | |||||
| }, | |||||
| const params = { | |||||
| body: { | |||||
| tags, | |||||
| source | |||||
| } | |||||
| }; | }; | ||||
| client.request("PUT", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| client.request('PUT', `/tags/hosts/${hostname}`, params, callback); | |||||
| } | |||||
| /*section: tag | |||||
| *comment: | | |||||
| * delete the host tags for the provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * source: | | |||||
| * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.remove("host.name", function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(hostname, source, callback){ | |||||
| if(arguments.length < 3 && typeof arguments[1] === "function"){ | |||||
| callback = source; | |||||
| source = undefined; | |||||
| /* section: tag | |||||
| *comment: | | |||||
| * delete the host tags for the provided host name or host id | |||||
| *params: | |||||
| * hostname: | | |||||
| * the hostname or host id | |||||
| * source: | | |||||
| * optional, the source of the tags (e.g. chef, puppet, etc) [default: users] | |||||
| * callback: | | |||||
| * function callback(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.tag.remove("host.name", function(err, results){ | |||||
| * console.dir(results); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(hostname, source, callback) { | |||||
| if (arguments.length < 3 && typeof arguments[1] === 'function') { | |||||
| callback = source; | |||||
| source = undefined; | |||||
| } | } | ||||
| var params = { | |||||
| query: { | |||||
| source: source | |||||
| } | |||||
| const params = { | |||||
| query: { | |||||
| source | |||||
| } | |||||
| }; | }; | ||||
| client.request("DELETE", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| client.request('DELETE', `/tags/hosts/${hostname}`, params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| return { | |||||
| _client: client, | _client: client, | ||||
| getAll: getAll, | |||||
| get: get, | |||||
| create: create, | |||||
| update: update, | |||||
| remove: remove, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi tag getall [--source <source>]", | |||||
| " dogapi tag get <host> [--source <source>] [--by-source]", | |||||
| " dogapi tag remove <host> [--source <source>]", | |||||
| " dogapi tag create <host> <tags> [--source <source>]", | |||||
| " dogapi tag update <host> <tags> [--source <source>]" | |||||
| ]; | |||||
| getAll, | |||||
| get, | |||||
| create, | |||||
| update, | |||||
| remove, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi tag getall [--source <source>]', | |||||
| ' dogapi tag get <host> [--source <source>] [--by-source]', | |||||
| ' dogapi tag remove <host> [--source <source>]', | |||||
| ' dogapi tag create <host> <tags> [--source <source>]', | |||||
| ' dogapi tag update <host> <tags> [--source <source>]' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Tag:", | |||||
| " Subcommands:", | |||||
| " getall get all tags", | |||||
| " get <host> get all tags for a given host", | |||||
| " remove <host> delete tags for a given host", | |||||
| " create <host> <tags> add the comma separates \"tag:value\"'s from <tag> to <host>", | |||||
| " update <host> <tags> update the comma separates \"tag:value\"'s from <tag> to <host>", | |||||
| "", | |||||
| " Options:", | |||||
| " --source <source> the source of the tags (e.g. \"chef\", \"user\", \"jenkins\", etc)", | |||||
| " --by-source whether the results should be grouped by source" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Tag:', | |||||
| ' Subcommands:', | |||||
| ' getall get all tags', | |||||
| ' get <host> get all tags for a given host', | |||||
| ' remove <host> delete tags for a given host', | |||||
| ' create <host> <tags> add the comma separates "tag:value"\'s from <tag> to <host>', | |||||
| ' update <host> <tags> update the comma separates "tag:value"\'s from <tag> to <host>', | |||||
| '', | |||||
| ' Options:', | |||||
| ' --source <source> the source of the tags (e.g. "chef", "user", "jenkins", etc)', | |||||
| ' --by-source whether the results should be grouped by source' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| var source = args["source"]; | |||||
| var host = args._[4]; | |||||
| handleCli(subcommand, args, callback) { | |||||
| const source = args.source; | |||||
| const host = args._[4]; | |||||
| if(subcommand === "getall"){ | |||||
| getAll(source, callback); | |||||
| } else if(subcommand === "get"){ | |||||
| var options = {}; | |||||
| if(source){ | |||||
| options.source = source; | |||||
| } | |||||
| if(args["by-source"]){ | |||||
| options.by_source = true; | |||||
| } | |||||
| get(host, options, callback); | |||||
| } else if(subcommand === "create"){ | |||||
| var tags = args._[5].split(","); | |||||
| create(host, tags, source, callback); | |||||
| } else if(subcommand === "update"){ | |||||
| var tags = args._[5].split(","); | |||||
| update(host, tags, source, callback); | |||||
| } else if(subcommand === "delete"){ | |||||
| remove(host, source, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi tag --help` for help", false); | |||||
| if (subcommand === 'getall') { | |||||
| getAll(source, callback); | |||||
| } else if (subcommand === 'get') { | |||||
| const options = {}; | |||||
| if (source) { | |||||
| options.source = source; | |||||
| } | |||||
| if (args['by-source']) { | |||||
| options.by_source = true; | |||||
| } | } | ||||
| get(host, options, callback); | |||||
| } else if (subcommand === 'create') { | |||||
| const tags = args._[5].split(','); | |||||
| create(host, tags, source, callback); | |||||
| } else if (subcommand === 'update') { | |||||
| const tags = args._[5].split(','); | |||||
| update(host, tags, source, callback); | |||||
| } else if (subcommand === 'delete') { | |||||
| remove(host, source, callback); | |||||
| } else { | |||||
| return callback('unknown subcommand or arguments try `dogapi tag --help` for help', false); | |||||
| } | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | |||||
| @ -1,275 +1,273 @@ | |||||
| var client = require("../client"); | |||||
| var json = require("../json"); | |||||
| var util = require("util"); | |||||
| const util = require('util'); | |||||
| const json = require('../json'); | |||||
| /*section: timeboard | |||||
| *comment: add a new timeboard | |||||
| *params: | |||||
| * title: the title of the timeboard | |||||
| * description: the description of the timeboard | |||||
| * graphs: | | |||||
| * an array of objects with the following keys | |||||
| * * title: the name of the graph | |||||
| * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` | |||||
| * templateVariables: | | |||||
| * optional, an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var title = "Time Keeps on Slipping"; | |||||
| * var description = "Into the Future"; | |||||
| * var graphs = [ | |||||
| * { | |||||
| * definition: { | |||||
| * events: [], | |||||
| * requests: [ | |||||
| * {q: "avg:system.mem.free{*}"} | |||||
| * ], | |||||
| * viz: "timeseries" | |||||
| * }, | |||||
| * title: "Average Memory Free" | |||||
| * } | |||||
| * ]; | |||||
| * var templateVariables = [ | |||||
| * { | |||||
| * name: "host1", | |||||
| * prefix: "host", | |||||
| * "default": "host:my-host" | |||||
| * } | |||||
| * ]; | |||||
| * dogapi.timeboard.create( | |||||
| * title, description, graphs, templateVariables, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function create(title, description, graphs, templateVariables, callback){ | |||||
| if(arguments.length < 5 && typeof arguments[3] === "function"){ | |||||
| callback = templateVariables; | |||||
| templateVariables = []; | |||||
| module.exports = function(client) { | |||||
| /* section: timeboard | |||||
| *comment: add a new timeboard | |||||
| *params: | |||||
| * title: the title of the timeboard | |||||
| * description: the description of the timeboard | |||||
| * graphs: | | |||||
| * an array of objects with the following keys | |||||
| * * title: the name of the graph | |||||
| * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` | |||||
| * templateVariables: | | |||||
| * optional, an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const title = "Time Keeps on Slipping"; | |||||
| * const description = "Into the Future"; | |||||
| * const graphs = [ | |||||
| * { | |||||
| * definition: { | |||||
| * events: [], | |||||
| * requests: [ | |||||
| * {q: "avg:system.mem.free{*}"} | |||||
| * ], | |||||
| * viz: "timeseries" | |||||
| * }, | |||||
| * title: "Average Memory Free" | |||||
| * } | |||||
| * ]; | |||||
| * const templateVariables = [ | |||||
| * { | |||||
| * name: "host1", | |||||
| * prefix: "host", | |||||
| * "default": "host:my-host" | |||||
| * } | |||||
| * ]; | |||||
| * dogapi.timeboard.create( | |||||
| * title, description, graphs, templateVariables, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function create(title, description, graphs, templateVariables, callback) { | |||||
| if (arguments.length < 5 && typeof arguments[3] === 'function') { | |||||
| callback = templateVariables; | |||||
| templateVariables = []; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| title: title, | |||||
| description: description, | |||||
| graphs: graphs | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| title, | |||||
| description, | |||||
| graphs | |||||
| } | |||||
| }; | }; | ||||
| if(Array.isArray(templateVariables) && templateVariables.length){ | |||||
| params.body.template_variables = templateVariables; | |||||
| if (Array.isArray(templateVariables) && templateVariables.length > 0) { | |||||
| params.body.template_variables = templateVariables; | |||||
| } | } | ||||
| client.request("POST", "/dash", params, callback); | |||||
| } | |||||
| client.request('POST', '/dash', params, callback); | |||||
| } | |||||
| /*section: timeboard | |||||
| *comment: update an existing timeboard | |||||
| *params: | |||||
| * dashId: the id of the timeboard to update | |||||
| * title: the title of the timeboard | |||||
| * description: the description of the timeboard | |||||
| * graphs: | | |||||
| * an array of objects with the following keys | |||||
| * * title: the name of the graph | |||||
| * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` | |||||
| * templateVariables: | | |||||
| * optional, an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var title = "Time Keeps on Slipping"; | |||||
| * var description = "Into the Future"; | |||||
| * var graphs = [ | |||||
| * { | |||||
| * definition: { | |||||
| * events: [], | |||||
| * requests: [ | |||||
| * {q: "avg:system.mem.free{*}"} | |||||
| * ], | |||||
| * viz: "timeseries" | |||||
| * }, | |||||
| * title: "Average Memory Free" | |||||
| * } | |||||
| * ]; | |||||
| * var templateVariables = [ | |||||
| * { | |||||
| * name: "host1", | |||||
| * prefix: "host", | |||||
| * default: "host:my-host" | |||||
| * } | |||||
| * ]; | |||||
| * dogapi.timeboard.update( | |||||
| * 1234, title, description, graphs, templateVariables, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function update(dashId, title, description, graphs, templateVariables, callback){ | |||||
| if(arguments.length < 6 && typeof arguments[4] === "function"){ | |||||
| callback = templateVariables; | |||||
| templateVariables = []; | |||||
| /* section: timeboard | |||||
| *comment: update an existing timeboard | |||||
| *params: | |||||
| * dashId: the id of the timeboard to update | |||||
| * title: the title of the timeboard | |||||
| * description: the description of the timeboard | |||||
| * graphs: | | |||||
| * an array of objects with the following keys | |||||
| * * title: the name of the graph | |||||
| * * definition: an object containing the graph definition, e.g. `{"requests": [{"q": "system.cpu.idle{*} by {host}"}` | |||||
| * templateVariables: | | |||||
| * optional, an array of objects with the following keys | |||||
| * * name: the name of the variable | |||||
| * * prefix: optional, the tag prefix for this variable | |||||
| * * default: optional, the default value for this tag | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const title = "Time Keeps on Slipping"; | |||||
| * const description = "Into the Future"; | |||||
| * const graphs = [ | |||||
| * { | |||||
| * definition: { | |||||
| * events: [], | |||||
| * requests: [ | |||||
| * {q: "avg:system.mem.free{*}"} | |||||
| * ], | |||||
| * viz: "timeseries" | |||||
| * }, | |||||
| * title: "Average Memory Free" | |||||
| * } | |||||
| * ]; | |||||
| * const templateVariables = [ | |||||
| * { | |||||
| * name: "host1", | |||||
| * prefix: "host", | |||||
| * default: "host:my-host" | |||||
| * } | |||||
| * ]; | |||||
| * dogapi.timeboard.update( | |||||
| * 1234, title, description, graphs, templateVariables, | |||||
| * function(err, res){ | |||||
| * console.dir(res); | |||||
| * } | |||||
| * ); | |||||
| * ``` | |||||
| */ | |||||
| function update(dashId, title, description, graphs, templateVariables, callback) { | |||||
| if (arguments.length < 6 && typeof arguments[4] === 'function') { | |||||
| callback = templateVariables; | |||||
| templateVariables = []; | |||||
| } | } | ||||
| var params = { | |||||
| body: { | |||||
| title: title, | |||||
| description: description, | |||||
| graphs: graphs | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| title, | |||||
| description, | |||||
| graphs | |||||
| } | |||||
| }; | }; | ||||
| if(Array.isArray(templateVariables) && templateVariables.length){ | |||||
| params.body.template_variables = templateVariables; | |||||
| if (Array.isArray(templateVariables) && templateVariables.length > 0) { | |||||
| params.body.template_variables = templateVariables; | |||||
| } | } | ||||
| client.request("PUT", util.format("/dash/%s", dashId), params, callback); | |||||
| } | |||||
| client.request('PUT', util.format('/dash/%s', dashId), params, callback); | |||||
| } | |||||
| /*section: timeboard | |||||
| *comment: remove an existing timeboard | |||||
| *params: | |||||
| * dashId: the id of the timeboard to remove | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.timeboard.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(dashId, callback){ | |||||
| client.request("DELETE", util.format("/dash/%s", dashId), {}, callback); | |||||
| } | |||||
| /* section: timeboard | |||||
| *comment: remove an existing timeboard | |||||
| *params: | |||||
| * dashId: the id of the timeboard to remove | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.timeboard.remove(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function remove(dashId, callback) { | |||||
| client.request('DELETE', util.format('/dash/%s', dashId), {}, callback); | |||||
| } | |||||
| /*section: timeboard | |||||
| *comment: get all existing timeboards | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.timeboard.getAll(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback){ | |||||
| client.request("GET", "/dash", {}, callback); | |||||
| } | |||||
| /* section: timeboard | |||||
| *comment: get all existing timeboards | |||||
| *params: | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.timeboard.getAll(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function getAll(callback) { | |||||
| client.request('GET', '/dash', {}, callback); | |||||
| } | |||||
| /*section: timeboard | |||||
| *comment: get an existing timeboard | |||||
| *params: | |||||
| * dashId: the id of the timeboard to get | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.timeboard.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(dashId, callback){ | |||||
| client.request("GET", util.format("/dash/%s", dashId), {}, callback); | |||||
| } | |||||
| /* section: timeboard | |||||
| *comment: get an existing timeboard | |||||
| *params: | |||||
| * dashId: the id of the timeboard to get | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * dogapi.timeboard.get(1234, function(err, res){ | |||||
| * console.dir(res); | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function get(dashId, callback) { | |||||
| client.request('GET', util.format('/dash/%s', dashId), {}, callback); | |||||
| } | |||||
| module.exports = { | |||||
| create: create, | |||||
| update: update, | |||||
| remove: remove, | |||||
| getAll: getAll, | |||||
| get: get, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi timeboard get <dash-id>", | |||||
| " dogapi timeboard getall", | |||||
| " dogapi timeboard remove <dash-id>", | |||||
| " dogapi timeboard create <title> <description> <graphs> [--tmpvars <templateVariables>]", | |||||
| " dogapi timeboard update <dash-id> <title> <description> <graphs> [--tmpvars <templateVariables>]", | |||||
| ]; | |||||
| return { | |||||
| create, | |||||
| update, | |||||
| remove, | |||||
| getAll, | |||||
| get, | |||||
| getUsage() { | |||||
| return [ | |||||
| ' dogapi timeboard get <dash-id>', | |||||
| ' dogapi timeboard getall', | |||||
| ' dogapi timeboard remove <dash-id>', | |||||
| ' dogapi timeboard create <title> <description> <graphs> [--tmpvars <templateVariables>]', | |||||
| ' dogapi timeboard update <dash-id> <title> <description> <graphs> [--tmpvars <templateVariables>]' | |||||
| ]; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Timeboard:", | |||||
| " Subcommands:", | |||||
| " get <dash-id> get an existing timeboard", | |||||
| " getall get all existing timeboards", | |||||
| " remove <dash-id> remove an existing timeboard", | |||||
| " create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition", | |||||
| " update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition", | |||||
| " Options:", | |||||
| " --tmpvars <templateVariables> a json representation of the template variables definition" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'Timeboard:', | |||||
| ' Subcommands:', | |||||
| ' get <dash-id> get an existing timeboard', | |||||
| ' getall get all existing timeboards', | |||||
| ' remove <dash-id> remove an existing timeboard', | |||||
| ' create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition', | |||||
| ' update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition', | |||||
| ' Options:', | |||||
| ' --tmpvars <templateVariables> a json representation of the template variables definition' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "get"){ | |||||
| get(args._[4], callback); | |||||
| } else if(subcommand === "getall"){ | |||||
| getAll(callback); | |||||
| } else if(subcommand === "remove"){ | |||||
| remove(args._[4], callback); | |||||
| } else if(subcommand === "create"){ | |||||
| var title = args._[4]; | |||||
| var description = args._[5]; | |||||
| var graphs = json.parse(args._[6]); | |||||
| var templateVariables = []; | |||||
| if(args["tmpvars"]){ | |||||
| templateVariables = json.parse(args["tmpvars"]); | |||||
| } | |||||
| handleCli(subcommand, args, callback) { | |||||
| if (subcommand === 'get') { | |||||
| get(args._[4], callback); | |||||
| } else if (subcommand === 'getall') { | |||||
| getAll(callback); | |||||
| } else if (subcommand === 'remove') { | |||||
| remove(args._[4], callback); | |||||
| } else if (subcommand === 'create') { | |||||
| const title = args._[4]; | |||||
| const description = args._[5]; | |||||
| const graphs = json.parse(args._[6]); | |||||
| const templateVariables = args.tmpvars ? json.parse(args.tmpvars) : []; | |||||
| create(title, description, graphs, templateVariables, callback); | |||||
| } else if(subcommand === "update"){ | |||||
| var dashId = parseInt(args._[4]); | |||||
| var title = args._[5]; | |||||
| var description = args._[6]; | |||||
| var graphs = json.parse(args._[7]); | |||||
| var templateVariables = []; | |||||
| if(args["tmpvars"]){ | |||||
| templateVariables = json.parse(args["tmpvars"]); | |||||
| } | |||||
| create(title, description, graphs, templateVariables, callback); | |||||
| } else if (subcommand === 'update') { | |||||
| const dashId = parseInt(args._[4]); | |||||
| const title = args._[5]; | |||||
| const description = args._[6]; | |||||
| const graphs = json.parse(args._[7]); | |||||
| const templateVariables = args.tmpvars ? json.parse(args.tmpvars) : []; | |||||
| update(dashId, title, description, graphs, templateVariables, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi timeboard --help` for help", false); | |||||
| } | |||||
| update(dashId, title, description, graphs, templateVariables, callback); | |||||
| } else { | |||||
| return callback( | |||||
| 'unknown subcommand or arguments try `dogapi timeboard --help` for help', | |||||
| false | |||||
| ); | |||||
| } | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,48 +1,46 @@ | |||||
| var client = require("../client"); | |||||
| /*section: user | |||||
| *comment: invite users via e-mail | |||||
| *params: | |||||
| * emails: an array of email addresses to send invites to | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * var dogapi = require("dogapi"); | |||||
| * var options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * var emails = ["me@domain.com", "you@domain.com"]; | |||||
| * dogapi.user.invite(emails, fuction(err, res){ | |||||
| * console.dir(res): | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function invite(emails, callback){ | |||||
| var params = { | |||||
| body: { | |||||
| emails: emails | |||||
| } | |||||
| module.exports = function(client) { | |||||
| /* section: user | |||||
| *comment: invite users via e-mail | |||||
| *params: | |||||
| * emails: an array of email addresses to send invites to | |||||
| * callback: function(err, res) | |||||
| *example: | | |||||
| * ```javascript | |||||
| * const dogapi = require("dogapi"); | |||||
| * const options = { | |||||
| * api_key: "api_key", | |||||
| * app_key: "app_key" | |||||
| * }; | |||||
| * dogapi.initialize(options); | |||||
| * const emails = ["me@domain.com", "you@domain.com"]; | |||||
| * dogapi.user.invite(emails, fuction(err, res){ | |||||
| * console.dir(res): | |||||
| * }); | |||||
| * ``` | |||||
| */ | |||||
| function invite(emails, callback) { | |||||
| const params = { | |||||
| body: { | |||||
| emails | |||||
| } | |||||
| }; | }; | ||||
| client.request("POST", "/invite_users", params, callback); | |||||
| }; | |||||
| client.request('POST', '/invite_users', params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| invite: invite, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi user invite <address>..." | |||||
| ]; | |||||
| return { | |||||
| invite, | |||||
| getUsage() { | |||||
| return [' dogapi user invite <address>...']; | |||||
| }, | }, | ||||
| getHelp: function(){ | |||||
| return [ | |||||
| "User:", | |||||
| " Subcommands:", | |||||
| " invite <address>... invite the given list of e-mail addresses to your datadog org" | |||||
| ]; | |||||
| getHelp() { | |||||
| return [ | |||||
| 'User:', | |||||
| ' Subcommands:', | |||||
| ' invite <address>... invite the given list of e-mail addresses to your datadog org' | |||||
| ]; | |||||
| }, | }, | ||||
| handleCli: function(subcommand, args, callback){ | |||||
| invite(args._.slice(4), callback) | |||||
| handleCli(subcommand, args, callback) { | |||||
| invite(args._.slice(4), callback); | |||||
| } | } | ||||
| }; | |||||
| }; | }; | ||||
| @ -1,13 +1,13 @@ | |||||
| module.exports.STATUSES = { | module.exports.STATUSES = { | ||||
| OK: 0, | |||||
| WARNING: 1, | |||||
| CRITICAL: 2, | |||||
| UNKNOWN: 3, | |||||
| OK: 0, | |||||
| WARNING: 1, | |||||
| CRITICAL: 2, | |||||
| UNKNOWN: 3 | |||||
| }; | }; | ||||
| module.exports.ALL_STATUSES = [ | module.exports.ALL_STATUSES = [ | ||||
| module.exports.STATUSES.OK, | |||||
| module.exports.STATUSES.WARNING, | |||||
| module.exports.STATUSES.CRITICAL, | |||||
| module.exports.STATUSES.UNKNOWN, | |||||
| module.exports.STATUSES.OK, | |||||
| module.exports.STATUSES.WARNING, | |||||
| module.exports.STATUSES.CRITICAL, | |||||
| module.exports.STATUSES.UNKNOWN | |||||
| ]; | ]; | ||||
| @ -1,7 +1,6 @@ | |||||
| var JSONBig = require("json-bigint"); | |||||
| const JSONBig = require('json-bigint'); | |||||
| module.exports = { | module.exports = { | ||||
| stringify: JSONBig.stringify, | |||||
| parse: JSONBig.parse | |||||
| stringify: JSONBig.stringify, | |||||
| parse: JSONBig.parse | |||||
| }; | }; | ||||
| @ -1,84 +1,86 @@ | |||||
| var assert = require("assert"); | |||||
| var client = require("../../lib/client"); | |||||
| var extend = require("extend"); | |||||
| var embed = require("../../lib/api/embed"); | |||||
| var sinon = require("sinon"); | |||||
| var querystring = require("querystring"); | |||||
| const assert = require('assert'); | |||||
| const querystring = require('querystring'); | |||||
| const sinon = require('sinon'); | |||||
| const Client = require('../../lib/client'); | |||||
| const Embed = require('../../lib/api/embed'); | |||||
| describe("api/embed", function(){ | |||||
| var stub_request; | |||||
| beforeEach(function(){ | |||||
| // Setup `client.request` as a stub | |||||
| stub_request = sinon.stub(client, "request"); | |||||
| describe('api/embed', function() { | |||||
| const client = new Client({}); | |||||
| const embed = Embed(client); | |||||
| let stub_request; | |||||
| describe('#create', function() { | |||||
| beforeEach(function() { | |||||
| // Setup `client.request` as a stub | |||||
| stub_request = sinon.stub(client, 'request'); | |||||
| }); | }); | ||||
| afterEach(function(){ | |||||
| // Reset the original `client.request` | |||||
| stub_request.restore(); | |||||
| stub_request = null; | |||||
| afterEach(function() { | |||||
| // Reset the original `client.request` | |||||
| stub_request.restore(); | |||||
| stub_request = null; | |||||
| }); | }); | ||||
| describe("#create", function(){ | |||||
| it("should make a valid api call", function(){ | |||||
| var graphJSON = { | |||||
| viz: "timeseries", | |||||
| requests: [ | |||||
| { | |||||
| q: "system.cpu.idle{*}" | |||||
| } | |||||
| ] | |||||
| }; | |||||
| var options = { | |||||
| timeframe: "1_hour", | |||||
| size: "large", | |||||
| legend: "yes", | |||||
| title: "test graph embed" | |||||
| }; | |||||
| it('should make a valid api call', function() { | |||||
| const graphJSON = { | |||||
| viz: 'timeseries', | |||||
| requests: [ | |||||
| { | |||||
| q: 'system.cpu.idle{*}' | |||||
| } | |||||
| ] | |||||
| }; | |||||
| const options = { | |||||
| timeframe: '1_hour', | |||||
| size: 'large', | |||||
| legend: 'yes', | |||||
| title: 'test graph embed' | |||||
| }; | |||||
| // Make our api call | |||||
| embed.create(graphJSON, options); | |||||
| // Make our api call | |||||
| embed.create(graphJSON, options); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], "POST"); | |||||
| assert.equal(call_args[1], "/graph/embed"); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], 'POST'); | |||||
| assert.equal(call_args[1], '/graph/embed'); | |||||
| // Properly formatted body and content-type | |||||
| var params = call_args[2]; | |||||
| var expectedBody = { | |||||
| graph_json: JSON.stringify(graphJSON), | |||||
| timeframe: "1_hour", | |||||
| size: "large", | |||||
| legend: "yes", | |||||
| title: "test graph embed" | |||||
| }; | |||||
| assert.deepEqual(querystring.parse(params.body), expectedBody); | |||||
| assert(params.contentType, "application/x-form-urlencoded"); | |||||
| }); | |||||
| // Properly formatted body and content-type | |||||
| const params = call_args[2]; | |||||
| const expectedBody = { | |||||
| graph_json: JSON.stringify(graphJSON), | |||||
| timeframe: '1_hour', | |||||
| size: 'large', | |||||
| legend: 'yes', | |||||
| title: 'test graph embed' | |||||
| }; | |||||
| assert.deepEqual(querystring.parse(params.body), expectedBody); | |||||
| assert(params.contentType, 'application/x-form-urlencoded'); | |||||
| }); | |||||
| it("should only require graph_json", function(){ | |||||
| var graphJSON = { | |||||
| viz: "timeseries", | |||||
| requests: [ | |||||
| { | |||||
| q: "system.cpu.idle{*}" | |||||
| } | |||||
| ] | |||||
| }; | |||||
| it('should only require graph_json', function() { | |||||
| const graphJSON = { | |||||
| viz: 'timeseries', | |||||
| requests: [ | |||||
| { | |||||
| q: 'system.cpu.idle{*}' | |||||
| } | |||||
| ] | |||||
| }; | |||||
| // Make our api call | |||||
| embed.create(graphJSON); | |||||
| // Make our api call | |||||
| embed.create(graphJSON); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // Properly formatted body | |||||
| var params = call_args[2]; | |||||
| var expectedBody = { | |||||
| graph_json: JSON.stringify(graphJSON) | |||||
| }; | |||||
| assert.deepEqual(querystring.parse(params.body), expectedBody); | |||||
| }); | |||||
| // Properly formatted body | |||||
| const params = call_args[2]; | |||||
| const expectedBody = { | |||||
| graph_json: JSON.stringify(graphJSON) | |||||
| }; | |||||
| assert.deepEqual(querystring.parse(params.body), expectedBody); | |||||
| }); | }); | ||||
| }); | |||||
| }); | }); | ||||
| @ -1,10 +0,0 @@ | |||||
| var assert = require("assert"); | |||||
| var client = require("../../lib/client"); | |||||
| var extend = require("extend"); | |||||
| var graph = require("../../lib/api/graph"); | |||||
| var sinon = require("sinon"); | |||||
| var querystring = require("querystring"); | |||||
| describe("api/graph", function(){ | |||||
| }); | |||||
| @ -1,355 +1,355 @@ | |||||
| var assert = require("assert"); | |||||
| var client = require("../../lib/client"); | |||||
| var extend = require("extend"); | |||||
| var metric = require("../../lib/api/metric"); | |||||
| var sinon = require("sinon"); | |||||
| describe("api/metrics", function(){ | |||||
| var stub_request; | |||||
| beforeEach(function(){ | |||||
| // Setup `client.request` as a stub | |||||
| stub_request = sinon.stub(client, "request"); | |||||
| const assert = require('assert'); | |||||
| const sinon = require('sinon'); | |||||
| const Client = require('../../lib/client'); | |||||
| const Metric = require('../../lib/api/metric'); | |||||
| describe('api/metrics', function() { | |||||
| const client = new Client({}); | |||||
| const metric = Metric(client); | |||||
| let stub_request; | |||||
| beforeEach(function() { | |||||
| // Setup `client.request` as a stub | |||||
| stub_request = sinon.stub(client, 'request'); | |||||
| }); | |||||
| afterEach(function() { | |||||
| // Reset the original `client.request` | |||||
| stub_request.restore(); | |||||
| stub_request = null; | |||||
| }); | |||||
| describe('#send', function() { | |||||
| it('should make a valid api call', function() { | |||||
| // Make our api call | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| metric.send('metric.send', [[now, 500]]); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], 'POST'); | |||||
| assert.equal(call_args[1], '/series'); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send", host: undefined, tags: undefined, type: undefined} ] } | |||||
| // DEV: host/tags/type are optional and should be undefined for this case | |||||
| const data = call_args[2]; | |||||
| assert(data.hasOwnProperty('body')); | |||||
| assert(data.body.hasOwnProperty('series')); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| const series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", points: [], ...} | |||||
| const first_series = series[0]; | |||||
| assert.equal(first_series.metric, 'metric.send'); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.points, [[now, 500]]); | |||||
| // These keys are optional and should be set, but undefined | |||||
| assert(first_series.hasOwnProperty('host')); | |||||
| assert.equal(first_series.host, undefined); | |||||
| assert(first_series.hasOwnProperty('tags')); | |||||
| assert.equal(first_series.tags, undefined); | |||||
| assert(first_series.hasOwnProperty('type')); | |||||
| assert.equal(first_series.type, undefined); | |||||
| }); | }); | ||||
| afterEach(function(){ | |||||
| // Reset the original `client.request` | |||||
| stub_request.restore(); | |||||
| stub_request = null; | |||||
| it('should properly normalize values to points', function() { | |||||
| // Make our api call | |||||
| metric.send('metrics.send.normalize', 500); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| const body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // points = [ [<timestamp>, 500] ] | |||||
| const points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| // point = [<timestamp>, 500] | |||||
| const point = points[0]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.equal(point.length, 2); | |||||
| assert.equal(point[1], 500); | |||||
| }); | |||||
| it('should properly normalize array of values to points', function() { | |||||
| // Make our api call | |||||
| metric.send('metrics.send.normalize', [500, 1000]); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| const body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] | |||||
| const points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 2); | |||||
| // point = [<timestamp>, 500] | |||||
| let point = points[0]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.equal(point.length, 2); | |||||
| assert.equal(point[1], 500); | |||||
| // point = [<timestamp>, 1000] | |||||
| point = points[1]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.equal(point.length, 2); | |||||
| assert.equal(point[1], 1000); | |||||
| }); | |||||
| it('should not normalize correctly formatted points', function() { | |||||
| // Make our api call | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| metric.send('metrics.send.normalize', [[now, 1000]]); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| const body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // points = [ [<timestamp>, 1000], ] | |||||
| const points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| // point = [<timestamp>, 500] | |||||
| const point = points[0]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.deepEqual(point, [now, 1000]); | |||||
| }); | |||||
| it('should properly set metric type', function() { | |||||
| // Make our api call | |||||
| metric.send('metrics.send.counter', 5, {type: 'count'}); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| const body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| const series = body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| const first_series = series[0]; | |||||
| assert.equal(first_series.metric, 'metrics.send.counter'); | |||||
| assert(first_series.hasOwnProperty('type')); | |||||
| assert.equal(first_series.type, 'count'); | |||||
| }); | }); | ||||
| describe("#send", function(){ | |||||
| it("should make a valid api call", function(){ | |||||
| // Make our api call | |||||
| var now = parseInt(new Date().getTime() / 1000); | |||||
| metric.send("metric.send", [[now, 500]]); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], "POST"); | |||||
| assert.equal(call_args[1], "/series"); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send", host: undefined, tags: undefined, type: undefined} ] } | |||||
| // DEV: host/tags/type are optional and should be undefined for this case | |||||
| var data = call_args[2]; | |||||
| assert(data.hasOwnProperty("body")); | |||||
| assert(data.body.hasOwnProperty("series")); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| var series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", points: [], ...} | |||||
| var first_series = series[0] | |||||
| assert.equal(first_series.metric, "metric.send"); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.points, [[now, 500]]); | |||||
| // These keys are optional and should be set, but undefined | |||||
| assert(first_series.hasOwnProperty("host")); | |||||
| assert.equal(first_series.host, undefined); | |||||
| assert(first_series.hasOwnProperty("tags")); | |||||
| assert.equal(first_series.tags, undefined); | |||||
| assert(first_series.hasOwnProperty("type")); | |||||
| assert.equal(first_series.type, undefined); | |||||
| }); | |||||
| it("should properly normalize values to points", function(){ | |||||
| // Make our api call | |||||
| metric.send("metrics.send.normalize", 500); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| var body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // points = [ [<timestamp>, 500] ] | |||||
| var points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| // point = [<timestamp>, 500] | |||||
| var point = points[0]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.equal(point.length, 2); | |||||
| assert.equal(point[1], 500); | |||||
| }); | |||||
| it("should properly normalize array of values to points", function(){ | |||||
| // Make our api call | |||||
| metric.send("metrics.send.normalize", [500, 1000]); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| var body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] | |||||
| var points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 2); | |||||
| // point = [<timestamp>, 500] | |||||
| var point = points[0]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.equal(point.length, 2); | |||||
| assert.equal(point[1], 500); | |||||
| // point = [<timestamp>, 1000] | |||||
| point = points[1]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.equal(point.length, 2); | |||||
| assert.equal(point[1], 1000); | |||||
| }); | |||||
| it("should not normalize correctly formatted points", function(){ | |||||
| // Make our api call | |||||
| var now = parseInt(new Date().getTime() / 1000); | |||||
| metric.send("metrics.send.normalize", [[now, 1000]]); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| var body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // points = [ [<timestamp>, 1000], ] | |||||
| var points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| // point = [<timestamp>, 500] | |||||
| var point = points[0]; | |||||
| assert(Array.isArray(point)); | |||||
| assert.deepEqual(point, [now, 1000]); | |||||
| }); | |||||
| it("should properly set metric type", function(){ | |||||
| // Make our api call | |||||
| metric.send("metrics.send.counter", 5, {type: "count"}); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| var body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| var series = body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| var first_series = series[0] | |||||
| assert.equal(first_series.metric, "metrics.send.counter"); | |||||
| assert(first_series.hasOwnProperty("type")); | |||||
| assert.equal(first_series.type, "count"); | |||||
| }); | |||||
| it("should properly set convert metric_type to type", function(){ | |||||
| // Make our api call | |||||
| metric.send("metrics.send.counter", 5, {metric_type: "count"}); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| var body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| var series = body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| var first_series = series[0] | |||||
| assert.equal(first_series.metric, "metrics.send.counter"); | |||||
| assert(first_series.hasOwnProperty("type")); | |||||
| assert.equal(first_series.type, "count"); | |||||
| }); | |||||
| it('should properly set convert metric_type to type', function() { | |||||
| // Make our api call | |||||
| metric.send('metrics.send.counter', 5, {metric_type: 'count'}); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| const body = call_args[2].body; | |||||
| assert.equal(body.series.length, 1); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| const series = body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| const first_series = series[0]; | |||||
| assert.equal(first_series.metric, 'metrics.send.counter'); | |||||
| assert(first_series.hasOwnProperty('type')); | |||||
| assert.equal(first_series.type, 'count'); | |||||
| }); | |||||
| }); | |||||
| describe('#send_all', function() { | |||||
| it('should make a valid api call', function() { | |||||
| // Make our api call | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| const metrics = [ | |||||
| { | |||||
| metric: 'metric.send_all', | |||||
| points: [[now, 500]] | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], 'POST'); | |||||
| assert.equal(call_args[1], '/series'); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send_all", host: undefined, tags: undefined, type: undefined} ] } | |||||
| // DEV: host/tags/type are optional and should be undefined for this case | |||||
| const data = call_args[2]; | |||||
| assert(data.hasOwnProperty('body')); | |||||
| assert(data.body.hasOwnProperty('series')); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| const series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", points: [], ...} | |||||
| const first_series = series[0]; | |||||
| assert.equal(first_series.metric, 'metric.send_all'); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.points, [[now, 500]]); | |||||
| }); | |||||
| it('should properly normalize metric points', function() { | |||||
| // Make our api call | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| const metrics = [ | |||||
| { | |||||
| metric: 'metric.send_all.normalize', | |||||
| points: [[now, 500]] | |||||
| }, | |||||
| { | |||||
| metric: 'metric.send_all.normalize', | |||||
| points: [500, 1000] | |||||
| }, | |||||
| { | |||||
| metric: 'metric.send_all.normalize', | |||||
| points: 1000 | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| const body = call_args[2].body; | |||||
| assert.equal(body.series.length, 3); | |||||
| // points = [ [<timestamp>, 500] ] | |||||
| let points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| assert.equal(points[0].length, 2); | |||||
| assert.equal(points[0][1], 500); | |||||
| // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] | |||||
| points = body.series[1].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 2); | |||||
| assert.equal(points[0].length, 2); | |||||
| assert.equal(points[0][1], 500); | |||||
| assert.equal(points[1].length, 2); | |||||
| assert.equal(points[1][1], 1000); | |||||
| // points = [ [<timestamp>, 1000] ] | |||||
| points = body.series[2].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| assert.equal(points[0].length, 2); | |||||
| assert.equal(points[0][1], 1000); | |||||
| }); | |||||
| it('should properly send metric type', function() { | |||||
| // Make our api call | |||||
| const metrics = [ | |||||
| { | |||||
| metric: 'metric.send.counter', | |||||
| points: 5, | |||||
| type: 'count' | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], 'POST'); | |||||
| assert.equal(call_args[1], '/series'); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } | |||||
| // DEV: host/tags are optional and should be undefined for this case | |||||
| const data = call_args[2]; | |||||
| assert(data.hasOwnProperty('body')); | |||||
| assert(data.body.hasOwnProperty('series')); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| const series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| const first_series = series[0]; | |||||
| assert.equal(first_series.metric, 'metric.send.counter'); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.type, 'count'); | |||||
| }); | }); | ||||
| describe("#send_all", function(){ | |||||
| it("should make a valid api call", function(){ | |||||
| // Make our api call | |||||
| var now = parseInt(new Date().getTime() / 1000); | |||||
| var metrics = [ | |||||
| { | |||||
| metric: "metric.send_all", | |||||
| points: [[now, 500]] | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], "POST"); | |||||
| assert.equal(call_args[1], "/series"); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send_all", host: undefined, tags: undefined, type: undefined} ] } | |||||
| // DEV: host/tags/type are optional and should be undefined for this case | |||||
| var data = call_args[2]; | |||||
| assert(data.hasOwnProperty("body")); | |||||
| assert(data.body.hasOwnProperty("series")); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| var series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", points: [], ...} | |||||
| var first_series = series[0] | |||||
| assert.equal(first_series.metric, "metric.send_all"); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.points, [[now, 500]]); | |||||
| }); | |||||
| it("should properly normalize metric points", function(){ | |||||
| // Make our api call | |||||
| var now = parseInt(new Date().getTime() / 1000); | |||||
| var metrics = [ | |||||
| { | |||||
| metric: "metric.send_all.normalize", | |||||
| points: [[now, 500]] | |||||
| }, | |||||
| { | |||||
| metric: "metric.send_all.normalize", | |||||
| points: [500, 1000] | |||||
| }, | |||||
| { | |||||
| metric: "metric.send_all.normalize", | |||||
| points: 1000 | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we called `client.request` with the correct `points` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // { body: series: [ {points: [], }, ] } | |||||
| var body = call_args[2].body; | |||||
| assert.equal(body.series.length, 3); | |||||
| // points = [ [<timestamp>, 500] ] | |||||
| var points = body.series[0].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| assert.equal(points[0].length, 2); | |||||
| assert.equal(points[0][1], 500); | |||||
| // points = [ [<timestamp>, 500], [<timestamp>, 1000] ] | |||||
| points = body.series[1].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 2); | |||||
| assert.equal(points[0].length, 2); | |||||
| assert.equal(points[0][1], 500); | |||||
| assert.equal(points[1].length, 2); | |||||
| assert.equal(points[1][1], 1000); | |||||
| // points = [ [<timestamp>, 1000] ] | |||||
| points = body.series[2].points; | |||||
| assert(Array.isArray(points)); | |||||
| assert.equal(points.length, 1); | |||||
| assert.equal(points[0].length, 2); | |||||
| assert.equal(points[0][1], 1000); | |||||
| }); | |||||
| it("should properly send metric type", function(){ | |||||
| // Make our api call | |||||
| var metrics = [ | |||||
| { | |||||
| metric: "metric.send.counter", | |||||
| points: 5, | |||||
| type: "count" | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], "POST"); | |||||
| assert.equal(call_args[1], "/series"); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } | |||||
| // DEV: host/tags are optional and should be undefined for this case | |||||
| var data = call_args[2]; | |||||
| assert(data.hasOwnProperty("body")); | |||||
| assert(data.body.hasOwnProperty("series")); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| var series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| var first_series = series[0] | |||||
| assert.equal(first_series.metric, "metric.send.counter"); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.type, "count"); | |||||
| }); | |||||
| it("should properly send metric_type as type", function(){ | |||||
| // Make our api call | |||||
| var metrics = [ | |||||
| { | |||||
| metric: "metric.send.counter", | |||||
| points: 5, | |||||
| metric_type: "count" | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| var call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], "POST"); | |||||
| assert.equal(call_args[1], "/series"); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } | |||||
| // DEV: host/tags are optional and should be undefined for this case | |||||
| var data = call_args[2]; | |||||
| assert(data.hasOwnProperty("body")); | |||||
| assert(data.body.hasOwnProperty("series")); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| var series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| var first_series = series[0] | |||||
| assert.equal(first_series.metric, "metric.send.counter"); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.type, "count"); | |||||
| }); | |||||
| it('should properly send metric_type as type', function() { | |||||
| // Make our api call | |||||
| const metrics = [ | |||||
| { | |||||
| metric: 'metric.send.counter', | |||||
| points: 5, | |||||
| metric_type: 'count' | |||||
| } | |||||
| ]; | |||||
| metric.send_all(metrics); | |||||
| // Assert we properly called `client.request` | |||||
| assert(stub_request.calledOnce); | |||||
| const call_args = stub_request.getCall(0).args; | |||||
| // Method and endpoint are correct | |||||
| assert.equal(call_args[0], 'POST'); | |||||
| assert.equal(call_args[1], '/series'); | |||||
| // Properly formatted body | |||||
| // { body: series: [ {metric: "metric.send.counter", host: undefined, tags: undefined, type: "count"} ] } | |||||
| // DEV: host/tags are optional and should be undefined for this case | |||||
| const data = call_args[2]; | |||||
| assert(data.hasOwnProperty('body')); | |||||
| assert(data.body.hasOwnProperty('series')); | |||||
| // Assert we have only 1 series | |||||
| // series = [ {metric: "", ...}, ... ] | |||||
| const series = data.body.series; | |||||
| assert(Array.isArray(series)); | |||||
| assert.equal(series.length, 1); | |||||
| // Assert the first series is properly formatted | |||||
| // first_series = {metric: "", type: "count", points: [], ...} | |||||
| const first_series = series[0]; | |||||
| assert.equal(first_series.metric, 'metric.send.counter'); | |||||
| assert(Array.isArray(first_series.points)); | |||||
| assert.deepEqual(first_series.type, 'count'); | |||||
| }); | }); | ||||
| }); | |||||
| }); | }); | ||||
| @ -1,26 +1,26 @@ | |||||
| var assert = require("assert"); | |||||
| var BigNumber = require("bignumber.js"); | |||||
| var json = require("../lib/json"); | |||||
| const assert = require('assert'); | |||||
| const BigNumber = require('bignumber.js'); | |||||
| const json = require('../lib/json'); | |||||
| describe("json", function(){ | |||||
| describe("#parse()", function(){ | |||||
| it("should properly parse big integers", function(){ | |||||
| // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 | |||||
| var data = "{\"id\": 2868860079149422351}"; | |||||
| var parsed = json.parse(data); | |||||
| // `parsed.id` is an instance of `BigNumber` | |||||
| assert.equal(parsed.id.toString(), "2868860079149422351"); | |||||
| }); | |||||
| describe('json', function() { | |||||
| describe('#parse()', function() { | |||||
| it('should properly parse big integers', function() { | |||||
| // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 | |||||
| const data = '{"id": 2868860079149422351}'; | |||||
| const parsed = json.parse(data); | |||||
| // `parsed.id` is an instance of `BigNumber` | |||||
| assert.equal(parsed.id.toString(), '2868860079149422351'); | |||||
| }); | }); | ||||
| }); | |||||
| describe("#stringify()", function(){ | |||||
| it("should properly parse big integers", function(){ | |||||
| // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 | |||||
| var data = {"id": new BigNumber('2868860079149422351')}; | |||||
| var stringified = json.stringify(data); | |||||
| // Yeah, it ends up being a string and not an int, but mostly we | |||||
| // want to make sure it doesn't throw an error or provide the wrong number | |||||
| assert.equal(stringified, "{\"id\":\"2868860079149422351\"}"); | |||||
| }); | |||||
| describe('#stringify()', function() { | |||||
| it('should properly parse big integers', function() { | |||||
| // DEV: This test case is from: https://github.com/brettlangdon/node-dogapi/issues/16 | |||||
| const data = {id: new BigNumber('2868860079149422351')}; | |||||
| const stringified = json.stringify(data); | |||||
| // Yeah, it ends up being a string and not an int, but mostly we | |||||
| // want to make sure it doesn't throw an error or provide the wrong number | |||||
| assert.equal(stringified, '{"id":"2868860079149422351"}'); | |||||
| }); | }); | ||||
| }); | |||||
| }); | }); | ||||