From 7b55a272243b3c23b0792d3111ffc8f6d3a70f63 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Wed, 18 Mar 2015 08:51:44 -0400
Subject: [PATCH 01/65] replace old http client library with a new one
---
lib/client.js | 122 ++++++++++++++++++++++++++++++++++++++
lib/http_client.js | 145 ---------------------------------------------
2 files changed, 122 insertions(+), 145 deletions(-)
create mode 100644 lib/client.js
delete mode 100644 lib/http_client.js
diff --git a/lib/client.js b/lib/client.js
new file mode 100644
index 0000000..3e91e40
--- /dev/null
+++ b/lib/client.js
@@ -0,0 +1,122 @@
+var extend = require("extend");
+var https = require("https");
+var url = require("url");
+var util = require("util");
+
+
+/*section: client
+ *comment: |
+ * the constructor for _client_ object
+ *params:
+ *example: |
+ * See [client.request](#client-request)
+ */
+var client = function(){
+ this.api_key = null;
+ this.app_key = null;
+ this.api_version = "v1";
+ this.api_host = "app.datadoghq.com";
+};
+
+/*section: client
+ *comment: |
+ * used to make a raw request to the datadog api
+ *params:
+ * method: |
+ * http method GET, POST, PUT, DELETE
+ * path: |
+ * the api url path e.g. /tags/hosts
+ * params: |
+ * an object which allows the keys `query` or `body`
+ * callback: |
+ * function to call on success/failure callback(err, result)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * dogapi.client.request("GET", "/url/path", {}, function(err, results){
+ * console.dir(results);
+ * });
+ * ```
+ */
+client.prototype.request = function(method, path, params, callback){
+ if(arguments.length === 3 && typeof arguments[2] === "function"){
+ callback = arguments[2];
+ params = {};
+ }
+
+ params = params || {};
+ var body = (typeof params["body"] === "object")? JSON.stringify(params["body"]) : params["body"];
+ var query = {
+ "api_key": this.api_key,
+ "application_key": this.app_key,
+ };
+
+ if(typeof params["query"] === "object"){
+ extend(query, params["query"]);
+ }
+
+ path = url.format({
+ "pathname": util.format("/api/%s%s", this.api_version, path),
+ "query": query,
+ });
+
+ var http_options = {
+ hostname: this.api_host,
+ port: 443,
+ method: method.toUpperCase(),
+ path: path,
+ };
+
+ if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){
+ http_options["headers"] = {
+ "Content-Type": "application/json",
+ "Content-Length": body.length,
+ };
+ }
+
+ var req = https.request(http_options, function(res){
+ res.on("error", function(err){
+ if(typeof callback == "function"){
+ callback(err, null, res.statusCode);
+ }
+ });
+
+ var data = "";
+ res.on("data", function(chunk){
+ data += chunk;
+ });
+
+ res.on("end", function(){
+ var error = null;
+ try{ data = JSON.parse(data); }catch(e){}
+ if(data["errors"]){
+ error = data["errors"];
+ data = null;
+ }
+
+ if(typeof callback === "function"){
+ callback(error, data, res.statusCode);
+ }
+ });
+ });
+
+ // This should only occur for errors such as a socket hang up prior to any
+ // data being received, or SSL-related issues.
+ req.on("error", function(err){
+ if(typeof callback === "function"){
+ callback(err, null, 0);
+ }
+ });
+
+ if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){
+ req.write(body);
+ }
+ req.end()
+};
+
+module.exports = new client();
diff --git a/lib/http_client.js b/lib/http_client.js
deleted file mode 100644
index bfcb8fc..0000000
--- a/lib/http_client.js
+++ /dev/null
@@ -1,145 +0,0 @@
-var extend = require('extend');
-var https = require('https');
-var url = require('url');
-var util = require('util');
-
-
-var client = function(options){
- /*
- * new http_client([options])
- *
- * http client used to make requests to datadog api service
- *
- * `options` is an optional object of parameters to set:
- * {
- * 'api_key': 'datadog api key',
- * 'app_key': 'datadog app key',
- * 'api_version': 'default is v1',
- * 'api_host': 'default is app.datadoghq.com',
- * }
- *
- * this client also allows you to provide these options as
- * environment variables instead:
- *
- * api_key: DD_API_KEY
- * app_key: DD_APP_KEY
- * api_version: DD_API_VERSION
- * api_host: DD_API_HOST
- */
- options = (options)? options : {};
-
- this.api_key = (options['api_key'])? options['api_key'] : process.env['DD_API_KEY'];
- if(!this.api_key){
- throw new Error('`api_key` is not present, either provide `api_key` in `options` or use environment variable `DD_API_KEY`');
- }
-
- this.app_key = (options['app_key'])? options['app_key'] : process.env['DD_APP_KEY'];
- if(!this.api_key){
- throw new Error('`app_key` is not present, either provide `app_key` in `options` or use environment variable `DD_APP_KEY`');
- }
-
- this.api_version = (options['api_version'])? options['api_version'] : process.env['DD_API_VERSION'];
- if(!this.api_version){
- this.api_version = 'v1';
- }
-
- this.api_host = (options['api_host'])? options['api_host'] : process.env['DD_API_HOST'];
- if(!this.api_host){
- this.api_host = 'app.datadoghq.com';
- }
-
-
-};
-
-client.prototype.request = function(method, path, params, callback){
- /*
- * http_client.request(method, path, [[params], callback])
- *
- * method used to send an http request to the datadog api service
- *
- * `method` is the http method to use ('POST', 'GET', 'DELETE', etc)
- * `path` the api url to call, e.g '/events', '/series', '/dash', etc
- * `params` an optional object of additional options:
- * {
- * 'query': { 'key': 'value' },
- * 'body': { 'json/object': 'body' } or 'string body',
- * }
- * `callback` an optional function to obtain the results of the api call
- * callback(error, result)
- */
- if(arguments.length == 3 && typeof arguments[2] == 'function'){
- callback = arguments[2];
- params = {};
- }
-
- params = params || {};
- var body = (typeof params['body'] == 'object')? JSON.stringify(params['body']) : params['body'];
- var query = {
- 'api_key': this.api_key,
- 'application_key': this.app_key,
- };
-
- if(typeof params['query'] == 'object'){
- extend(query, params['query']);
- }
-
- path = url.format({
- 'pathname': util.format('/api/%s%s', this.api_version, path),
- 'query': query,
- });
-
- var http_options = {
- hostname: this.api_host,
- port: 443,
- method: method.toUpperCase(),
- path: path,
- };
-
- if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){
- http_options['headers'] = {
- 'Content-Type': 'application/json',
- 'Content-Length': body.length,
- };
- }
-
- var req = https.request(http_options, function(res){
- res.on('error', function(err){
- if(typeof callback == 'function'){
- callback(err, null, res.statusCode);
- }
- });
-
- var data = '';
- res.on('data', function(chunk){
- data += chunk;
- });
-
- res.on('end', function(){
- var error = null;
- try{ data = JSON.parse(data); }catch(e){}
- if(data['errors']){
- error = data['errors'];
- data = null;
- }
-
- if(typeof callback == 'function'){
- callback(error, data, res.statusCode);
- }
- });
- });
-
- // This should only occur for errors such as a socket hang up prior to any
- // data being received, or SSL-related issues.
- req.on('error', function(err) {
- if(typeof callback == 'function'){
- callback(err, null, 0);
- }
- });
-
- if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){
- req.write(body);
- }
- req.end()
-};
-
-return module.exports = client;
From ad5841aa5300cd211a366eeb300a5f20fd7952a9 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Wed, 18 Mar 2015 08:52:47 -0400
Subject: [PATCH 02/65] setup new dogapi base and port over the tag api
---
lib/api/index.js | 9 ++
lib/api/tag.js | 294 +++++++++++++++++++++++++++--------------------
lib/index.js | 65 ++++++-----
3 files changed, 210 insertions(+), 158 deletions(-)
create mode 100644 lib/api/index.js
diff --git a/lib/api/index.js b/lib/api/index.js
new file mode 100644
index 0000000..04d809b
--- /dev/null
+++ b/lib/api/index.js
@@ -0,0 +1,9 @@
+var api = {
+ tag: require("./tag")
+};
+
+module.exports = function(obj){
+ for(key in api){
+ obj[key] = api[key];
+ }
+};
diff --git a/lib/api/tag.js b/lib/api/tag.js
index f155430..e376b8c 100644
--- a/lib/api/tag.js
+++ b/lib/api/tag.js
@@ -1,169 +1,213 @@
+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.get_all(function(err, results){
+ * console.dir(results);
+ * });
+ * ```
+ */
+function get_all(source, callback){
+ if(arguments.length < 2 && typeof arguments[0] === "function"){
+ callback = source;
source = undefined;
}
- params = {
+ var params = {
query: {
source: source
}
};
- this.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;
+ client.request("GET", "/tags/hosts", params, callback);
+}
+
+/*section: tag
+ *comment: |
+ * get the host tags for a provided host name or host id
+ *params:
+ * hostname: |
+ * the hostname or host id
+ * options:
+ * |
+ * optional, an object of options for the query allowing the following
+ * * source: the source of the tags (e.g. chef, puppet, users, etc) [default: null]
+ * * by_source: whether or not to group the results by source [default: false]
+ * callback: |
+ * function callback(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * dogapi.tag.get("host.name", function(err, results){
+ * console.dir(results);
+ * });
+ * ```
+ */
+function get(hostname, options, callback){
+ if(arguments.length < 3 && typeof arguments[1] === "function"){
+ callback = options;
+ options = {};
}
+ 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 `:` 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 `:` 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.delete("host.name", function(err, results){
+ * console.dir(results);
+ * });
+ * ```
+ */
+function delete_tags(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,
+ get_all: get_all,
+ get: get,
+ create: create,
+ update: update,
+ "delete": delete_tags,
+}
diff --git a/lib/index.js b/lib/index.js
index 7cfc672..2f2234f 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,36 +1,35 @@
-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');
-
-
-var dogapi = function(options){
- http_client.call(this, options);
+/*section: dogapi
+ *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: "",
+ * app_key: ""
+ * };
+ * 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];
+ }
+ }
};
-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;
From 5b868c60dbbb024f97f6cf0086cb50520a0ca33c Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Wed, 18 Mar 2015 08:53:22 -0400
Subject: [PATCH 03/65] add documentation generation
---
docs/create.js | 109 ++++++++++++++++++++++++++++++++++++++++++++++++
docs/styles.css | 49 ++++++++++++++++++++++
package.json | 8 +++-
3 files changed, 165 insertions(+), 1 deletion(-)
create mode 100644 docs/create.js
create mode 100644 docs/styles.css
diff --git a/docs/create.js b/docs/create.js
new file mode 100644
index 0000000..2e0df72
--- /dev/null
+++ b/docs/create.js
@@ -0,0 +1,109 @@
+var path = require("path");
+
+var docast = require("docast");
+var glob = require("glob");
+var marked = require("marked");
+var yaml = require("js-yaml");
+
+marked.setOptions({
+ gfm: true,
+ sanitize: true,
+ pedantic: false
+});
+
+var above = path.resolve(__dirname, "../lib/");
+var match = above + "/**/*.js";
+
+var docs = {};
+glob(match, function(er, files){
+ files.forEach(function(file){
+ var comments = docast.parse(file);
+ for(var i = 0; i < comments.length; ++i){
+ var comment = comments[i];
+ try{
+ comment.doc = yaml.safeLoad(comment.doc);
+ if(!comment.doc.hasOwnProperty("section")){
+ continue;
+ }
+ if(!docs[comment.doc.section]){
+ docs[comment.doc.section] = {};
+ }
+
+ for(var key in comment.doc.params){
+ if(comment.doc.params.hasOwnProperty(key)){
+ comment.doc.params[key] = comment.doc.params[key].replace("optional", "_optional_");
+ comment.doc.params[key] = marked(comment.doc.params[key]);
+ }
+ }
+ if(comment.doc.hasOwnProperty("example")){
+ comment.doc.example = marked(comment.doc.example);
+ } else {
+ comment.doc.example = "";
+ }
+
+ if(comment.doc.hasOwnProperty("comment")){
+ comment.doc.comment = marked(comment.doc.comment);
+ } else {
+ comment.doc.comment = "";
+ }
+
+ docs[comment.doc.section][comment.name] = comment.doc;
+ } catch(e){}
+ }
+ });
+
+ var output = "\n\n\n\n\n\n\n\n\n";
+ output += "\n";
+ for(var section in docs){
+ if(!docs.hasOwnProperty(section)){
+ continue;
+ }
+ output += "- " + section + "
\n";
+ }
+ output += "
\n";
+
+ for(var section in docs){
+ if(!docs.hasOwnProperty(section)){
+ continue;
+ }
+ methods = docs[section];
+
+ output += "\n";
+ output += "" + section + "
\n";
+ for(var name in methods){
+ if(!methods.hasOwnProperty(name)){
+ continue;
+ }
+ doc = methods[name];
+
+ var className = section + "-" + name;
+ output += "\n";
+
+ output += "
" + name + "
\n";
+ output += "
\n";
+ output += "
\n";
+ output += doc.comment;
+ output += "
Parameters:
\n";
+ for(var param in doc.params){
+ if(!doc.params.hasOwnProperty(param)){
+ continue;
+ }
+ var comment = doc.params[param];
+ output += "" + param + "
\n";
+ output += comment;
+ }
+ output += "\n";
+
+ output += "
\n";
+ output += doc.example;
+ output += "
\n";
+
+ output += "
\n";
+ output += "
\n";
+
+ }
+ output += "\n";
+ }
+ output += "";
+ console.log(output);
+});
diff --git a/docs/styles.css b/docs/styles.css
new file mode 100644
index 0000000..e758e2c
--- /dev/null
+++ b/docs/styles.css
@@ -0,0 +1,49 @@
+
+h2 {
+ width: 100%;
+ font-size: 2em;
+ background-color: #eee;
+}
+
+h3 {
+ width: 100%;
+ font-size: 1.5em;
+}
+
+.function {
+ border-top: solid 1px #eee;
+}
+
+.function .container {
+ display: flex;
+}
+
+.function .doc {
+ width: 50%;
+}
+
+.function .doc p {
+ text-indent: 1.5em;
+}
+
+.function .example {
+ width: 50%;
+ flex-grow: 2;
+ flex-basis: auto;
+ overflow-x: scroll;
+}
+
+.function .example code {
+ border-radius: 5px;
+ border: solid 1px #000;
+}
+
+@media all and (max-width: 800px) {
+ .function .container {
+ flex-direction: column;
+ }
+
+ .function .doc, .function .example {
+ width: 100%;
+ }
+}
diff --git a/package.json b/package.json
index d94f0d8..1cfe83a 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
"dog api"
],
"author": "Brett Langdon (http://brett.is)",
- "contributors":[
+ "contributors": [
"colinjonesx (http://www.thetestpeople.com)",
"dalehamel (http://blog.srvthe.net)"
],
@@ -28,5 +28,11 @@
"gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc",
"dependencies": {
"extend": "^2.0.0"
+ },
+ "devDependencies": {
+ "docast": "^0.1.1",
+ "glob": "^5.0.3",
+ "js-yaml": "^3.2.7",
+ "marked": "^0.3.3"
}
}
From 192ba230beaa35f4a1812874a94a53dddc9757f5 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 08:59:26 -0400
Subject: [PATCH 04/65] fix up documentation template some more
---
docs/create.js | 71 +++++++++++++++++++++++++++++++++++--------------
docs/styles.css | 49 ----------------------------------
2 files changed, 51 insertions(+), 69 deletions(-)
delete mode 100644 docs/styles.css
diff --git a/docs/create.js b/docs/create.js
index 2e0df72..43eb893 100644
--- a/docs/create.js
+++ b/docs/create.js
@@ -52,15 +52,26 @@ glob(match, function(er, files){
}
});
- var output = "\n\n\n\n\n\n\n\n\n";
- output += "\n";
+ var output = "\n\n\n";
+ output += "\n";
+ output += "\n\n";
+ output += "\n";
+ output += "\n";
+ output += "\n\n";
+ output += "Jump To Top\n";
+ output += "\n";
+ output += "
\n";
+ output += "
\n";
+ output += "
Node Dogapi
\n";
+ output += "
\n";
for(var section in docs){
if(!docs.hasOwnProperty(section)){
continue;
}
- output += "- " + section + "
\n";
+ output += "- " + section + "\n";
+ output += "
\n";
}
- output += "
\n";
+ output += "\n
\n
\n";
for(var section in docs){
if(!docs.hasOwnProperty(section)){
@@ -68,8 +79,19 @@ glob(match, function(er, files){
}
methods = docs[section];
- output += "
\n";
- output += "" + section + "
\n";
+ output += "\n";
+ output += "\n
" + section + "
\n";
+
+ output += "\n";
+ for(var name in methods){
+ if(!methods.hasOwnProperty(name)){
+ continue;
+ }
+ output += "- " + name + "
\n";
+ }
+
+ output += "
\n";
+
for(var name in methods){
if(!methods.hasOwnProperty(name)){
continue;
@@ -77,33 +99,42 @@ glob(match, function(er, files){
doc = methods[name];
var className = section + "-" + name;
- output += "\n";
+ output += "
\n";
+
+ var definition = name + "(";
+ if(doc.params && typeof doc.params === "object"){
+ definition += Object.keys(doc.params).join(", ");
+ }
+ definition += ")";
- output += "
" + name + "
\n";
- output += "
\n";
- output += "
\n";
+ output += "
" + definition + "
\n";
+ output += "
\n";
output += doc.comment;
- output += "
Parameters:
\n";
- for(var param in doc.params){
- if(!doc.params.hasOwnProperty(param)){
- continue;
+ if(doc.params){
+ output += "
Parameters:
\n";
+ output += "
\n";
+ for(var param in doc.params){
+ if(!doc.params.hasOwnProperty(param)){
+ continue;
+ }
+ var comment = doc.params[param];
+ output += "- " + param + "
\n";
+ output += "- " + comment + "
\n";
}
- var comment = doc.params[param];
- output += "" + param + "
\n";
- output += comment;
+ output += "
\n";
}
output += "
\n";
- output += "
\n";
+ output += "
\n";
output += doc.example;
output += "
\n";
output += "
\n";
- output += "
\n";
-
}
output += "\n";
}
+ output += "
\n";
+ output += "

";
output += "";
console.log(output);
});
diff --git a/docs/styles.css b/docs/styles.css
deleted file mode 100644
index e758e2c..0000000
--- a/docs/styles.css
+++ /dev/null
@@ -1,49 +0,0 @@
-
-h2 {
- width: 100%;
- font-size: 2em;
- background-color: #eee;
-}
-
-h3 {
- width: 100%;
- font-size: 1.5em;
-}
-
-.function {
- border-top: solid 1px #eee;
-}
-
-.function .container {
- display: flex;
-}
-
-.function .doc {
- width: 50%;
-}
-
-.function .doc p {
- text-indent: 1.5em;
-}
-
-.function .example {
- width: 50%;
- flex-grow: 2;
- flex-basis: auto;
- overflow-x: scroll;
-}
-
-.function .example code {
- border-radius: 5px;
- border: solid 1px #000;
-}
-
-@media all and (max-width: 800px) {
- .function .container {
- flex-direction: column;
- }
-
- .function .doc, .function .example {
- width: 100%;
- }
-}
From df67f3d90b1aeff23ec6e8e7d2e6d9945a0fdab3 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 08:59:33 -0400
Subject: [PATCH 05/65] add script to build docs
---
package.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 1cfe83a..fc139a3 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,8 @@
"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"
},
"repository": {
"type": "git",
From 306c3699263d063809fb7755633ce7b7a50aa31c Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:05:41 -0400
Subject: [PATCH 06/65] re-write metric api
---
lib/api/metric.js | 182 +++++++++++++++++++++++++++++++++-------------
1 file changed, 133 insertions(+), 49 deletions(-)
diff --git a/lib/api/metric.js b/lib/api/metric.js
index 6cdba32..97f530f 100644
--- a/lib/api/metric.js
+++ b/lib/api/metric.js
@@ -1,59 +1,143 @@
-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');
- }
-
- for(var i in metrics['series']){
- var metric = metrics['series'][i];
- if(!metric['metric']){
- throw new Error('metric["metric"] is required');
+ extra = extra || {};
+ var series = [
+ {
+ metric: metric,
+ points: points,
+ host: extra.host,
+ tags: extra.tags,
+ metric_type: extra.metric_type
}
+ ];
+
+ send_all(series, callback);
+}
- if(!metric['points'] || typeof metric['points'] != 'object'){
- throw new Error('metric["points"] must be an array');
+/*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);
+}
- this.request('POST', '/series', {body: metrics}, callback);
-};
+/*section: metric
+ *comment: |
+ * make a metric query
+ *params:
+ * from: POSIX timestamp for start of query
+ * to: POSIX timestamp for end of query
+ * query: the string query to perform (e.g. "system.cpu.idle{*}by{host}")
+ * callback: function(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * var now = parseInt(new Date().getTime() / 1000);
+ * var then = now - 3600; // one hour ago
+ * var query = "system.cpu.idle{*}by{host}";
+ * dogapi.metric.query(then, now, query, function(err, res){
+ * console.dir(res);
+ * });
+ * ```
+ */
+function query(from, to, query, callback){
+ var params = {
+ from: from,
+ to: to,
+ query: query
+ };
+ client.request("GET", "/query", params, callback);
+}
-return module.exports = metric_api;
+module.exports = {
+ send: send,
+ send_all: send_all
+};
From d9ad10a9a8f52873763272f458acdf22206a55a4 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:10:48 -0400
Subject: [PATCH 07/65] re-write the event api
---
lib/api/event.js | 349 +++++++++++++++++++----------------------------
1 file changed, 138 insertions(+), 211 deletions(-)
diff --git a/lib/api/event.js b/lib/api/event.js
index d2a9cb5..8801cf9 100644
--- a/lib/api/event.js
+++ b/lib/api/event.js
@@ -1,216 +1,143 @@
-var extend = require('extend');
-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');
- }
- query = {
- start: parseInt(start),
- end: parseInt(end),
+var client = require("../client");
+var util = require("util");
+
+/*section: event
+ *comment: |
+ * create a new event
+ *params:
+ * title: the title of the event
+ * text: the body of the event
+ * properties: |
+ * an optional object continaing any of the following additional optional properties
+ * * date_happened: POSIX timestamp of when it happened
+ * * priority: "normal" or "low" [defualt: "normal"]
+ * * host: the host name to associate with the event
+ * * tags: array of "tag:value"'s to associate with the event
+ * * alert_type: "error", "warning", "info" or "success" [defualt: "info"]
+ * * aggregation_key: an arbitrary string used to aggregate like events
+ * * source_type_name: options: "nagios", "hudson", "jenkins", "user", "my apps", "feed", "chef", "puppet", "git", "bitbucket", "fabric", "capistrano"
+ * callback: |
+ * function(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * var title = "some new event";
+ * var text = "IT HAPPENED!";
+ * dogapi.event.create(title, text, function(err, res){
+ * console.dir(res);
+ * });
+ * title = "another event";
+ * text = "IT HAPPENED AGAIN!";
+ * var properties = {
+ * tags: ["some:tag"],
+ * alert_type: "error"
+ * };
+ * dogapi.event.create(title, text, properties, function(err, res){
+ * console.dir(res);
+ * });
+ * ```
+ */
+function create(title, text, properties, callback){
+ if(arguments.length < 4 && typeof arguments[2] === "function"){
+ callback = properties;
+ properties = {};
+ }
+ if(typeof properties !== "object"){
+ properties = {};
+ }
+
+ properties.title = tile;
+ properties.text = text;
+
+ var params = {
+ body: properties
};
-
- // 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 = {};
- }
-
- // 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();
- }
-
- params = {
- query: query,
+ client.request("POST", "/events", params, callback);
+}
+
+/*section: event
+ *comment: |
+ * get event details from the provided event id
+ *params:
+ * eventId: |
+ * the id of the event to fetch
+ * callback: |
+ * function(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * dogapi.event.get(10005, function(err, res){
+ * console.dir(res);
+ * });
+ * ```
+ */
+function get(eventId, callback){
+ client.request("GET", util.format("/events/%s", eventId), callback);
+}
+
+/*section: event
+ *comment: |
+ * 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 = {};
+ }
+
+ if(typeof parameters !== "object"){
+ parameters = {}
+ }
+ parameters.start = start;
+ parameters.end = end;
+
+ var params = {
+ query: parameters
};
- this.request('GET', '/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');
- }
-
- 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');
- }
+ client.request("GET", "/events", params, callback);
+}
- this.request('GET', util.format('/events/%s', event_id), callback);
+module.exports = {
+ create: create,
+ get: get,
+ query: query
};
-
-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(!event['title']){
- throw new Error('`title` property of `event` parameter is required');
- }
-
- if(!event['text']){
- throw new Error('`text` property of `event` parameter is required');
- }
-
- 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;
- }
- }
-
- 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;
From ac399d191e96f1d5b52f3a38838f32ea8d333f55 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:11:05 -0400
Subject: [PATCH 08/65] expose the new metric and event apis
---
lib/api/index.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/api/index.js b/lib/api/index.js
index 04d809b..c83395a 100644
--- a/lib/api/index.js
+++ b/lib/api/index.js
@@ -1,5 +1,7 @@
var api = {
- tag: require("./tag")
+ tag: require("./tag"),
+ metric: require("./metric"),
+ event: require("./event")
};
module.exports = function(obj){
From 508b4d0d0fcb0215c451918c8c03f7730ab5c983 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:11:30 -0400
Subject: [PATCH 09/65] build documentation
---
index.html | 553 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 553 insertions(+)
create mode 100644 index.html
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..a7cdbb5
--- /dev/null
+++ b/index.html
@@ -0,0 +1,553 @@
+
+
+
+
+
+
+
+
+
+
+Jump To Top
+
+
+
+
+
event
+
+
+
create(title, text, properties, callback)
+
+
create a new event
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+ });
+
+
+
+
+
get(eventId, callback)
+
+
get event details from the provided event id
+
Parameters:
+
+- eventId
+the id of the event to fetch
+
+- callback
+function(err, res)
+
+
+
+
+
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);
+ });
+
+
+
+
+
query(start, end, parameters, callback)
+
+
query the event stream
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+ });
+
+
+
+
+
+
+
metric
+
+
+
send(metric, points, extra, callback)
+
+
submit a new metric
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+ });
+
+
+
+
+
send_all(metrics, callback)
+
+
send a list of metrics
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+ });
+
+
+
+
+
query(from, to, query, callback)
+
+
make a metric query
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+ });
+
+
+
+
+
+
+
tag
+
+
+
get_all(source, callback)
+
+
get all host tags
+
Parameters:
+
+- source
+optional, only show tags for a particular source [default: null]
+
+- callback
+function callback(err, res)
+
+
+
+
+
var dogapi = require("dogapi");
+var options = {
+ api_key: "api_key",
+ app_key: "app_key"
+};
+dogapi.initialize(options);
+dogapi.tag.get_all(function(err, results){
+ console.dir(results);
+});
+
+
+
+
+
get(hostname, options, callback)
+
+
get the host tags for a provided host name or host id
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+});
+
+
+
+
+
create(hostname, tags, source, callback)
+
+
assign new host tags to the provided host name or host id
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+});
+
+
+
+
+
update(hostname, tags, source, callback)
+
+
update the host tags for the provided host name or host id
+
Parameters:
+
+- 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)
+
+
+
+
+
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);
+});
+
+
+
+
+
+
+
+
client
+
+
+
client()
+
+
the constructor for client object
+
+
+
+
+
request(method, path, params, callback)
+
+
used to make a raw request to the datadog api
+
Parameters:
+
+- method
+http method GET, POST, PUT, DELETE
+
+- path
+the api url path e.g. /tags/hosts
+
+- params
+an object which allows the keys query or body
+
+- callback
+function to call on success/failure callback(err, result)
+
+
+
+
+
var dogapi = require("dogapi");
+var options = {
+ api_key: "api_key",
+ app_key: "app_key"
+};
+dogapi.initialize(options);
+dogapi.client.request("GET", "/url/path", {}, function(err, results){
+ console.dir(results);
+});
+
+
+
+
+
+
+
dogapi
+
+
+
initialize(options)
+
+
Parameters:
+
+- 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]
+
+
+
+
+
+
var dogapi = require("dogapi");
+var options = {
+ api_key: "<API_KEY_HERE>",
+ app_key: "<APP_KEY_HERE>"
+};
+dogapi.initialize(options);
+dogapi.event.create(...);
+
+
+
+
+
+
From 18180281804c09349e36813e8c1b4fc5f860cb05 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:27:30 -0400
Subject: [PATCH 10/65] add serviceCheck api
---
lib/api/index.js | 3 ++-
lib/api/serviceCheck.js | 55 ++++++++++++++++++++++++++++++++++++++++
lib/api/service_check.js | 47 ----------------------------------
lib/index.js | 4 +++
4 files changed, 61 insertions(+), 48 deletions(-)
create mode 100644 lib/api/serviceCheck.js
delete mode 100644 lib/api/service_check.js
diff --git a/lib/api/index.js b/lib/api/index.js
index c83395a..3d0faa8 100644
--- a/lib/api/index.js
+++ b/lib/api/index.js
@@ -1,7 +1,8 @@
var api = {
tag: require("./tag"),
metric: require("./metric"),
- event: require("./event")
+ event: require("./event"),
+ serviceCheck: require("./serviceCheck")
};
module.exports = function(obj){
diff --git a/lib/api/serviceCheck.js b/lib/api/serviceCheck.js
new file mode 100644
index 0000000..5db6ea0
--- /dev/null
+++ b/lib/api/serviceCheck.js
@@ -0,0 +1,55 @@
+var client = require("../client");
+
+/*section: serviceCheck
+ *comment: |
+ * post an update to a service check
+ *params:
+ * check: the check name (e.g. "app.ok")
+ * hostName: the name of the host submitting the check
+ * status: one of `dogapi.OK`, `dogapi.WARNING`, `dogapi.CRITICAL` or `dogapi.UNKNOWN`
+ * parameters: |
+ * optional, an object containing any of the following
+ * * timestamp: POSIX timestamp for when the check happened
+ * * message: string message to accompany the check
+ * * tags: an array of "tag:value"'s associated with the check
+ * callback: function(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * var check = "app.ok";
+ * var hostName = "some.machine";
+ * dogapi.serviceCheck.check(
+ * check, hostName, dogapi.WARNING, function(err, res){
+ * console.dir(res);
+ * });
+ * ```
+ */
+function check(check, hostName, status, parameters, callback){
+ if(arguments.length < 5 && typeof arguments[3] === "function"){
+ callback = parameters;
+ parameters = {};
+ }
+
+ if(typeof parameters !== "object"){
+ parameters = {};
+ }
+
+ parameters.check = check;
+ parameters.host_name = hostName,
+ parameters.status = status;
+
+ var params = {
+ body: parameters
+ };
+ client.request("POST", "/check_run", params, callback);
+};
+
+
+module.exports = {
+ check: check
+};
diff --git a/lib/api/service_check.js b/lib/api/service_check.js
deleted file mode 100644
index c762981..0000000
--- a/lib/api/service_check.js
+++ /dev/null
@@ -1,47 +0,0 @@
-var util = require('util');
-
-var constants = require('../constants');
-
-var service_check_api = function(){};
-
-
-service_check_api.prototype.service_check = function(status, check, host, extra, callback){
- /*
- * service_check_api.service_check(options, callback])
- *
- * used to post a service check
- *
- * `status` the `dogapi.constant.STATUSES` status code for the check
- * `check` the name of the check
- * `host` the host associated with the check
- * `extra` an object of optional arguments `timestamp`, `message` or `tags`
- * `callback` is an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- if(typeof extra === 'function'){
- callback = extra;
- extra = {};
- }
-
- if(constants.ALL_STATUSES.indexOf(status) < 0){
- throw new Error(util.format('Unknown service_check status %s', status));
- }
-
- var body = {
- check: check,
- status: status,
- host_name: host,
- timestamp: parseInt(extra['timestamp'] || (new Date().getTime() / 1000)),
- };
-
- if(extra['message']){
- body['message'] = extra['message'];
- }
- if(extra['tags']){
- body['tags'] = extra['tags'];
- }
-
- this.request('POST', '/check_run', {body: body}, callback);
-};
-
-return module.exports = service_check_api;
diff --git a/lib/index.js b/lib/index.js
index 2f2234f..893bb13 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -33,3 +33,7 @@ function initialize(options){
module.exports.client = require("./client"),
module.exports.initialize = initialize;
+module.exports.OK = 0;
+module.exports.WARNING = 1;
+module.exports.CRITICAL = 2;
+module.exports.UNKNOWN = 3;
From dfdf498da8b64c98cabbc4a6eaeed4014219ec4f Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:28:10 -0400
Subject: [PATCH 11/65] build docs
---
index.html | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/index.html b/index.html
index a7cdbb5..a7040d7 100644
--- a/index.html
+++ b/index.html
@@ -20,6 +20,8 @@ document.addEventListener("DOMContentLoaded", function(){hljs.initHighlightingOn
- metric
+- serviceCheck
+
- tag
- client
@@ -296,6 +298,57 @@ is given "now" is used as the timestamp
+
+
+
serviceCheck
+
+
+
check(check, hostName, status, parameters, callback)
+
+
post an update to a service check
+
Parameters:
+
+- 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)
+
+
+
+
+
var dogapi = require("dogapi");
+ var options = {
+ api_key: "api_key",
+ app_key: "app_key"
+ };
+ dogapi.initialize(options);
+ var check = "app.ok";
+ var hostName = "some.machine";
+ dogapi.serviceCheck.check(
+ check, hostName, dogapi.WARNING, function(err, res){
+ console.dir(res);
+ });
+
+
+
+
tag
From 43834e9fecebfcd214f7b62f8c5caadaf050ea23 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:30:14 -0400
Subject: [PATCH 12/65] Add dogapi.now helper method
---
lib/index.js | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lib/index.js b/lib/index.js
index 893bb13..4d77121 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -31,8 +31,23 @@ function initialize(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);
+};
+
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;
From c27d73b0eef5bfac701520361b2183f372101f6f Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:30:19 -0400
Subject: [PATCH 13/65] build docs
---
index.html | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/index.html b/index.html
index a7040d7..cdab18b 100644
--- a/index.html
+++ b/index.html
@@ -572,6 +572,7 @@ dogapi.client.request("GET", "/url/path", {}, function(err,
dogapi
initialize(options)
@@ -601,6 +602,19 @@ dogapi.event.create(...);
+
+
now()
+
+
get the current POSIX timestamp
+
+
+
var dogapi = require("dogapi");
+dogapi.now();
+// this is the same as
+parseInt(new Date().getTime() / 1000);
+
+
+
From 7250b5262efe2ee31e2a8a77c62100a0e88cc0f1 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:36:46 -0400
Subject: [PATCH 14/65] add user api
---
lib/api/index.js | 3 ++-
lib/api/user.js | 33 +++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 lib/api/user.js
diff --git a/lib/api/index.js b/lib/api/index.js
index 3d0faa8..94cf122 100644
--- a/lib/api/index.js
+++ b/lib/api/index.js
@@ -2,7 +2,8 @@ var api = {
tag: require("./tag"),
metric: require("./metric"),
event: require("./event"),
- serviceCheck: require("./serviceCheck")
+ serviceCheck: require("./serviceCheck"),
+ user: require("./user")
};
module.exports = function(obj){
diff --git a/lib/api/user.js b/lib/api/user.js
new file mode 100644
index 0000000..580dd83
--- /dev/null
+++ b/lib/api/user.js
@@ -0,0 +1,33 @@
+var client = require("../client");
+
+/*section: user
+ *comment: invite users via e-mail
+ *params:
+ * emails: an array of email addresses to send invites to
+ * callback: function(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * var emails = ["me@domain.com", "you@domain.com"];
+ * dogapi.user.invite(emails, fuction(err, res){
+ * console.dir(res):
+ * });
+ * ```
+ */
+function invite(emails, callback){
+ var params = {
+ body: {
+ emails: emails
+ }
+ };
+ client.request("POST", "/invite_users", params, callback);
+};
+
+module.exports = {
+ invite: invite
+};
From 001f263963bd29b7d4917d523c92f200bb8fa4fc Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:37:46 -0400
Subject: [PATCH 15/65] Add comment for dogapi.initialize
---
lib/index.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/index.js b/lib/index.js
index 4d77121..08f06fa 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,6 +1,7 @@
require("./api")(module.exports);
/*section: dogapi
+ *comment: configure the dogapi client with your app/api keys
*params:
* options:
* |
From 0a06e34c52f0dd828f89772de31f55e7ec57a0a2 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:37:55 -0400
Subject: [PATCH 16/65] build docs
---
index.html | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/index.html b/index.html
index cdab18b..5b0288c 100644
--- a/index.html
+++ b/index.html
@@ -24,6 +24,8 @@ document.addEventListener("DOMContentLoaded", function(){hljs.initHighlightingOn
tag
+user
+
client
dogapi
@@ -517,6 +519,41 @@ dogapi.tag.delete("host.name", function(err, results){
+
+
+
user
+
+
+
invite(emails, callback)
+
+
invite users via e-mail
+
Parameters:
+
+- emails
+an array of email addresses to send invites to
+
+- callback
+function(err, res)
+
+
+
+
+
var dogapi = require("dogapi");
+var options = {
+ api_key: "api_key",
+ app_key: "app_key"
+};
+dogapi.initialize(options);
+var emails = ["me@domain.com", "you@domain.com"];
+dogapi.user.invite(emails, fuction(err, res){
+ console.dir(res):
+});
+
+
+
+
client
@@ -577,6 +614,7 @@ dogapi.client.request("GET", "/url/path", {}, function(err,
initialize(options)
+
configure the dogapi client with your app/api keys
Parameters:
- options
From 2251c3825938414d07fcb07d34034a1d9c557cd3 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 09:39:16 -0400
Subject: [PATCH 17/65] remove docs from readme
---
README.md | 91 -------------------------------------------------------
1 file changed, 91 deletions(-)
diff --git a/README.md b/README.md
index 26d7293..b3cc743 100644
--- a/README.md
+++ b/README.md
@@ -45,97 +45,6 @@ var app = new dogapi(options);
DD_API_KEY=YOUR_KEY_HERE DD_APP_KEY=YOUR_KEY_HERE node app.js
```
-## API
-
-`dogapi` implements all available functions in the official datadog api, http://docs.datadoghq.com/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
-
## Sample Usage:
**Example:** get all events since this time yesterday:
From 7b836fd0c3fabe1fd2c7a8607344a5cae2bd7c57 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 13:03:02 -0400
Subject: [PATCH 18/65] fix example indentation for metric
---
lib/api/metric.js | 92 +++++++++++++++++++++++------------------------
1 file changed, 46 insertions(+), 46 deletions(-)
diff --git a/lib/api/metric.js b/lib/api/metric.js
index 97f530f..472ae88 100644
--- a/lib/api/metric.js
+++ b/lib/api/metric.js
@@ -18,19 +18,19 @@ var client = require("../client");
* 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);
- * });
+ * 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){
@@ -68,27 +68,27 @@ function send(metric, points, extra, 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);
- * });
+ * 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){
@@ -114,18 +114,18 @@ function send_all(metrics, callback){
* 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);
- * });
+ * 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){
From 6f3b077d49e9940812ead369d8ffbcb827524a57 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 13:04:09 -0400
Subject: [PATCH 19/65] add infrastructure.search api
---
lib/api/index.js | 3 ++-
lib/api/infrastructure.js | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
create mode 100644 lib/api/infrastructure.js
diff --git a/lib/api/index.js b/lib/api/index.js
index 94cf122..1125d63 100644
--- a/lib/api/index.js
+++ b/lib/api/index.js
@@ -3,7 +3,8 @@ var api = {
metric: require("./metric"),
event: require("./event"),
serviceCheck: require("./serviceCheck"),
- user: require("./user")
+ user: require("./user"),
+ infrastructure: require("./infrastructure")
};
module.exports = function(obj){
diff --git a/lib/api/infrastructure.js b/lib/api/infrastructure.js
new file mode 100644
index 0000000..4ed7d29
--- /dev/null
+++ b/lib/api/infrastructure.js
@@ -0,0 +1,36 @@
+var client = require("../client");
+
+/*section: infrastructure
+ *comment: |
+ * search for metrics or hosts
+ *params:
+ * query: |
+ * the query to use for search see [datadog docs](http://docs.datadoghq.com/api/#search)
+ * for examples of the query (e.g. "hosts:database", "metrics:system" or "test")
+ * callback: function(err, res)
+ *example: |
+ * ```javascript
+ * var dogapi = require("dogapi");
+ * var options = {
+ * api_key: "api_key",
+ * app_key: "app_key"
+ * };
+ * dogapi.initialize(options);
+ * dogapi.infrastructure.search("hosts:database", function(err, res){
+ * console.dir(res);
+ * });
+ * ```
+ */
+function search(query, callback){
+ var params = {
+ query: {
+ q: query
+ }
+ };
+
+ client.request("GET", "/search", params, callback);
+}
+
+module.exports = {
+ search: search
+};
From 94f0196ee63e300ee849f5a21b9828effd9278b1 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 13:04:13 -0400
Subject: [PATCH 20/65] build docs
---
index.html | 129 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 83 insertions(+), 46 deletions(-)
diff --git a/index.html b/index.html
index 5b0288c..33c52e7 100644
--- a/index.html
+++ b/index.html
@@ -18,6 +18,8 @@ document.addEventListener("DOMContentLoaded", function(){hljs.initHighlightingOn
+
+
+
infrastructure
+
+
+
search(query, callback)
+
+
search for metrics or hosts
+
Parameters:
+
+- query
+the query to use for search see search docs
+for examples of the query (e.g. "hosts:database", "metrics:system" or "test")
+
+- callback
+function(err, res)
+
+
+
+
+
var dogapi = require("dogapi");
+var options = {
+ api_key: "api_key",
+ app_key: "app_key"
+};
+dogapi.initialize(options);
+dogapi.infrastructure.search("hosts:database", function(err, res){
+ console.dir(res);
+});
+
+
+
+
metric
@@ -201,19 +238,19 @@ is given "now" is used as the timestamp
-
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);
- });
+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);
+});
@@ -239,27 +276,27 @@ is given "now" is used as the timestamp
-
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);
- });
+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);
+});
@@ -284,18 +321,18 @@ is given "now" is used as the timestamp
-
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);
- });
+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);
+});
From 8e3e9787b88cda92536835510bc75321ce48cab9 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 13:52:02 -0400
Subject: [PATCH 21/65] ignore .dogapirc file
---
.gitignore | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitignore b/.gitignore
index 303335e..82cee7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@ logs
results
npm-debug.log
+
+.dogapirc
From 17da0c0f6b368b8ce8eebab3e70d5e83583689eb Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 14:39:16 -0400
Subject: [PATCH 22/65] add start to cli tool
---
bin/dogapi | 70 +++++++++++++++++++++++++++++++++++++++
lib/api/infrastructure.js | 11 +++++-
lib/api/metric.js | 39 +++++++++++++++++++++-
package.json | 7 +++-
4 files changed, 124 insertions(+), 3 deletions(-)
create mode 100755 bin/dogapi
diff --git a/bin/dogapi b/bin/dogapi
new file mode 100755
index 0000000..d872d89
--- /dev/null
+++ b/bin/dogapi
@@ -0,0 +1,70 @@
+#!/usr/bin/env node
+var dogapi = require("../");
+var minimist = require("minimist");
+var rc = require("rc");
+
+var config = rc("dogapi", {
+ api_key: null,
+ app_key: null
+});
+dogapi.initialize(config);
+
+var usage = [
+ "Usage:",
+ "${command} --help",
+ "${command} --version",
+ "${command} now",
+ "${command} then "
+];
+var help = [];
+for(var key in dogapi){
+ if(!dogapi.hasOwnProperty(key)){
+ continue;
+ } else if(!dogapi[key].hasOwnProperty("getUsage") || typeof dogapi[key].getUsage !== "function"){
+ continue;
+ } else if(!dogapi[key].hasOwnProperty("handleCli") || typeof dogapi[key].handleCli !== "function"){
+ continue;
+ }
+ usage = usage.concat(dogapi[key].getUsage());
+
+ if(dogapi[key].hasOwnProperty("getHelp") && typeof dogapi[key].getHelp === "function"){
+ help = help.concat(["\r\n"], dogapi[key].getHelp());
+ }
+}
+
+usage = usage.concat(help);
+usage = usage.join("\r\n").replace(/\$\{command\}/g, " dogapi");
+var args = minimist(process.argv);
+
+var command = args._[2];
+var subcommand = args._[3];
+
+if(command === "now"){
+ console.log(dogapi.now());
+} else if(command === "then" && args._.length > 3){
+ console.log(dogapi.now() - parseInt(args._[args._.length - 1]));
+} else if(dogapi.hasOwnProperty(command)){
+ if(subcommand && dogapi[command].hasOwnProperty(subcomand)){
+ dogapi[command].handleCli(subcommand, args, function(err, res){
+ if(err){
+ console.error(err);
+ process.exit(1);
+ } else {
+ if(res === ""){
+ res = "success";
+ }
+ console.log(res);
+ }
+ });
+ } else {
+ var commandUsage = ["Usage:"].concat(dogapi[command].getUsage());
+ if(dogapi[command].hasOwnProperty("getHelp") && typeof dogapi[command].getHelp === "function"){
+ commandUsage = commandUsage.concat(["\r\n"], dogapi[command].getHelp());
+ }
+ console.log(commandUsage.join("\r\n").replace(/\$\{command\}/g, " dogapi"));
+ }
+} else if(args.version){
+ console.log(require("../package.json").version);
+} else {
+ console.log(usage);
+}
diff --git a/lib/api/infrastructure.js b/lib/api/infrastructure.js
index 4ed7d29..73e1deb 100644
--- a/lib/api/infrastructure.js
+++ b/lib/api/infrastructure.js
@@ -32,5 +32,14 @@ function search(query, callback){
}
module.exports = {
- search: search
+ search: search,
+ getUsage: function(){
+ return [
+ "${command} infrastructure search "
+ ]
+ },
+ handleCli: function(subcommand, args, callback){
+ var query = args._[4];
+ search(query, callback);
+ }
};
diff --git a/lib/api/metric.js b/lib/api/metric.js
index 472ae88..bf46145 100644
--- a/lib/api/metric.js
+++ b/lib/api/metric.js
@@ -139,5 +139,42 @@ function query(from, to, query, callback){
module.exports = {
send: send,
- send_all: send_all
+ send_all: send_all,
+ query: query,
+ getUsage: function(){
+ return [
+ "${command} metric send [--tags ] [--host ] [--type ]",
+ "${command} metric query "
+ ]
+ },
+ getHelp: function(){
+ return [
+ "Metric Options:",
+ " --tags a comma separated list of \"tag:value\"'s",
+ " --host the hostname that should be associated with this metric",
+ " --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[""], args[""], 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 --help` for help", false);
+ }
+ }
};
diff --git a/package.json b/package.json
index fc139a3..2c65bbd 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,9 @@
"test": "echo \"Error: no test specified\" && exit 1",
"docs": "node ./docs/create.js > index.html"
},
+ "bin": {
+ "dogapi": "bin/dogapi"
+ },
"repository": {
"type": "git",
"url": "git://github.com/brettlangdon/node-dogapi"
@@ -28,7 +31,9 @@
"readmeFilename": "README.md",
"gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc",
"dependencies": {
- "extend": "^2.0.0"
+ "extend": "^2.0.0",
+ "minimist": "^1.1.1",
+ "rc": "^1.0.0"
},
"devDependencies": {
"docast": "^0.1.1",
From 0123b0d25b218168981653f67f8d62e7e5833a1a Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 14:39:30 -0400
Subject: [PATCH 23/65] fix param format for dogapi.metric.query
---
lib/api/metric.js | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/api/metric.js b/lib/api/metric.js
index bf46145..ee9f663 100644
--- a/lib/api/metric.js
+++ b/lib/api/metric.js
@@ -130,9 +130,11 @@ function send_all(metrics, callback){
*/
function query(from, to, query, callback){
var params = {
- from: from,
- to: to,
- query: query
+ query: {
+ from: from,
+ to: to,
+ query: query
+ }
};
client.request("GET", "/query", params, callback);
}
From 80f84f6a81fc870683aa46c71a4aaffe4fc88e1d Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 14:41:10 -0400
Subject: [PATCH 24/65] remove old api code
---
lib/api/alert.js | 123 --------------------------------------------
lib/api/dash.js | 103 -------------------------------------
lib/api/downtime.js | 102 ------------------------------------
lib/api/screen.js | 116 -----------------------------------------
lib/api/search.js | 16 ------
lib/api/snapshot.js | 101 ------------------------------------
6 files changed, 561 deletions(-)
delete mode 100644 lib/api/alert.js
delete mode 100644 lib/api/dash.js
delete mode 100644 lib/api/downtime.js
delete mode 100644 lib/api/screen.js
delete mode 100644 lib/api/search.js
delete mode 100644 lib/api/snapshot.js
diff --git a/lib/api/alert.js b/lib/api/alert.js
deleted file mode 100644
index cc7bc9c..0000000
--- a/lib/api/alert.js
+++ /dev/null
@@ -1,123 +0,0 @@
-var util = require('util');
-
-
-var alert_api = function(){};
-
-alert_api.prototype.add_alert = function(alert, callback){
- /*
- * alert_api.add_alert(alert, [callback])
- *
- * add a new alert to datadog
- *
- * `alert` is an object containing:
- * query: *required*, the metric to query on
- * name: name of the alert
- * message: an optional message to include with the alert
- * silenced: whether the alert should notify by email and in the stream
- *
- * `callback` an optional function to get called with the results of the api call
- * callback(error, result, status_code)
- */
- if(typeof alert != 'object'){
- throw new Error('`alert` parameter must be an object');
- }
-
- if(!alert['query']){
- throw new Error('`alert["query"]` is required');
- }
-
- this.request('POST', '/alert', {body: alert}, callback);
-};
-
-alert_api.prototype.update_alert = function(alert_id, alert, callback){
- /*
- * alert_api.update_alert(alert_id, alert, [callback])
- *
- * update an existing alert
- *
- * `alert_id` the id of alert to update
- * `alert` is an object containing:
- * query: *required*, the metric to query on
- * name: name of the alert
- * message: an optional message to include with the alert
- * silenced: whether the alert should notify by email and in the stream
- *
- * `callback` an optional function to get called with the results of the api call
- * callback(error, result, status_code)
- */
- if(typeof alert != 'object'){
- throw new Error('`alert` parameter must be an object');
- }
-
- if(!alert['query']){
- throw new Error('`alert["query"]` is required');
- }
-
- this.request('PUT', util.format('/alert/%s', alert_id), {body: alert}, callback);
-};
-
-alert_api.prototype.get_alert = function(alert_id, callback){
- /*
- * alert_api.get_alert(alert_id, [callback])
- *
- * get the details of an alert from the given id
- *
- * `alert_id` the id for the alert to get
- *
- * `callback` an optional function to call with the results
- * callback(error, result, status_code)
- */
- this.request('GET', util.format('/alert/%s', alert_id), callback);
-};
-
-alert_api.prototype.delete_alert = function(alert_id, callback){
- /*
- * alert_api.delete_alert(alert_id, [callback])
- *
- * delete the given alert from datadog
- *
- * `alert_id` the id for the alert to get
- *
- * `callback` an optional function to call with the results
- * callback(error, result, status_code)
- */
- this.request('DELETE', util.format('/alert/%s', alert_id), callback);
-};
-
-alert_api.prototype.get_all_alerts = function(callback){
- /*
- * alert_api.get_all_alerts([callback])
- *
- * get the details of all alerts in datadog
- *
- * `callback` an optional function to call with the results
- * callback(error, result, status_code)
- */
- this.request('GET', '/alert', callback);
-};
-
-alert_api.prototype.mute_alerts = function(callback){
- /*
- * alert_api.mute_alerts([callback])
- *
- * mute all alerts
- *
- * `callback` an optional function to call with the results
- * callback(error, result, status_code)
- */
- this.request('POST', '/mute_alerts', callback);
-};
-
-alert_api.prototype.unmute_alerts = function(callback){
- /*
- * alert_api.unmute_alerts([callback])
- *
- * unmute all alerts
- *
- * `callback` an optional function to call with the results
- * callback(error, result, status_code)
- */
- this.request('POST', '/unmute_alerts', callback);
-};
-
-return module.exports = alert_api;
diff --git a/lib/api/dash.js b/lib/api/dash.js
deleted file mode 100644
index 8abe9c4..0000000
--- a/lib/api/dash.js
+++ /dev/null
@@ -1,103 +0,0 @@
-var util = require('util');
-
-var validate_dashboard = function(dashboard){
- if(typeof dashboard != 'object'){
- throw new Error('`dashboard` parameter must be an object');
- }
-
- if(dashboard['title'] != 'string'){
- throw new Error('`dashboard["title"]` must be a string');
- }
-
- if(typeof dashboard['description'] != 'string'){
- throw new Error('`dashboard["description"]` must be a string');
- }
-
- if(typeof dashboard['graphs'] != 'object'){
- throw new Error('`dashboard["graphs"]` must be an array');
- }
-
- for(var i in dashboard['graphs']){
- if(!dashboard['graphs'][i]['title']){
- throw new Error(util.format('`dashboard["graphs"][%s]["title"]` is missing', i));
- }
- if(!dashboard['graphs'][i]['definition']){
- throw new Error(util.format('`dashboard["graphs"][%s]["definition"]` is missing', i));
- }
- }
-};
-
-var dash_api = function(){};
-
-dash_api.prototype.get_dashboard = function(dash_id, callback){
- /*
- * dash_api.get_dashboard(dash_id, [callback])
- *
- * method to get a single dashboard information
- *
- * `dash_id` is the id of the dashboard to get information for
- * `callback` is an optional function to call with the results of the api call
- * callback(error, results, status_code)
- */
- this.request('GET', util.format('/dash/%s', dash_id), callback);
-};
-
-dash_api.prototype.get_all_dashboards = function(callback){
- /*
- * dash_api.get_all_dashboards([callback])
- *
- * method to retrieve all dashboards in datadog
- *
- * `callback` is an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- this.request('GET', '/dash', callback);
-};
-
-dash_api.prototype.create_dashboard = function(dashboard, callback){
- /*
- * dash_api.create_dashboard(dashboard, [callback])
- *
- * method used to create a new dashboard in datadog
- *
- * `dashboard` is the definition for the dashboard
- * please see (http://docs.datadoghq.com/api/) for more information
- *
- * `callback` is an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- validate_dashboard(dashboard);
- this.request('POST', '/dash', {body: dashboard}, callback);
-};
-
-dash_api.prototype.update_dashboard = function(dash_id, dashboard, callback){
- /*
- * dash_api.update_dashboard(dash_id, dashboard, [callback])
- *
- * method used to update the dashboard with the provided `dash_id`
- *
- * `dash_id` the id of the dashboard to update
- * `dashboard` is a definition for the datadog dashboard
- * please see (http://docs.datadoghq.com/api/) for more information
- *
- * `callback` an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- validate_dashboard(dashboard);
- this.request('PUT', util.format('/dash/%s', dash_id), {body: dashbboard}, callback);
-};
-
-dash_api.prototype.delete_dashboard = function(dash_id, callback){
- /*
- * dash_api.delete_dashboard(dash_id, [callback])
- *
- * method to remove a dashboard from datadog
- *
- * `dash_id` the id for the dashboard to remove
- * `callback` an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- this.request('DELETE', util.format('/dash/%s', dash_id), callback);
-};
-
-return module.exports = dash_api;
diff --git a/lib/api/downtime.js b/lib/api/downtime.js
deleted file mode 100644
index 98dcf66..0000000
--- a/lib/api/downtime.js
+++ /dev/null
@@ -1,102 +0,0 @@
-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');
- }
-
- if(typeof options === 'function'){
- callback = options;
- options = {};
- }
- options.scope = scope;
-
- 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 = {};
- }
-
- this.request('PUT', util.format('/downtime/%s', downtime_id), {body: options}, 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)
- */
-
- this.request('GET', util.format('/downtime/%s', downtime_id), 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;
- }
-
- query = {};
- if(current_only){
- query.current_only = true;
- }
-
- this.request('GET', '/downtime', {query: query}, callback);
-};
-
-return module.exports = downtime_api;
diff --git a/lib/api/screen.js b/lib/api/screen.js
deleted file mode 100644
index febfb8f..0000000
--- a/lib/api/screen.js
+++ /dev/null
@@ -1,116 +0,0 @@
-var util = require('util');
-
-var validate_screenboard = function(screenboard){
- if(typeof screenboard != 'object'){
- throw new Error('`screenboard` parameter must be an object');
- }
-
- if(typeof screenboard['board_title'] != 'string'){
- throw new Error('`screenboard["board_title"]` must be a string');
- }
-
- if(screenboard['width'] != undefined && typeof screenboard['width'] != 'number'){
- throw new Error('`screenboard["width"]` must be a number');
- }
-
- if(screenboard['height'] != undefined && typeof screenboard['height'] != 'number'){
- throw new Error('`screenboard["height"]` must be a number');
- }
-
- if(typeof screenboard['widgets'] != 'object'){
- throw new Error('`screenboard["widgets"]` must be an array');
- }
-
- for(var i in screenboard['widgets']){
- if(!screenboard['widgets'][i]['type']){
- throw new Error(util.format('`screenboard["widgets"][%s]["type"]` is missing', i));
- }
- if(!screenboard['widgets'][i]['width']){
- throw new Error(util.format('`screenboard["widgets"][%s]["width"]` is missing', i));
- }
- if(!screenboard['widgets'][i]['height']){
- throw new Error(util.format('`screenboard["widgets"][%s]["height"]` is missing', i));
- }
- if(!screenboard['widgets'][i]['x']){
- throw new Error(util.format('`screenboard["widgets"][%s]["x"]` is missing', i));
- }
- if(!screenboard['widgets'][i]['y']){
- throw new Error(util.format('`screenboard["widgets"][%s]["y"]` is missing', i));
- }
- }
-};
-
-var screen_api = function(){};
-
-screen_api.prototype.get_screenboard = function(screen_id, callback){
- /*
- * screen_api.get_screenboard(screen_id, [callback])
- *
- * method to get a single screenboard information
- *
- * `screen_id` is the id of the screenboard to get information for
- * `callback` is an optional function to call with the results of the api call
- * callback(error, results, status_code)
- */
- this.request('GET', util.format('/screen/%s', screen_id), callback);
-};
-
-screen_api.prototype.get_all_screenboards = function(callback){
- /*
- * screen_api.get_all_screenboards([callback])
- *
- * method to retrieve all screenboards in datadog
- *
- * `callback` is an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- this.request('GET', '/screen', callback);
-};
-
-screen_api.prototype.create_screenboard = function(screenboard, callback){
- /*
- * screen_api.create_screenboard(screenboard, [callback])
- *
- * method used to create a new screenboard in datadog
- *
- * `screenboard` is the definition for the screenboard
- * please see (http://docs.datadoghq.com/api/) for more information
- *
- * `callback` is an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- validate_screenboard(screenboard);
- this.request('POST', '/screen', {body: screenboard}, callback);
-};
-
-screen_api.prototype.update_screenboard = function(screen_id, screenboard, callback){
- /*
- * screen_api.update_screenboard(screen_id, screenboard, [callback])
- *
- * method used to update the screenboard with the provided `screen_id`
- *
- * `screen_id` the id of the screenboard to update
- * `screenboard` is a definition for the datadog screenboard
- * please see (http://docs.datadoghq.com/api/) for more information
- *
- * `callback` an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- validate_screenboard(screenboard);
- this.request('PUT', util.format('/screen/%s', screen_id), {body: screenboard}, callback);
-};
-
-screen_api.prototype.delete_screenboard = function(screen_id, callback){
- /*
- * screen_api.delete_screenboard(screen_id, [callback])
- *
- * method to remove a screenboard from datadog
- *
- * `screen_id` the id for the screenboard to remove
- * `callback` an optional function to call with the results of the api call
- * callback(error, result, status_code)
- */
- this.request('DELETE', util.format('/screen/%s', screen_id), callback);
-};
-
-return module.exports = screen_api;
diff --git a/lib/api/search.js b/lib/api/search.js
deleted file mode 100644
index 416110c..0000000
--- a/lib/api/search.js
+++ /dev/null
@@ -1,16 +0,0 @@
-var search_api = function(){};
-search_api.prototype.search = function(query, callback){
- /*
- * search_api.search(query, [callback])
- *
- * method used to query the api for `metrics` or `hosts`
- *
- * `query` the query to use to search the datadog service
- *
- * `callback` an optional function called with the results of the search
- * callback(error, result, status_code)
- */
- this.request('GET', '/search', {query: {'q': query}}, callback);
-};
-
-return module.exports = search_api;
diff --git a/lib/api/snapshot.js b/lib/api/snapshot.js
deleted file mode 100644
index 2ce482a..0000000
--- a/lib/api/snapshot.js
+++ /dev/null
@@ -1,101 +0,0 @@
-var extend = require('extend');
-var util = require('util');
-
-var snapshot_api = function(){};
-
-snapshot_api.prototype.add_snapshot = function(snapshot, callback){
- /*
- * snapshot_api.add_snapshot(snapshot, [callback])
- *
- * method used to add a new snapshot to datadog
- *
- * `snapshot` is an object containing any of the following:
- * metric_query: *required*, The metric query.
- * start: *required*, int, Start of the query.(POSIX timestamp)
- * end: *required*, int, End of the query.(POSIX timestamp)
- * event_query: A query that will add event bands to the graph.
- *
- * `callback` is an optional function for the result
- * callback(error, result, status_code)
- */
- if(typeof snapshot != 'object'){
- throw new Error('`snapshot` parameter must be an object');
- }
-
- if(!snapshot['metric_query']){
- throw new Error('`metric_query` property of `snapshot` parameter is required');
- }
-
- if(!snapshot['start']){
- throw new Error('`start` property of `snapshot` parameter is required');
- }
-
- if(!snapshot['end']){
- throw new Error('`end` property of `snapshot` parameter is required');
- }
-
- this.request('GET', '/graph/snapshot', {query: snapshot}, callback);
-};
-
-snapshot_api.prototype.add_snapshot_from_def = function(snapshot, callback){
- /*
- * snapshot_api.add_snapshot_from_def(snapshot, [callback])
- *
- * method used to add a new snapshot to datadog based on a graph definition
- * https://github.com/DataDog/dogapi/commit/583f13d7bd8de5a86daa2ff53f2d7cf6570e7ab2
- * feature is not currently documented (at time of writing), but very useful.
- *
- * `snapshot` is an object containing any of the following:
- * graph_def: *required*, JSON string dump of an existing graph definition
- * start: *required*, int, Start of the query.(POSIX timestamp)
- * end: *required*, int, End of the query.(POSIX timestamp)
- *
- * `callback` is an optional function for the result
- * callback(error, result, status_code)
- */
- if(typeof snapshot != 'object'){
- throw new Error('`snapshot` parameter must be an object');
- }
-
- if(!snapshot['graph_def']){
- throw new Error('`graph_def` property of `snapshot` parameter is required');
- }
-
- if(!snapshot['start']){
- throw new Error('`start` property of `snapshot` parameter is required');
- }
-
- if(!snapshot['end']){
- throw new Error('`end` property of `snapshot` parameter is required');
- }
-
- this.request('GET', '/graph/snapshot', {query: snapshot}, callback);
-};
-
-snapshot_api.prototype.snapshot_status = function(snapshot_url, callback){
- /*
- * snapshot_api.add_snapshot(snapshot_url, [callback])
- *
- * method used to check the status of a datadog snapshot.
- * https://github.com/DataDog/dogapi/blob/master/src/dogapi/http/snapshot.py#L64
- * Snapshot URLs are returned right away, but may be empty if the query or graph is complicated.
- * Result will be a json payload, with 403 for incomplete, or 200 for complete.
- * Examples:
- * * {"status_code":403} - incomplete (still processing, image is empty)
- * * {"status_code":200} - image is rendered and ready
- *
- * `snapshot_url` is a string containing URL returned from a call to add_snapshot or add_snapshot_from_def
- *
- * `callback` is an optional function for the result
- * callback(error, result, status_code)
- */
- if(typeof snapshot_url != 'string'){
- throw new Error('`snapshot_url` parameter must be a string');
- }
-
- url = snapshot_url.split('/snapshot/view/')[1].split('.png')[0]
-
- this.request('GET', '/graph/snapshot_status/'+url, {}, callback);
-};
-
-return module.exports = snapshot_api;
From 9ccf2563869f2bfeda1caf7b6510f25f97230ae1 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 14:43:49 -0400
Subject: [PATCH 25/65] fix spelling mistake
---
bin/dogapi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bin/dogapi b/bin/dogapi
index d872d89..fbae857 100755
--- a/bin/dogapi
+++ b/bin/dogapi
@@ -44,7 +44,7 @@ if(command === "now"){
} else if(command === "then" && args._.length > 3){
console.log(dogapi.now() - parseInt(args._[args._.length - 1]));
} else if(dogapi.hasOwnProperty(command)){
- if(subcommand && dogapi[command].hasOwnProperty(subcomand)){
+ if(subcommand && dogapi[command].hasOwnProperty(subcommand)){
dogapi[command].handleCli(subcommand, args, function(err, res){
if(err){
console.error(err);
From b61e7e14a9d837cdbb9ae9cb63cc0b074c621fa0 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 14:44:29 -0400
Subject: [PATCH 26/65] add cli commands for user invite
---
lib/api/user.js | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/api/user.js b/lib/api/user.js
index 580dd83..3436ca6 100644
--- a/lib/api/user.js
+++ b/lib/api/user.js
@@ -29,5 +29,13 @@ function invite(emails, callback){
};
module.exports = {
- invite: invite
+ invite: invite,
+ getUsage: function(){
+ return [
+ "${command} user invite ..."
+ ];
+ },
+ handleCli: function(subcommand, args, callback){
+ invite(args._.slice(4), callback)
+ }
};
From f40d2f41ac0cf2f7f6d52c65522e246817d7032b Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 15:00:38 -0400
Subject: [PATCH 27/65] add tag commands to cli
---
lib/api/tag.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/lib/api/tag.js b/lib/api/tag.js
index e376b8c..5d0e634 100644
--- a/lib/api/tag.js
+++ b/lib/api/tag.js
@@ -210,4 +210,52 @@ module.exports = {
create: create,
update: update,
"delete": delete_tags,
+ getUsage: function(){
+ return [
+ "${command} tag get_all [--source ]",
+ "${command} tag get [--source ] [--by-source]",
+ "${command} tag delete [--source ]",
+ "${command} tag create [--source ]",
+ "${command} tag update [--source ]"
+ ];
+ },
+ getHelp: function(){
+ return [
+ "Tag Commands:",
+ " get_all get all tags",
+ " get get all tags for a given host",
+ " delete delete tags for a given host",
+ " create add the comma separates \"tag:value\"'s from to ",
+ " update update the comma separates \"tag:value\"'s from to ",
+ "",
+ "Tag Options:",
+ " --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 === "get_all"){
+ get_all(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"){
+ delete_tags(host, source, callback);
+ }
+ }
}
From 4051602e9278c73bdf7e5a845e9238640c0f6a08 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 15:01:37 -0400
Subject: [PATCH 28/65] rename dogapi.tag.delete to dogapi.tag.remove
---
lib/api/tag.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/api/tag.js b/lib/api/tag.js
index 5d0e634..bede22e 100644
--- a/lib/api/tag.js
+++ b/lib/api/tag.js
@@ -184,12 +184,12 @@ function update(hostname, tags, source, callback){
* app_key: "app_key"
* };
* dogapi.initialize(options);
- * dogapi.tag.delete("host.name", function(err, results){
+ * dogapi.tag.remove("host.name", function(err, results){
* console.dir(results);
* });
* ```
*/
-function delete_tags(hostname, source, callback){
+function remove(hostname, source, callback){
if(arguments.length < 3 && typeof arguments[1] === "function"){
callback = source;
source = undefined;
@@ -209,12 +209,12 @@ module.exports = {
get: get,
create: create,
update: update,
- "delete": delete_tags,
+ remove: remove,
getUsage: function(){
return [
"${command} tag get_all [--source ]",
"${command} tag get [--source ] [--by-source]",
- "${command} tag delete [--source ]",
+ "${command} tag remove [--source ]",
"${command} tag create [--source ]",
"${command} tag update [--source ]"
];
@@ -224,7 +224,7 @@ module.exports = {
"Tag Commands:",
" get_all get all tags",
" get get all tags for a given host",
- " delete delete tags for a given host",
+ " remove delete tags for a given host",
" create add the comma separates \"tag:value\"'s from to ",
" update update the comma separates \"tag:value\"'s from to ",
"",
@@ -255,7 +255,7 @@ module.exports = {
var tags = args._[5].split(",");
update(host, tags, source, callback);
} else if(subcommand === "delete"){
- delete_tags(host, source, callback);
+ remove(host, source, callback);
}
}
}
From 2e85bb5a1d25dc9145b3baedeef34fbe5cff0ce9 Mon Sep 17 00:00:00 2001
From: brettlangdon
Date: Sat, 21 Mar 2015 15:01:50 -0400
Subject: [PATCH 29/65] rebuild docs
---
index.html | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/index.html b/index.html
index 33c52e7..55d4309 100644
--- a/index.html
+++ b/index.html
@@ -181,7 +181,7 @@ document.addEventListener("DOMContentLoaded", function(){hljs.initHighlightingOn
Parameters:
- query
-the query to use for search see search docs
+
the query to use for search see datadog docs
for examples of the query (e.g. "hosts:database", "metrics:system" or "test")
- callback
@@ -396,7 +396,7 @@ dogapi.metric.query(then, now, query, function(err, res){
get
create
update
-delete_tags
+remove
get_all(source, callback)
@@ -525,8 +525,8 @@ dogapi.tag.update("host.name", function(err, results){
-