Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dogapi

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dogapi - npm Package Compare versions

Comparing version 0.2.3 to 1.0.0

bin/dogapi

318

lib/api/downtime.js

@@ -1,102 +0,242 @@

var util = require('util');
var client = require("../client");
var util = require("util");
var downtime_api = function(){};
downtime_api.prototype.schedule_downtime = function(scope, options, callback){
/*
* downtime_api.schedule_downtime(scope, [options], [callback])
*
* method to schedule a new downtime
*
* `scope` the scope to schedule downtime for
* `options` optional `start` `end` and `message` paramaters
* `callback` is an optional function to call with the results of the api call
* callback(error, results, status_code)
*/
if(typeof scope !== 'string'){
throw new Error('scope parameter must be a string');
/*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(typeof options === 'function'){
callback = options;
options = {};
var 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;
}
}
options.scope = scope;
client.request("POST", "/downtime", params, callback);
}
this.request('POST', '/downtime', {body: options}, callback);
};
downtime_api.prototype.update_downtime = function(downtime_id, options, callback){
/*
* downtime_api.update_downtime(downtime_id, [options], [callback])
*
* method to update an existing downtime
*
* `downtime_id` the id of the downtime
* `options` optional `scope` `start` `end` and `message` paramaters
* `callback` is an optional function to call with the results of the api call
* callback(error, results, status_code)
*/
if(typeof options === 'function'){
callback = options;
options = {};
/*section: downtime
*comment: update an existing downtime
*params:
* downtimeId: the id the downtie to update
* properties: |
* optional, an object containing any of the following
* * scope: the scope the downtime should be changed to (e.g. "env:staging")
* * start: POSIX timestamp for when the downtime should start
* * end: POSIX timestamp for when the downtime should end
* * message: a string message to accompany the downtime
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var properties = {
* scope: "env:staging"
* };
* dogapi.downtime.update(1234, properties, function(err, res){
* console.dir(res);
* });
* ```
*/
function update(downtimeId, properties, callback){
if(arguments.length < 3 && typeof arguments[1] === "function"){
callback = properties;
properties = {};
}
var params = {
body: {}
};
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);
}
this.request('PUT', util.format('/downtime/%s', downtime_id), {body: options}, 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);
}
downtime_api.prototype.get_downtime = function(downtime_id, callback){
/*
* downtime_api.get_downtime(downtime_id, [callback])
*
* method to get an existing downtime
*
* `downtime_id` the id of the downtime
* `callback` is an optional function to call with the results of the api call
* callback(error, results, status_code)
*/
/*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);
}
this.request('GET', util.format('/downtime/%s', downtime_id), 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);
}
downtime_api.prototype.cancel_downtime = function(downtime_id, callback){
/*
* downtime_api.cancel_downtime(downtime_id, [callback])
*
* method to cancel an existing downtime
*
* `downtime_id` the id of the downtime
* `callback` is an optional function to call with the results of the api call
* callback(error, results, status_code)
*/
this.request('DELETE', util.format('/downtime/%s', downtime_id), callback);
};
downtime_api.prototype.get_all_downtimes = function(current_only, callback){
/*
* downtime_api.get_all_downtimes(downtime_id, [current_only], [callback])
*
* method to get all downtimes
*
* `downtime_id` the id of the downtime
* `current_only` whether or not to get the current downtime only
* `callback` is an optional function to call with the results of the api call
* callback(error, results, status_code)
*/
if(typeof current_only === 'function'){
callback = current_only;
current_only = false;
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"){
var scope = args._[4];
var properties = {};
if(args["start"]){
properties.start = parseInt(args["start"]);
}
if(args["end"]){
properties.end = parseInt(args["end"]);
}
if(args["message"]){
properties.message = args["message"];
}
create(scope, properties, callback);
} else if(subcommand === "update"){
var downtimeId = args._[4];
var properties = {};
if(args["scope"]){
properties.scope = args["scope"];
}
if(args["start"]){
properties.start = parseInt(args["start"]);
}
if(args["end"]){
properties.end = parseInt(args["end"]);
}
if(args["message"]){
properties.message = args["message"];
}
update(downtimeId, properties, callback);
} else {
callback("unknown subcommand or arguments try `dogapi downtime --help` for help", false);
}
}
query = {};
if(current_only){
query.current_only = true;
}
this.request('GET', '/downtime', {query: query}, callback);
};
return module.exports = downtime_api;

@@ -1,216 +0,209 @@

