From 1705858f2e13f47713ee38e37350ceb89cafde64 Mon Sep 17 00:00:00 2001 From: Dale Hamel Date: Mon, 29 Dec 2014 13:27:12 -0500 Subject: [PATCH 1/2] Add API to support graph_def based snapshots --- lib/api/snapshot.js | 37 +++++++++++++++++++++++++++++++++---- package.json | 3 ++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/api/snapshot.js b/lib/api/snapshot.js index d96c80d..a6f6f89 100644 --- a/lib/api/snapshot.js +++ b/lib/api/snapshot.js @@ -1,11 +1,8 @@ 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]) @@ -37,10 +34,42 @@ snapshot_api.prototype.add_snapshot = function(snapshot, callback){ 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); }; - return module.exports = snapshot_api; diff --git a/package.json b/package.json index 22242b5..55d3f56 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ ], "author": "Brett Langdon (http://brett.is)", "contributors":[ - "colinjonesx (http://www.thetestpeople.com)" + "colinjonesx (http://www.thetestpeople.com)", + "dalehamel (http://blog.srvthe.net)" ], "license": "MIT", "readmeFilename": "README.md", From 93b3c8e74afd61539e7e926c3254f1ae64631a5b Mon Sep 17 00:00:00 2001 From: Dale Hamel Date: Tue, 30 Dec 2014 00:08:08 -0500 Subject: [PATCH 2/2] Bump extend to avoid deprecation warnings --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55d3f56..c542c71 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,6 @@ "readmeFilename": "README.md", "gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc", "dependencies": { - "extend": "~1.1.3" + "extend": "^2.0.0" } }