| @ -1,157 +1,158 @@ | |||||
| const client = require("../client"); | |||||
| const 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 = {}; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| message: 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; | |||||
| } | |||||
| } | |||||
| client.request("POST", "/comments", params, callback); | |||||
| } | } | ||||
| const params = { | |||||
| body: { | |||||
| message: message | |||||
| /*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; | |||||
| } | } | ||||
| }; | |||||
| if(typeof properties === "object"){ | |||||
| if(properties.handle){ | |||||
| const params = { | |||||
| body: { | |||||
| message: message | |||||
| } | |||||
| }; | |||||
| if (handle) { | |||||
| params.body.handle = 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); | |||||
| } | |||||
| /*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; | |||||
| client.request("PUT", util.format("/comments/%s", commentId), params, callback); | |||||
| } | } | ||||
| const params = { | |||||
| body: { | |||||
| message: message | |||||
| } | |||||
| }; | |||||
| if(handle){ | |||||
| params.body.handle = properties.handle; | |||||
| /*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); | |||||
| } | } | ||||
| 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); | |||||
| } | |||||
| 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>" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(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"]); | |||||
| return { | |||||
| 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>" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (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 { | |||||
| callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); | |||||
| } | } | ||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi comment --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,242 +1,243 @@ | |||||
| const client = require("../client"); | |||||
| const 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 = {}; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| scope: scope | |||||
| } | |||||
| }; | |||||
| if(typeof properties === "object"){ | |||||
| if(properties.start){ | |||||
| params.body.start = parseInt(properties.start); | |||||
| 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 = {}; | |||||
| } | } | ||||
| if(properties.end){ | |||||
| params.body.end = parseInt(properties.end); | |||||
| } | |||||
| if(properties.message){ | |||||
| params.body.message = properties.message; | |||||
| const params = { | |||||
| body: { | |||||
| scope: 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; | |||||
| } | |||||
| } | } | ||||
| 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 = {}; | |||||
| } | |||||
| const params = { | |||||
| body: {} | |||||
| }; | |||||
| if(typeof properties === "object"){ | |||||
| if(properties.scope){ | |||||
| params.body.scope = properties.scope; | |||||
| /*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 = {}; | |||||
| } | } | ||||
| 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; | |||||
| 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; | |||||
| } | |||||
| } | } | ||||
| 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", | |||||
| ]; | |||||
| }, | |||||
| 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\")" | |||||
| ]; | |||||
| }, | |||||
| 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"){ | |||||
| const scope = args._[4]; | |||||
| const properties = {}; | |||||
| if(args["start"]){ | |||||
| properties.start = parseInt(args["start"]); | |||||
| } | |||||
| if(args["end"]){ | |||||
| properties.end = parseInt(args["end"]); | |||||
| return { | |||||
| 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", | |||||
| ]; | |||||
| }, | |||||
| 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\")" | |||||
| ]; | |||||
| }, | |||||
| 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") { | |||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false); | |||||
| } | } | ||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,170 +1,172 @@ | |||||
| const client = require("../client"); | |||||
| const extend = require("extend"); | const extend = require("extend"); | ||||
| const json = require("../json"); | |||||
| const json = require("../json"); // TODO inline lib | |||||
| const querystring = require("querystring"); | const querystring = require("querystring"); | ||||
| /*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 = {}; | |||||
| } | |||||
| const body = { | |||||
| graph_json: JSON.stringify(graphJSON) | |||||
| }; | |||||
| // Use `extend` to merge `options` into `body` | |||||
| // DEV: `extend` will ignore any properties whose value is `undefined` | |||||
| extend(body, options || {}); | |||||
| module.exports = function (client) { | |||||
| // Create the request | |||||
| const params = { | |||||
| body: querystring.stringify(body), | |||||
| contentType: "application/x-www-form-urlencoded" | |||||
| }; | |||||
| /*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 = {}; | |||||
| } | |||||
| const body = { | |||||
| graph_json: JSON.stringify(graphJSON) | |||||
| }; | |||||
| // Use `extend` to merge `options` into `body` | |||||
| // DEV: `extend` will ignore any properties whose value is `undefined` | |||||
| extend(body, options || {}); | |||||
| client.request("POST", "/graph/embed", params, callback); | |||||
| } | |||||
| // Create the request | |||||
| const params = { | |||||
| body: querystring.stringify(body), | |||||
| contentType: "application/x-www-form-urlencoded" | |||||
| }; | |||||
| /*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); | |||||
| } | |||||
| 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 | |||||
| * 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 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 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); | |||||
| } | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| return { | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(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 { | |||||
| callback("unknown subcommand or arguments try `dogapi embed --help` for help", false); | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (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 { | |||||
| callback("unknown subcommand or arguments try `dogapi embed --help` for help", false); | |||||
| } | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,209 +1,210 @@ | |||||
| const client = require("../client"); | |||||
| const 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 | |||||
| * 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 = {}; | |||||
| } | |||||
| properties.title = title; | |||||
| properties.text = text; | |||||
| const params = { | |||||
| body: properties | |||||
| }; | |||||
| client.request("POST", "/events", params, callback); | |||||
| } | |||||
| 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 = {}; | |||||
| } | |||||
| /*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); | |||||
| } | |||||
| properties.title = title; | |||||
| properties.text = text; | |||||
| /*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 argument[2] === "function"){ | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| const params = { | |||||
| body: properties | |||||
| }; | |||||
| client.request("POST", "/events", params, callback); | |||||
| } | } | ||||
| if(typeof parameters !== "object"){ | |||||
| parameters = {} | |||||
| /*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); | |||||
| } | } | ||||
| parameters.start = start; | |||||
| parameters.end = end; | |||||
| const params = { | |||||
| query: 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 argument[2] === "function") { | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| } | |||||
| client.request("GET", "/events", params, callback); | |||||
| } | |||||
| if (typeof parameters !== "object") { | |||||
| parameters = {} | |||||
| } | |||||
| parameters.start = start; | |||||
| parameters.end = end; | |||||
| 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>]" | |||||
| ]; | |||||
| }, | |||||
| 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)" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(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"]; | |||||
| const params = { | |||||
| query: parameters | |||||
| }; | |||||
| client.request("GET", "/events", params, callback); | |||||
| } | |||||
| return { | |||||
| 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>]" | |||||
| ]; | |||||
| }, | |||||
| 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)" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (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 { | |||||
| callback("unknown subcommand or arguments try `dogapi event --help` for help", false); | |||||
| } | } | ||||
| create(title, text, properties, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi event --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,75 +1,78 @@ | |||||
| const client = require("../client"); | |||||
| const 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 | |||||
| * 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; | |||||
| } | |||||
| const params = { | |||||
| query: { | |||||
| metric_query: query, | |||||
| start: parseInt(from), | |||||
| end: parseInt(to) | |||||
| 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; | |||||
| } | |||||
| 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, | |||||
| createEmbed: embed.create, | |||||
| getUsage: function(){ | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(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 { | |||||
| callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); | |||||
| return { | |||||
| snapshot: snapshot, | |||||
| createEmbed: embed.create, | |||||
| getUsage: function () { | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (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 { | |||||
| callback("unknown subcommand or arguments try `dogapi graph --help` for help", false); | |||||
| } | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,108 +1,109 @@ | |||||
| const client = require("../client"); | |||||
| const 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 | |||||
| * 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 = {}; | |||||
| } | |||||
| const params = {}; | |||||
| if(typeof options === "object"){ | |||||
| params.body = {}; // create body property | |||||
| if(options.end){ | |||||
| params.body.end = parseInt(options.end); | |||||
| 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 = {}; | |||||
| } | } | ||||
| 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 { | |||||
| params.body = ""; // create empty body | |||||
| } | } | ||||
| } else { | |||||
| 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 | |||||
| * 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); | |||||
| } | |||||
| /*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>" | |||||
| ]; | |||||
| }, | |||||
| getHelp: function(){ | |||||
| return [ | |||||
| "Host:", | |||||
| " Subcommands:", | |||||
| " mute <host> mute the host with the provided hostname", | |||||
| " unmute <host> unmute the host with the provided hostname", | |||||
| "", | |||||
| " Options:", | |||||
| " --end <end> POSIX timestamp for when the mute should end", | |||||
| " --override override an existing \"end\" for a mute on a host" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(subcommand === "mute"){ | |||||
| const hostname = args._[4]; | |||||
| const options = {}; | |||||
| if(args["end"]){ | |||||
| options.end = parseInt(args["end"]); | |||||
| } | |||||
| if(args["override"]){ | |||||
| options.override = args["override"]; | |||||
| return { | |||||
| mute: mute, | |||||
| unmute: unmute, | |||||
| getUsage: function () { | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (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 { | |||||
| callback("unknown subcommand or arguments try `dogapi host --help` for help", false); | |||||
| } | } | ||||
| mute(hostname, options, callback); | |||||
| } else if(subcommand === "unmute"){ | |||||
| const hostname = args._[4]; | |||||
| unmute(hostname, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi host --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,52 +1,52 @@ | |||||
| const client = require("../client"); | |||||
| 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); | |||||
| } | |||||
| /*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 | |||||
| } | |||||
| }; | |||||
| module.exports = { | |||||
| search: search, | |||||
| getUsage: function(){ | |||||
| 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)", | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| const query = args._[4]; | |||||
| search(query, callback); | |||||
| client.request("GET", "/search", params, callback); | |||||
| } | } | ||||
| return { | |||||
| search: search, | |||||
| getUsage: function () { | |||||
| 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)", | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (subcommand, args, callback) { | |||||
| const query = args._[4]; | |||||
| search(query, callback); | |||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,220 +1,221 @@ | |||||
| const client = require("../client"); | |||||
| module.exports = function (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 | |||||
| * 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: metric, | |||||
| points: points, | |||||
| host: extra.host, | |||||
| tags: extra.tags, | |||||
| // DEV: For backwards compatibility, allow `metric_type` | |||||
| type: extra.type || extra.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: metric, | |||||
| points: points, | |||||
| host: extra.host, | |||||
| tags: extra.tags, | |||||
| // DEV: For backwards compatibility, allow `metric_type` | |||||
| type: extra.type || extra.metric_type | |||||
| } | |||||
| ]; | |||||
| send_all(series, callback); | |||||
| } | |||||
| send_all(series, callback); | |||||
| } | |||||
| /*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)){ | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| point = [now, point]; | |||||
| /*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]; | |||||
| } | } | ||||
| return point; | |||||
| }); | |||||
| 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)) { | |||||
| const now = parseInt(new Date().getTime() / 1000); | |||||
| point = [now, point]; | |||||
| } | |||||
| return point; | |||||
| }); | |||||
| metrics[i].points = points; | |||||
| metrics[i].points = points; | |||||
| // 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; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| series: metrics | |||||
| // 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; | |||||
| } | } | ||||
| }; | |||||
| client.request("POST", "/series", params, 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 | |||||
| * 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, query, callback){ | |||||
| const params = { | |||||
| query: { | |||||
| from: from, | |||||
| to: to, | |||||
| query: query | |||||
| } | |||||
| }; | |||||
| client.request("GET", "/query", params, callback); | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| series: metrics | |||||
| } | |||||
| }; | |||||
| client.request("POST", "/series", 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>" | |||||
| ] | |||||
| }, | |||||
| 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\"" | |||||
| ] | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| if(args._.length > 5 && subcommand === "send"){ | |||||
| const extra = {}; | |||||
| if(args.tags){ | |||||
| extra.tags = args.tags.split(","); | |||||
| /*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 | |||||
| * 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, query, callback) { | |||||
| const params = { | |||||
| query: { | |||||
| from: from, | |||||
| to: to, | |||||
| query: query | |||||
| } | } | ||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); | |||||
| } | |||||
| }; | |||||
| client.request("GET", "/query", params, callback); | |||||
| } | } | ||||
| return { | |||||
| 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>" | |||||
| ] | |||||
| }, | |||||
| 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\"" | |||||
| ] | |||||
| }, | |||||
| handleCli: function (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 { | |||||
| callback("unknown subcommand or arguments try `dogapi metric --help` for help", false); | |||||
| } | |||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,454 +1,456 @@ | |||||
| const client = require("../client"); | |||||
| const 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 | |||||
| * 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 = {}; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| type: type, | |||||
| query: query | |||||
| } | |||||
| }; | |||||
| module.exports = function(client){ | |||||
| if(typeof properties === "object"){ | |||||
| if(properties.name){ | |||||
| params.body.name = properties.name; | |||||
| /*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 = {}; | |||||
| } | } | ||||
| 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); | |||||
| } | |||||
| /*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; | |||||
| } | |||||
| const params = {}; | |||||
| if(groupStates){ | |||||
| params.query = { | |||||
| group_states: groupStates.join(",") | |||||
| const params = { | |||||
| body: { | |||||
| type: type, | |||||
| query: query | |||||
| } | |||||
| }; | }; | ||||
| } | |||||
| 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 | |||||
| * 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 = {}; | |||||
| } | |||||
| const params = {}; | |||||
| if(typeof options === "object"){ | |||||
| params.query = {}; | |||||
| if(options.group_states){ | |||||
| params.query.group_states = options.group_states.join(","); | |||||
| 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(options.tags){ | |||||
| params.query.tags = options.tags.join(","); | |||||
| 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 | |||||
| * 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; | |||||
| } | } | ||||
| if(options.monitor_tags){ | |||||
| params.query.monitor_tags = options.monitor_tags.join(","); | |||||
| const params = {}; | |||||
| if(groupStates){ | |||||
| params.query = { | |||||
| group_states: groupStates.join(",") | |||||
| }; | |||||
| } | } | ||||
| client.request("GET", util.format("/monitor/%s", monitorId), 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 | |||||
| * 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 = {}; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| query: query | |||||
| /*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 = {}; | |||||
| } | } | ||||
| }; | |||||
| if(typeof properties === "object"){ | |||||
| if(properties.name){ | |||||
| params.body.name = properties.name; | |||||
| } | |||||
| if(properties.message){ | |||||
| params.body.message = properties.message; | |||||
| 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(","); | |||||
| } | |||||
| } | } | ||||
| if(properties.tags){ | |||||
| params.body.tags = properties.tags; | |||||
| 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 | |||||
| * 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 = {}; | |||||
| } | } | ||||
| if(typeof properties.options === "object"){ | |||||
| params.body.options = properties.options; | |||||
| const params = { | |||||
| body: { | |||||
| query: 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; | |||||
| } | |||||
| } | } | ||||
| 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 | |||||
| * 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 | |||||
| * 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 = {}; | |||||
| /*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); | |||||
| } | } | ||||
| const params = {}; | |||||
| if(typeof options === "object"){ | |||||
| params.body = {}; | |||||
| if(options.scope){ | |||||
| params.body.scope = options.scope; | |||||
| /*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 = {}; | |||||
| } | } | ||||
| 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 { | |||||
| params.body = ""; // create empty body | |||||
| } | } | ||||
| } else { | |||||
| params.body = ""; // create empty body | |||||
| } | |||||
| client.request("POST", util.format("/monitor/%s/mute", monitorId), params, 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 | |||||
| * 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; | |||||
| client.request("POST", util.format("/monitor/%s/mute", monitorId), params, callback); | |||||
| } | } | ||||
| const params = {}; | |||||
| if(scope){ | |||||
| params.body = { | |||||
| scope: scope | |||||
| }; | |||||
| } else { | |||||
| params.body = ""; // create empty body | |||||
| /*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); | |||||
| } | } | ||||
| client.request("POST", util.format("/monitor/%s/unmute", monitorId), params, 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>]" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| const states = []; | |||||
| if(args["states"]){ | |||||
| states = args["states"].split(","); | |||||
| /*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; | |||||
| } | } | ||||
| const tags = []; | |||||
| if(args["tags"]){ | |||||
| tags = args["tags"].split(","); | |||||
| const params = {}; | |||||
| if(scope){ | |||||
| params.body = { | |||||
| scope: scope | |||||
| }; | |||||
| } else { | |||||
| params.body = ""; // create empty body | |||||
| } | } | ||||
| const name = args["name"]; | |||||
| const message = args["message"]; | |||||
| if(subcommand === "get"){ | |||||
| const monitorId = args._[4]; | |||||
| get(monitorId, states, callback); | |||||
| } else if(subcommand === "getall"){ | |||||
| const options = {}; | |||||
| if(states.length){ | |||||
| options.group_states = states; | |||||
| } | |||||
| if(tags.length){ | |||||
| 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; | |||||
| client.request("POST", util.format("/monitor/%s/unmute", monitorId), params, 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); | |||||
| } | |||||
| return { | |||||
| 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>]" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| const states = []; | |||||
| if(args["states"]){ | |||||
| states = args["states"].split(","); | |||||
| } | } | ||||
| 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; | |||||
| const tags = []; | |||||
| if(args["tags"]){ | |||||
| tags = args["tags"].split(","); | |||||
| } | } | ||||
| if(message){ | |||||
| properties.message = message; | |||||
| const name = args["name"]; | |||||
| const message = args["message"]; | |||||
| if(subcommand === "get"){ | |||||
| const monitorId = args._[4]; | |||||
| get(monitorId, states, callback); | |||||
| } else if(subcommand === "getall"){ | |||||
| const options = {}; | |||||
| if(states.length){ | |||||
| options.group_states = states; | |||||
| } | |||||
| if(tags.length){ | |||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi monitor --help` for help", false); | |||||
| } | } | ||||
| update(monitorId, query, properties, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi monitor --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,351 +1,351 @@ | |||||
| const client = require("../client"); | |||||
| const json = require("../json"); | const json = require("../json"); | ||||
| const util = require("util"); | const util = require("util"); | ||||
| 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 = {}; | |||||
| } | |||||
| /*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 = {}; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| board_title: boardTitle, | |||||
| widgets: widgets | |||||
| } | |||||
| }; | |||||
| const params = { | |||||
| body: { | |||||
| board_title: boardTitle, | |||||
| widgets: widgets | |||||
| if (options.description) { | |||||
| params.body.description = options.description; | |||||
| } | |||||
| if (options.templateVariables) { | |||||
| params.body.template_variables = options.templateVariables; | |||||
| } | |||||
| if (options.width) { | |||||
| params.body.width = options.width; | |||||
| } | |||||
| if (options.height) { | |||||
| params.body.height = options.height; | |||||
| } | |||||
| if (options.readOnly) { | |||||
| params.body.read_only = options.readOnly; | |||||
| } | } | ||||
| }; | |||||
| if(options.description){ | |||||
| params.body.description = options.description; | |||||
| } | |||||
| if(options.templateVariables){ | |||||
| params.body.template_variables = options.templateVariables; | |||||
| } | |||||
| if(options.width){ | |||||
| params.body.width = options.width; | |||||
| } | |||||
| if(options.height){ | |||||
| params.body.height = options.height; | |||||
| } | |||||
| 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 | |||||
| * 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; | |||||
| options = {}; | |||||
| } | |||||
| if (typeof options !== "object") { | |||||
| options = {}; | |||||
| } | |||||
| /*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; | |||||
| options = {}; | |||||
| } | |||||
| if(typeof options !== "object"){ | |||||
| options = {}; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| board_title: boardTitle, | |||||
| widgets: widgets | |||||
| } | |||||
| }; | |||||
| const params = { | |||||
| body: { | |||||
| board_title: boardTitle, | |||||
| widgets: widgets | |||||
| } | |||||
| }; | |||||
| if (options.description) { | |||||
| params.body.description = options.description; | |||||
| } | |||||
| if (options.templateVariables) { | |||||
| params.body.template_variables = options.templateVariables; | |||||
| } | |||||
| if (options.width) { | |||||
| params.body.width = options.width; | |||||
| } | |||||
| if (options.height) { | |||||
| params.body.height = options.height; | |||||
| } | |||||
| if (options.readOnly) { | |||||
| params.body.read_only = options.readOnly; | |||||
| } | |||||
| if(options.description){ | |||||
| params.body.description = options.description; | |||||
| } | |||||
| if(options.templateVariables){ | |||||
| params.body.template_variables = options.templateVariables; | |||||
| } | |||||
| if(options.width){ | |||||
| params.body.width = options.width; | |||||
| } | |||||
| if(options.height){ | |||||
| params.body.height = options.height; | |||||
| } | |||||
| if(options.readOnly){ | |||||
| params.body.read_only = options.readOnly; | |||||
| } | |||||
| client.request("PUT", util.format("/screen/%s", boardId), params, callback); | |||||
| } | |||||
| 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 | |||||
| * 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: 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 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: 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: 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: 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); | |||||
| } | |||||
| /*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); | |||||
| } | |||||
| return { | |||||
| 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>" | |||||
| ]; | |||||
| }, | |||||
| 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", | |||||
| ]; | |||||
| }, | |||||
| 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") { | |||||
| const boardId = args._[4]; | |||||
| const boardTitle = args._[5]; | |||||
| const widgets = json.parse(args._[6]); | |||||
| 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>" | |||||
| ]; | |||||
| }, | |||||
| 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", | |||||
| ]; | |||||
| }, | |||||
| 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"){ | |||||
| const boardId = args._[4]; | |||||
| const boardTitle = args._[5]; | |||||
| const widgets = json.parse(args._[6]); | |||||
| 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"]); | |||||
| } | |||||
| 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"]); | |||||
| } | |||||
| update(boardId, boardTitle, widgets, options, callback); | |||||
| } else if (subcommand === "create") { | |||||
| const boardTitle = args._[4]; | |||||
| const widgets = json.parse(args._[5]); | |||||
| update(boardId, boardTitle, widgets, options, callback); | |||||
| } else if(subcommand === "create"){ | |||||
| const boardTitle = args._[4]; | |||||
| const 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"]); | |||||
| } | |||||
| 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"]); | |||||
| create(boardTitle, widgets, options, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi screenboard --help` for help", false); | |||||
| } | } | ||||
| if(args["height"]){ | |||||
| options.height = parseInt(args["height"]); | |||||
| } | |||||
| create(boardTitle, widgets, options, callback); | |||||
| } else { | |||||
| callback("unknown subcommand or arguments try `dogapi screenboard --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,53 +1,53 @@ | |||||
| const client = require("../client"); | |||||
| 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(query, callback) { | |||||
| const params = { | |||||
| query: { | |||||
| q: query | |||||
| } | |||||
| }; | |||||
| client.request("GET", "/search", params, callback); | |||||
| } | |||||
| /*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(query, callback){ | |||||
| const params = { | |||||
| query: { | |||||
| q: query | |||||
| return { | |||||
| query: query, | |||||
| getUsage: function () { | |||||
| return [ | |||||
| " dogapi search query <query>" | |||||
| ]; | |||||
| }, | |||||
| getHelp: function () { | |||||
| 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); | |||||
| } | |||||
| } | } | ||||
| }; | }; | ||||
| client.request("GET", "/search", params, callback); | |||||
| } | |||||
| module.exports = { | |||||
| query: query, | |||||
| getUsage: function(){ | |||||
| return [ | |||||
| " dogapi search query <query>" | |||||
| ]; | |||||
| }, | |||||
| getHelp: function(){ | |||||
| 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); | |||||
| } | |||||
| } | |||||
| }; | }; | ||||
| @ -1,89 +1,90 @@ | |||||
| const client = require("../client"); | |||||
| 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(check, hostName, status, parameters, callback){ | |||||
| if(arguments.length < 5 && typeof arguments[3] === "function"){ | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| } | |||||
| /*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(check, hostName, status, parameters, callback) { | |||||
| if (arguments.length < 5 && typeof arguments[3] === "function") { | |||||
| callback = parameters; | |||||
| parameters = {}; | |||||
| } | |||||
| if(typeof parameters !== "object"){ | |||||
| parameters = {}; | |||||
| } | |||||
| if (typeof parameters !== "object") { | |||||
| parameters = {}; | |||||
| } | |||||
| parameters.check = check; | |||||
| parameters.host_name = hostName, | |||||
| parameters.status = status; | |||||
| parameters.check = check; | |||||
| parameters.host_name = hostName, | |||||
| parameters.status = status; | |||||
| const params = { | |||||
| body: parameters | |||||
| const params = { | |||||
| body: parameters | |||||
| }; | |||||
| client.request("POST", "/check_run", params, callback); | |||||
| }; | }; | ||||
| 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){ | |||||
| const parameters = {}; | |||||
| if(args["time"]){ | |||||
| parameters.time = parseInt(args["time"]); | |||||
| return { | |||||
| 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) { | |||||
| const 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); | |||||
| } | } | ||||
| 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,265 @@ | |||||
| const client = require("../client"); | |||||
| const util = require('util'); | const util = require('util'); | ||||
| 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; | |||||
| } | |||||
| const params = { | |||||
| query: { | |||||
| source: source | |||||
| /*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; | |||||
| } | } | ||||
| }; | |||||
| 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 | |||||
| * 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 = {}; | |||||
| const params = { | |||||
| query: { | |||||
| source: source | |||||
| } | |||||
| }; | |||||
| client.request("GET", "/tags/hosts", params, callback); | |||||
| } | } | ||||
| options = options || {}; | |||||
| const params = { | |||||
| query: { | |||||
| /*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 = {}; | |||||
| } | } | ||||
| }; | |||||
| if(options.source){ | |||||
| params.query.source = options.source; | |||||
| } | |||||
| if(options.by_source){ | |||||
| params.query.by_source = options.by_source; | |||||
| } | |||||
| client.request("GET", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| options = options || {}; | |||||
| /*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; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| tags: tags, | |||||
| source: source | |||||
| }, | |||||
| const params = { | |||||
| query: { | |||||
| } | |||||
| }; | |||||
| if (options.source) { | |||||
| params.query.source = options.source; | |||||
| } | |||||
| if (options.by_source) { | |||||
| params.query.by_source = options.by_source; | |||||
| } | |||||
| client.request("GET", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | }; | ||||
| client.request("POST", "/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 | |||||
| * 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; | |||||
| } | |||||
| /*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; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| tags: tags, | |||||
| source: source | |||||
| }, | |||||
| }; | |||||
| const params = { | |||||
| body: { | |||||
| tags: tags, | |||||
| source: source | |||||
| }, | |||||
| client.request("POST", "/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 | |||||
| * 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; | |||||
| } | |||||
| const params = { | |||||
| query: { | |||||
| source: source | |||||
| /*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; | |||||
| } | } | ||||
| const params = { | |||||
| body: { | |||||
| tags: tags, | |||||
| source: source | |||||
| }, | |||||
| }; | |||||
| client.request("PUT", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | }; | ||||
| client.request("DELETE", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| module.exports = { | |||||
| _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>]" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function(subcommand, args, callback){ | |||||
| const source = args["source"]; | |||||
| const host = args._[4]; | |||||
| /*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; | |||||
| } | |||||
| if(subcommand === "getall"){ | |||||
| getAll(source, callback); | |||||
| } else if(subcommand === "get"){ | |||||
| const options = {}; | |||||
| if(source){ | |||||
| options.source = source; | |||||
| const params = { | |||||
| query: { | |||||
| source: source | |||||
| } | } | ||||
| if(args["by-source"]){ | |||||
| options.by_source = true; | |||||
| }; | |||||
| client.request("DELETE", "/tags/hosts/" + hostname, params, callback); | |||||
| }; | |||||
| return { | |||||
| _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>]" | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| handleCli: function (subcommand, args, callback) { | |||||
| const source = args["source"]; | |||||
| const host = args._[4]; | |||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi tag --help` for help", false); | |||||
| } | } | ||||
| 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi tag --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| } | |||||
| }; | |||||
| }; | |||||
| @ -1,275 +1,276 @@ | |||||
| const client = require("../client"); | |||||
| const json = require("../json"); | const json = require("../json"); | ||||
| const util = require("util"); | const util = require("util"); | ||||
| /*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 = []; | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| title: title, | |||||
| description: description, | |||||
| graphs: graphs | |||||
| 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 = []; | |||||
| } | } | ||||
| }; | |||||
| if(Array.isArray(templateVariables) && templateVariables.length){ | |||||
| params.body.template_variables = templateVariables; | |||||
| } | |||||
| client.request("POST", "/dash", params, callback); | |||||
| } | |||||
| const params = { | |||||
| body: { | |||||
| title: title, | |||||
| description: description, | |||||
| graphs: graphs | |||||
| } | |||||
| }; | |||||
| if (Array.isArray(templateVariables) && templateVariables.length) { | |||||
| params.body.template_variables = 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 = []; | |||||
| client.request("POST", "/dash", params, callback); | |||||
| } | } | ||||
| const params = { | |||||
| body: { | |||||
| title: title, | |||||
| description: description, | |||||
| graphs: graphs | |||||
| /*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 = []; | |||||
| } | } | ||||
| }; | |||||
| if(Array.isArray(templateVariables) && templateVariables.length){ | |||||
| params.body.template_variables = templateVariables; | |||||
| const params = { | |||||
| body: { | |||||
| title: title, | |||||
| description: description, | |||||
| graphs: graphs | |||||
| } | |||||
| }; | |||||
| if (Array.isArray(templateVariables) && templateVariables.length) { | |||||
| 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 | |||||
| * 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: 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 | |||||
| * 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 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 | |||||
| * 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); | |||||
| } | |||||
| /*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); | |||||
| } | |||||
| return { | |||||
| 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>]", | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| 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") { | |||||
| const title = args._[4]; | |||||
| const description = args._[5]; | |||||
| const graphs = json.parse(args._[6]); | |||||
| const templateVariables = []; | |||||
| if (args["tmpvars"]) { | |||||
| templateVariables = json.parse(args["tmpvars"]); | |||||
| } | |||||
| 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>]", | |||||
| ]; | |||||
| }, | |||||
| 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" | |||||
| ]; | |||||
| }, | |||||
| 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"){ | |||||
| const title = args._[4]; | |||||
| const description = args._[5]; | |||||
| const graphs = json.parse(args._[6]); | |||||
| const 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 = []; | |||||
| 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 = []; | |||||
| if(args["tmpvars"]){ | |||||
| templateVariables = 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 { | |||||
| callback("unknown subcommand or arguments try `dogapi timeboard --help` for help", false); | |||||
| } | } | ||||
| } | |||||
| }; | |||||
| }; | }; | ||||
| @ -1,48 +1,49 @@ | |||||
| const client = require("../client"); | |||||
| 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: emails | |||||
| } | |||||
| /*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: 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>..." | |||||
| ]; | |||||
| }, | |||||
| getHelp: function(){ | |||||
| 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) | |||||
| } | |||||
| return { | |||||
| invite: invite, | |||||
| getUsage: function () { | |||||
| return [ | |||||
| " dogapi user invite <address>..." | |||||
| ]; | |||||
| }, | |||||
| getHelp: function () { | |||||
| 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) | |||||
| } | |||||
| }; | |||||
| }; | }; | ||||