var extend = require('extend');
var util = require('util');
var client = require("../client");
var util = require("util");
var event_api = function(){};
event_api.prototype.stream = function(start, end, filter, callback){
/*
* event_api.stream( start, end, [[filter], callback] )
*
* function used to retrieve all events that have occured between
* `start` and `end` (POSIX timestamps)
*
* optionally filter the query with `filter`:
* {
* 'priority': ("low" or "normal"),
* 'sources': ["sources", "as", "a", "list"],
* 'tags': ["tags", "as", "a", "list"],
* }
*
* optionally provide a `callback` function to get the result
* of this api call:
* callback(error, result, status_code)
*/
if(arguments.length < 2){
throw new Error('parameters `start` and `end` are required');
/*section: event
*comment: |
* create a new event
*params:
* title: the title of the event
* text: the body of the event
* properties: |
* an optional object continaing any of the following additional optional properties
* * date_happened: POSIX timestamp of when it happened
* * priority: "normal" or "low" [defualt: "normal"]
* * host: the host name to associate with the event
* * tags: array of "tag:value"'s to associate with the event
* * alert_type: "error", "warning", "info" or "success" [defualt: "info"]
* * aggregation_key: an arbitrary string used to aggregate like events
* * source_type_name: options: "nagios", "hudson", "jenkins", "user", "my apps", "feed", "chef", "puppet", "git", "bitbucket", "fabric", "capistrano"
* callback: |
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var title = "some new event";
* var text = "IT HAPPENED!";
* dogapi.event.create(title, text, function(err, res){
* console.dir(res);
* });
* title = "another event";
* text = "IT HAPPENED AGAIN!";
* var properties = {
* tags: ["some:tag"],
* alert_type: "error"
* };
* dogapi.event.create(title, text, properties, function(err, res){
* console.dir(res);
* });
* ```
*/
function create(title, text, properties, callback){
if(arguments.length < 4 && typeof arguments[2] === "function"){
callback = properties;
properties = {};
}
query = {
start: parseInt(start),
end: parseInt(end),
};
// this is the only case we have to check
// if we have `event_api(1234, 5678, callback)` then
// we want to push callback back
if(arguments.length == 3 && typeof arguments[2] == 'function'){
callback = arguments[2];
filter = {};
if(typeof properties !== "object"){
properties = {};
}
// validate the filters we were given and append to `query`
// if they exist and meet their requirements
if(filter['priority'] && ['low', 'normal'].indexOf(filter['priority'].toLowerCase()) >= 0){
query['priority'] = filter['priority'].toLowerCase();
}
if(filter['sources'] && typeof filter['sources'] == 'object'){
query['sources'] = filter['sources'].join();
}
if(filter['tags'] && typeof filter['tags'] == 'object'){
query['tags'] = filter['tags'].join();
}
properties.title = title;
properties.text = text;
params = {
query: query,
var params = {
body: properties
};
this.request('GET', '/events', params, callback);
};
client.request("POST", "/events", params, callback);
}
event_api.prototype.polling_stream = function(interval, filter, callback){
/*
* event_api.polling_stream(interval, [[filter], callback] )
*
* function used to continuously call `stream` for new events
*
* `interval` seconds between each call
* `filter` is an object to limit the results by
* `callback` is an optional function called with the results of the api call
* callback(error, result, status_code)
*/
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
filter = {};
}
if(typeof filter != 'object'){
throw new Error('`filter` parameter must be an object');
}
/*section: event
*comment: |
* get event details from the provided event id
*params:
* eventId: |
* the id of the event to fetch
* callback: |
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.event.get(10005, function(err, res){
* console.dir(res);
* });
* ```
*/
function get(eventId, callback){
client.request("GET", util.format("/events/%s", eventId), callback);
}
var last_run = new Date().getTime() / 1000;
var self = this;
setInterval(function(){
var start = last_run;
last_run = new Date().getTime() / 1000;
self.stream(start, last_run, filter, callback);
}, interval * 1000);
};
event_api.prototype.get_event = function(event_id, callback){
/*
* event_api.get_event(event_id, callback)
*
* method used to retrieve a single event's data
*
* `event_id` the id of the event to get the information for
* `callback` an optional function called with the results
* callback(error, result, status_code)
*/
if(!event_id){
throw new Error('`event_id` parameter is required');
/*section: event
*comment: |
* query the event stream
*params:
* start: POSIX timestamp for start of query
* end: POSIX timestamp for end of query
* parameters: |
* optional parameters to use for the query
* * priority: "low" or "normal"
* * sources: comma separated list of sources (e.g. "jenkins,user")
* * tags: comma separated list of tags (e.g. "tag:value1,tag:value2")
* callback: |
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var now = parseInt(new Date().getTime() / 1000);
* var then = now - 3600; // an hour ago
* var parameters = {
* tags: "some:tag",
* sources: "jenkins"
* };
* dogapi.event.query(then, now, parameters, function(err, res){
* console.dir(res);
* });
* ```
*/
function query(start, end, parameters, callback){
if(arguments.length < 4 && typeof argument[2] === "function"){
callback = parameters;
parameters = {};
}
this.request('GET', util.format('/events/%s', event_id), callback);
};
event_api.prototype.add_event = function(event, callback){
/*
* event_api.add_event(event, callback)
*
* method used to add a new event to datadog
*
* `event` is an object containing any of the following:
* title: *required*, string, title for the new event
* text: *required*, string, event message
* date_happened: int, when the event occurred. if unset defaults to the current time. (POSIX timestamp)
* handle: string, user to post the event as. defaults to owner of the application key used to submit.
* priority: string, priority to post the event as. ("normal" or "low", defaults to "normal")
* related_event_id: post event as a child of the given event
* tags: array, tags to post the event with
* host: string, host to post the event with
* device_name: string, device_name to post the event with
* aggregation_ket: string, key to aggregate this event on
*
* `callback` is an optional function for the result
* callback(error, result, status_code)
*/
if(typeof event != 'object'){
throw new Error('`event` parameter must be an object');
if(typeof parameters !== "object"){
parameters = {}
}
parameters.start = start;
parameters.end = end;
if(!event['title']){
throw new Error('`title` property of `event` parameter is required');
}
var params = {
query: parameters
};
if(!event['text']){
throw new Error('`text` property of `event` parameter is required');
}
client.request("GET", "/events", params, callback);
}
if(!event['date_happened']){
event['date_happened'] = Math.round((new Date()).getTime() / 1000);
}
if(event['priority']){
if(['normal', 'low'].indexOf(event['priority'].toLowerCase()) == -1){
event['priority'] = undefined;
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){
var from = parseInt(args._[4]);
var to = parseInt(args._[5]);
var parameters = {};
if(args["sources"]){
parameters.sources = args["sources"];
}
if(args["tags"]){
parameters.tags = args["tags"];
}
query(from, to, parameters, callback);
} else if(subcommand === "create" && args._.length > 5){
var title = args._[4];
var text = args._[5];
var properties = {};
if(args["priority"]){
properties.priority = args["priority"];
}
if(args["host"]){
properties.host = args["host"];
}
if(args["time"]){
properties.date_happened = parseInt(args["time"]);
}
if(args["tags"]){
properties.tags = args["tags"].split(",");
}
if(args["agg-key"]){
properties.aggregation_key = args["agg-key"];
}
if(args["source"]){
properties.source_type_name = args["source"];
}
create(title, text, properties, callback);
} else {
callback("unknown subcommand or arguments try `dogapi event --help` for help", false);
}
}
if(event['tags']){
event['tags'] = event['tags'].join();
}
this.request('POST', '/events', {body: event}, callback);
};
event_api.prototype.add_comment = function(comment, callback){
/*
* event_api.add_comment(comment, [callback])
*
* method used to add a new comment to datadog
*
* `comment` is a object representation of the new comment:
* message: *require*, string, comment text body
* handle: string, optional handle name to use instead of owner of the app key
* related_event_id: string, optional event id to attach this comment to
*
* `callback` is an optional function for the result of the call
* callback(error, result, status_code)
*/
if(typeof comment != 'object'){
throw new Error('`comment` parameter must be an object');
}
if(!comment['message']){
throw new Error('`message` property of `comment` paramter is required');
}
this.request('POST', '/comments', {body: comment}, callback);
};
event_api.prototype.update_comment = function(comment_id, comment, callback){
/*
* event_api.update_comment(comment_id, comment, callback)
*
* method used to update a comment that already exists in datadog
*
* `comment_id` is the id of the comment to update
* `comment` an object representation of the comment changes to make
* message: string, the new message text for the comment
* handle: string, the new owner of the comment
*
* `callback` an optional callback to call with the result
* callback(error, result, status_code)
*/
if(typeof comment != 'object'){
throw new Error('`comment` parameter must be an object');
}
this.request('PUT', util.format('/comments/%s', comment_id), {body: comment}, callback);
};
event_api.prototype.delete_comment = function(comment_id, callback){
/*
* event_api.delete_comment(comment_id, callback)
*
* method used to remove a comment from datadog
*
* `comment_id` the comment id for the comment to remove
* `callback` an optional function to handle the result
* callback(error, result, status_code)
*
*/
this.request('DELETE', util.format('/comments/%s', comment_id), callback);
};
return module.exports = event_api;

@@ -1,59 +0,187 @@

var metric_api = function(){};
var client = require("../client");
metric_api.prototype.add_metric = function(metric, callback){
/*
* metric_api.add_metric(metric, [callback])
*
* method used to add a single metric to datadog
*
* `metric` an object representation of the metric
* metric: *required*, the name of the metric
* points: *required*, an array of elements [ timestamp, value ]
* host: name of the host that produced the event
* tags: array of tags to associate with the event
* type: "guage" or "counter"
*
* `callback` an optional function to call with the results
* callback(metric, [callback])
*/
var metrics = {
'series': [metric]
};
this.add_metrics(metrics, callback);
};
metric_api.prototype.add_metrics = function(metrics, callback){
/*
* metric_api.add_metrics(metrics, [callback])
*
* method used to add multiple metrics to datadog
*
* `metrics` an object representation of the metric:
* series: an array of `metrics` to add
*
* `callback` an optional function to call with the results
* callback(metric, [callback])
*/
if(typeof metrics != 'object'){
throw new Error('`metrics` parameter must be an object');
/*section: metric
*comment: |
* submit a new metric
*params:
* metric: the metric name
* points: |
* single datapoint or array of [timestamp, datapoint], if a single point
* is given "now" is used as the timestamp
* 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: which metric type to use ("gauge" or "counter") [default: gauge]
* callback: |
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.metric.send("my.metric", 1000, function(err, results){
* console.dir(results);
* });
* var now = parseInt(new Date().getTime() / 1000);
* dogapi.metric.send("my.metric", [now, 1000], function(err, results){
* console.dir(results);
* });
* ```
*/
function send(metric, points, extra, callback){
if(arguments.length < 4 && typeof arguments[2] === "function"){
callback = tags;
extra = {};
}
if(!metrics['series'] || typeof metrics['series'] != 'object'){
throw new Error('`metrics["series"]` parameter must be an array');
extra = extra || {};
var series = [
{
metric: metric,
points: points,
host: extra.host,
tags: extra.tags,
metric_type: extra.metric_type
}
];
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 datapoint or an array of [timestamp, datapoint] (same as `dogapi.metric.send`)
* * tags: an array of "tag:value"'s
* * host: the source hostname to use for the metrics
* * metric_type: the type of metric to use ("gauge" or "counter") [default: gauge]
* callback: |
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var now = parseInt(new Date().getTime() / 1000);
* var metrics = [
* {
* metric: "my.metric",
* points: [now, 1000],
* tags: ["tag:value"]
* },
* {
* metric: "another.metric",
* points: 1000
* }
* ];
* dogapi.metric.send_all(metrics, function(err, results){
* console.dir(results);
* });
* ```
*/
function send_all(metrics, callback){
var now = parseInt(new Date().getTime() / 1000);
for(var i = 0; i < metrics.length; ++i){
if(!Array.isArray(metrics[i].points)){
metrics[i].points = [now, metrics[i].points];
}
}
var params = {
body: metrics
};
client.request("POST", "/series", params, callback);
}
for(var i in metrics['series']){
var metric = metrics['series'][i];
if(!metric['metric']){
throw new Error('metric["metric"] is required');
/*section: metric
*comment: |
* make a metric query
*params:
* from: POSIX timestamp for start of query
* to: POSIX timestamp for end of query
* query: the string query to perform (e.g. "system.cpu.idle{*}by{host}")
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var now = parseInt(new Date().getTime() / 1000);
* var then = now - 3600; // one hour ago
* var query = "system.cpu.idle{*}by{host}";
* dogapi.metric.query(then, now, query, function(err, res){
* console.dir(res);
* });
* ```
*/
function query(from, to, query, callback){
var params = {
query: {
from: from,
to: to,
query: query
}
};
client.request("GET", "/query", params, callback);
}
if(!metric['points'] || typeof metric['points'] != 'object'){
throw new Error('metric["points"] must be an array');
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 \"counter\""
]
},
handleCli: function(subcommand, args, callback){
if(subcommand === "send"){
var extra = {};
if(args["--tags"]){
extra.tags = args["--tags"].split(",");
}
if(args["--host"]){
extra.host = args["--host"];
}
if(args["--type"]){
extra.metric_type = args["--type"];
}
send(args["<metric>"], args["<point>"], extra, callback);
} else if(subcommand === "query" && args._.length > 6){
var from = parseInt(args._[4]);
var to = parseInt(args._[5]);
var q = args._[6];
query(from, to, q, callback);
} else {
callback("unknown subcommand or arguments try `dogapi metric --help` for help", false);
}
}
this.request('POST', '/series', {body: metrics}, callback);
};
return module.exports = metric_api;

@@ -0,22 +1,33 @@

var client = require("../client");
var util = require('util');
var tag_api = function(){};
tag_api.prototype.all_tags = function(source, callback){
/*
* tag_api.all_tags([[source], callback])
*
* method to get all the tags in datadog
*
* `source` a source to limit to
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(arguments.length < 2 && typeof arguments[0] == 'function'){
callback = arguments[0];
/*section: tag
*comment: |
* get all host tags
*params:
* source: |
* optional, only show tags for a particular source [default: null]
* callback: |
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.tag.getAll(function(err, results){
* console.dir(results);
* });
* ```
*/
function getAll(source, callback){
if(arguments.length < 2 && typeof arguments[0] === "function"){
callback = source;
source = undefined;
}
params = {
var params = {
query: {

@@ -26,145 +37,229 @@ source: source

};
this.request('GET', '/tags/hosts', params, callback);
};
client.request("GET", "/tags/hosts", params, callback);
}
tag_api.prototype.host_tags = function(host, source, callback){
/*
* tag_api.host_tags(host, [[source], callback])
*
* method to get the tags associated with a given `host`
*
* `host` the hostname or id to get tags for
* `source` a source to limit the results to
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
source = undefined;
/*section: tag
*comment: |
* get the host tags for a provided host name or host id
*params:
* hostname: |
* the hostname or host id
* options:
* |
* optional, an object of options for the query allowing the following
* * source: the source of the tags (e.g. chef, puppet, users, etc) [default: null]
* * by_source: whether or not to group the results by source [default: false]
* callback: |
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.tag.get("host.name", function(err, results){
* console.dir(results);
* });
* ```
*/
function get(hostname, options, callback){
if(arguments.length < 3 && typeof arguments[1] === "function"){
callback = options;
options = {};
}
options = options || {};
params = {
var params = {
query: {
source: source,
}
};
this.request('GET', util.format('/tags/hosts/%s', host), params, callback);
};
tag_api.prototype.host_tags_by_source = function(host, source, callback){
/*
* tag_api.host_tags_by_source(host, [[source], callback])
*
* method to return the tags associated with a host, arranged by source
*
* `host` the hostname of id to get tags for
* `source` a source to limit the lookup for
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
source = undefined;
if(options.source){
params.query.source = options.source;
}
params = {
query: {
source: source,
by_source: true,
}
};
this.request('GET', util.format('/tags/hosts/%s', host), params, callback);
if(options.by_source){
params.query.by_source = options.by_source;
}
client.request("GET", "/tags/hosts/" + hostname, params, callback);
};
tag_api.prototype.add_tags = function(host, tags, source, callback){
/*
* tag_api.add_tags(host, tags, [[source], callback])
*
* add new tags to given `host`
*
* `host` the hostname or id of the machine to add tags for
* `tags` an array of tags to add to the `host`
* `source` the source to associate the tags with, default: user
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(typeof tags != 'object'){
throw new Error('`tags` parameter must be an array');
}
if(arguments.length < 4 && typeof arguments[2] == 'function'){
callback = arguments[2];
/*section: tag
*comment: |
* assign new host tags to the provided host name or host id
*params:
* hostname: |
* the hostname or host id
* tags: |
* list of `<tag>:<value>` tags to assign to the server
* source: |
* optional, the source of the tags (e.g. chef, puppet, etc) [default: users]
* callback: |
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.tag.create("host.name", ["role:webserver"], function(err, results){
* console.dir(results);
* });
* ```
*/
function create(hostname, tags, source, callback){
if(arguments.length < 4 && typeof arguments[2] === "function"){
callback = source;
source = undefined;
}
params = {
query: {
source: source,
},
var params = {
body: {
tags: tags,
}
source: source
},
};
this.request('POST', util.format('/tags/hosts/%s', host), params, callback);
client.request("POST", "/tags/hosts/" + hostname, params, callback);
};
tag_api.prototype.update_tags = function(host, tags, source, callback){
/*
* tag_api.update_tags(host, tags, [[source], callback])
*
* update the tags associated with the given `host`
*
* `host` is the hostname or id of the machine to update tags for
* `tags` an array of tags to associate with the `host`
* `source` the source to associate the tags with, default: user
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(typeof tags != 'object'){
throw new Error('`tags` parameter must be an array');
}
if(arguments.length < 4 && typeof arguments[2] == 'function'){
callback = arguments[2];
/*section: tag
*comment: |
* update the host tags for the provided host name or host id
*params:
* hostname: |
* the hostname or host id
* tags: |
* list of `<tag>:<value>` tags to assign to the server
* source: |
* optional, the source of the tags (e.g. chef, puppet, etc) [default: users]
* callback: |
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.tag.update("host.name", function(err, results){
* console.dir(results);
* });
* ```
*/
function update(hostname, tags, source, callback){
if(arguments.length < 4 && typeof arguments[2] === "function"){
callback = source;
source = undefined;
}
params = {
query: {
source: source,
},
var params = {
body: {
tags: tags,
}
source: source
},
};
this.request('PUT', util.format('/tags/hosts/%s', host), params, callback);
client.request("PUT", "/tags/hosts/" + hostname, params, callback);
};
tag_api.prototype.detach_tags = function(host, source, callback){
/*
* tag_api.detach_tags(host, [[source], callback])
*
* method to remove tags for a given `host`
*
* `host` the hostname or id of the machine to remove the tags for
* `source` the source of the tags
* `callback` is an optional function to call with the results of the api call
* callback(error, result, status_code)
*/
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
/*section: tag
*comment: |
* delete the host tags for the provided host name or host id
*params:
* hostname: |
* the hostname or host id
* source: |
* optional, the source of the tags (e.g. chef, puppet, etc) [default: users]
* callback: |
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.tag.remove("host.name", function(err, results){
* console.dir(results);
* });
* ```
*/
function remove(hostname, source, callback){
if(arguments.length < 3 && typeof arguments[1] === "function"){
callback = source;
source = undefined;
}
params = {
var params = {
query: {
source: source,
},
source: source
}
};
this.request('DELETE', util.format('/tags/hosts/%s', host), params, callback);
client.request("DELETE", "/tags/hosts/" + hostname, params, callback);
};
return module.exports = tag_api;
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){
var source = args["source"];
var host = args._[4];
if(subcommand === "getall"){
getAll(source, callback);
} else if(subcommand === "get"){
var options = {};
if(source){
options.source = source;
}
if(args["by-source"]){
options.by_source = true;
}
get(host, options, callback);
} else if(subcommand === "create"){
var tags = args._[5].split(",");
create(host, tags, source, callback);
} else if(subcommand === "update"){
var tags = args._[5].split(",");
update(host, tags, source, callback);
} else if(subcommand === "delete"){
remove(host, source, callback);
} else {
callback("unknown subcommand or arguments try `dogapi tag --help` for help", false);
}
}
}

@@ -1,36 +0,55 @@

var extend = require('extend');
require("./api")(module.exports);
var http_client = require('./http_client.js');
var constants = require('./constants.js');
var alert_api = require('./api/alert.js');
var dash_api = require('./api/dash.js');
var screen_api = require('./api/screen.js');
var event_api = require('./api/event.js');
var tag_api = require('./api/tag.js');
var metric_api = require('./api/metric.js');
var search_api = require('./api/search.js');
var service_check_api = require('./api/service_check.js');
var snapshot_api = require('./api/snapshot.js');
var downtime_api = require('./api/downtime.js');
/*section: dogapi
*comment: configure the dogapi client with your app/api keys
*params:
* options:
* |
* An object which allows you to override the default set parameters for interacting
* with the datadog api. The available options are.
* * api_key: your api key
* * app_key: your app key
* * api_version: the version of the api [default: `v1`]
* * api_host: the host to call [default: `api.datadoghq.com`]
*example:
* |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* api_key: "<API_KEY_HERE>",
* app_key: "<APP_KEY_HERE>"
* };
* dogapi.initialize(options);
* dogapi.event.create(...);
* ```
*/
function initialize(options){
options = options || {};
for(var key in options){
if(module.exports.client.hasOwnProperty(key)){
module.exports.client[key] = options[key];
}
}
};
var dogapi = function(options){
http_client.call(this, options);
/*section: dogapi
*comment: get the current POSIX timestamp
*example: |
* ```javascript
* var dogapi = require("dogapi");
* dogapi.now();
* // this is the same as
* parseInt(new Date().getTime() / 1000);
* ```
*/
function now(){
return parseInt(new Date().getTime() / 1000);
};
extend(dogapi.prototype,
http_client.prototype,
alert_api.prototype,
dash_api.prototype,
screen_api.prototype,
event_api.prototype,
tag_api.prototype,
metric_api.prototype,
search_api.prototype,
service_check_api.prototype,
snapshot_api.prototype,
downtime_api.prototype);
dogapi.constants = constants;
return module.exports = dogapi;
module.exports.client = require("./client"),
module.exports.initialize = initialize;
module.exports.now = now;
module.exports.OK = 0;
module.exports.WARNING = 1;
module.exports.CRITICAL = 2;
module.exports.UNKNOWN = 3;
{
"name": "dogapi",
"version": "0.2.3",
"version": "1.0.0",
"description": "Datadog API Node.JS Client",
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"docs": "node ./docs/create.js > index.html"
},
"bin": {
"dogapi": "bin/dogapi"
},
"repository": {

@@ -22,3 +26,3 @@ "type": "git",

"author": "Brett Langdon <brett@blangdon.com> (http://brett.is)",
"contributors":[
"contributors": [
"colinjonesx (http://www.thetestpeople.com)",

@@ -31,4 +35,12 @@ "dalehamel (http://blog.srvthe.net)"

"dependencies": {
"extend": "^2.0.0"
"extend": "^2.0.0",
"minimist": "^1.1.1",
"rc": "^1.0.0"
},
"devDependencies": {
"docast": "^0.1.1",
"glob": "^5.0.3",
"js-yaml": "^3.2.7",
"marked": "^0.3.3"
}
}
node-dogapi
===========
Datadog API Node.JS Client modeled after `Datadog/dogapi` python client.
Datadog API Node.JS Client.
Official API Documentation: http://docs.datadoghq.com/api/
Official Datadog API Documentation: http://docs.datadoghq.com/api/
dogapi API Docs: http://brettlangdon.github.io/node-dogapi/
*note* `dogapi` has been updated to `v1.0.0` the api has changed quiet a
bit please be sure to review the new api before upgrading.
## Installation

@@ -28,143 +33,43 @@

The keys can be provided either as constructor parameters when creating an instance of `dogapi`
as `api_key` and `app_key` or as the environment variables `DD_API_KEY` and `DD_APP_KEY`.
**Constructor parameters:**
```javascript
var dogapi = require('dogapi');
var dogapi = require("dogapi");
var options = {
api_key: 'YOUR_KEY_HERE',
app_key: 'YOUR_KEY_HERE',
api_key: "YOUR_KEY_HERE",
app_key: "YOUR_KEY_HERE",
};
var app = new dogapi(options);
dogapi.initialize(options);
```
**Environment Variables:**
```bash
DD_API_KEY=YOUR_KEY_HERE DD_APP_KEY=YOUR_KEY_HERE node app.js
```
## CLI Usage
## API
`dogapi` now ships with a command line interface `dogapi`. To use it you
will need a `.dogapirc` file which meets the standards of
https://github.com/dominictarr/rc
`dogapi` implements all available functions in the official datadog api, http://docs.datadoghq.com/api/.
The config file must contain both `api_key` and `app_key` keys (you can find
your datadog api and app keys here
https://app.datadoghq.com/account/settings#api)
* `dogapi.constants.STATUSES`
* `OK`, `WARNING`, `CRITICAL`, `UNKNOWN`
* `dogapi.stream(start, end, [[filter], callback])`
* function used to retrieve all events that have occured between
* `dogapi.polling_stream(interval, [[filter], callback])`
* function used to continuously call `stream` for new events
* `dogapi.get_event(event_id, callback)`
* method used to retrieve a single event's data
* `dogapi.add_event(event, callback)`
* method used to add a new event to datadog
* `dogapi.add_comment(comment, [callback])`
* method used to add a new comment to datadog
* `dogapi.update_comment(comment_id, comment, callback)`
* method used to update a comment that already exists in datadog
* `dogapi.delete_comment(comment_id, callback)`
* method used to remove a comment from datadog
* `dogapi.add_alert(alert, [callback])`
* add a new alert to datadog
* `dogapi.update_alert(alert_id, alert, [callback])`
* update an existing alert
* `dogapi.get_alert(alert_id, [callback])`
* get the details of an alert from the given id
* `dogapi.delete_alert(alert_id, [callback])`
* delete the given alert from datadog
* `dogapi.get_all_alerts([callback])`
* get the details of all alerts in datadog
* `dogapi.mute_alerts([callback])`
* mute all alerts
* `dogapi.unmute_alerts([callback])`
* unmute all alerts
* `dogapi.get_dashboard(dash_id, [callback])`
* method to get a single dashboard information
* `dogapi.get_all_dashboards([callback])`
* method to retrieve all dashboards in datadog
* `dogapi.create_dashboard(dashboard, [callback])`
* method used to create a new dashboard in datadog
* `dogapi.update_dashboard(dash_id, dashboard, [callback])`
* method used to update the dashboard with the provided `dash_id`
* `dogapi.delete_dashboard(dash_id, [callback])`
* method to remove a dashboard from datadog
* `dogapi.get_screenboard(screen_id, [callback])`
* method to get a single screenboard information
* `dogapi.get_all_screenboards([callback])`
* method to retrieve all screenboards in datadog
* `dogapi.create_screenboard(screenboard, [callback])`
* method used to create a new screenboard in datadog
* `dogapi.update_screenboard(screen_id, screenboard, [callback])`
* method used to update the screenboard with the provided `screen_id`
* `dogapi.delete_screenboard(screen_id, [callback])`
* method to remove a screenboard from datadog
* `dogapi.search(query, [callback])`
* method used to query the api for `metrics` or `hosts`
* `dogapi.add_metric(metric, [callback])`
* method used to add a single metric to datadog
* `dogapi.add_metrics(metrics, [callback])`
* method used to add multiple metrics to datadog
* `dogapi.all_tags([[source], callback])`
* method to get all the tags in datadog
* `dogapi.host_tags(host, [[source], callback])`
* method to get the tags associated with a given `host`
* `dogapi.host_tags_by_source(host, [[source], callback])`
* method to return the tags associated with a host, arranged by source
* `dogapi.add_tags(host, tags, [[source], callback])`
* add new tags to given `host`
* `dogapi.update_tags(host, tags, [[source], callback])`
* update the tags associated with the given `host`
* `dogapi.detach_tags(host, [[source], callback])`
* method to remove tags for a given `host`
* `dogapi.add_snapshot(snapshot, [callback])`
* method used to take a snapshot of a datadog graph
* `dogapi.add_snapshot_from_def(snapshot, [callback])`
* method used to take a snapshot of a datadog graph
* `dogapi.snapshot_status(snapshot_url, [callback])`
* method used to check the status of a datadog snapshot
* `dogapi.service_check(status, check, host, [[extra], [callback]])`
* method used to post a new service check (see `dogapi.constants.STATUSES`)
* `dogapi.schedule_downtime(scope, [options], [callback])`
* method to schedule a new downtime
* `dogapi.update_downtime(downtime_id, [options], [callback])`
* method to update an existing downtime
* `dogapi.cancel_downtime(downtime_id, [callback])`
* method to cancel an existing downtime
* `dogapi.get_downtime(downtime_id, [callback])`
* method to get an existing downtime
* `dogapi.get_all_downtimes([current_only], [callback])`
* method to get all downtimes
Example:
## Sample Usage:
```json
{
"api_key": "<API_KEY>",
"app_key": "<APP_KEY>"
}
```
**Example:** get all events since this time yesterday:
```javascript
var dogapi = require('dogapi');
### Usage
var options = {
api_key: 'YOUR_KEY_HERE',
app_key: 'YOUR KEY_HERE',
};
Please run `dogapi --help` to see current usage documentation for the tool.
var api = new dogapi(options);
Every api method available in `dogapi` is exposed via the cli tool.
var end = parseInt(new Date().getTime() / 1000);
var start = end - 86400;
## TODO
api.stream(start, end, function(error, result, status_code){
if(error){
console.log('Error: ', error);
console.log('Status Code: ', status_code);
return;
}
- [ ] Add tests
- [ ] Add parameter validation (especially for dashboards)
result['events'].forEach(function(event){
console.log(event['id'] + ': ' + event['title']);
});
});
```
## License

@@ -171,0 +76,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc