Browse Source

fix #1: add support for screenboards

pull/2/merge v0.1.2
Brett Langdon 13 years ago
parent
commit
da2ddd0027
4 changed files with 130 additions and 1 deletions
  1. +10
    -0
      README.md
  2. +117
    -0
      lib/api/screen.js
  3. +2
    -0
      lib/index.js
  4. +1
    -1
      package.json

+ 10
- 0
README.md View File

@ -87,6 +87,16 @@ DD_API_KEY=YOUR_KEY_HERE DD_APP_KEY=YOUR_KEY_HERE node app.js
* method used to update the dashboard with the provided `dash_id` * method used to update the dashboard with the provided `dash_id`
* `dogapi.delete_dashboard(dash_id, [callback])` * `dogapi.delete_dashboard(dash_id, [callback])`
* method to remove a dashboard from datadog * 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])` * `dogapi.search(query, [callback])`
* method used to query the api for `metrics` or `hosts` * method used to query the api for `metrics` or `hosts`
* `dogapi.add_metric(metric, [callback])` * `dogapi.add_metric(metric, [callback])`


+ 117
- 0
lib/api/screen.js View File

@ -0,0 +1,117 @@
var util = require('util');
var v8type = require('v8type');
var validate_screenboard = function(screenboard){
if(!v8type.of(screenboard, v8type.OBJECT)){
throw new Error('`screenboard` parameter must be an object');
}
if(!v8type.of(screenboard['board_title'], v8type.STRING)){
throw new Error('`screenboard["board_title"]` must be a string');
}
if(screenboard['width'] != undefined && !v8type.of(screenboard['width'], v8type.NUMBER)){
throw new Error('`screenboard["width"]` must be a number');
}
if(screenboard['height'] != undefined && !v8type.of(screenboard['height'], v8type.NUMBER)){
throw new Error('`screenboard["height"]` must be a number');
}
if(!v8type.of(screenboard['widgets'], v8type.ARRAY)){
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;

+ 2
- 0
lib/index.js View File

@ -3,6 +3,7 @@ var extend = require('extend');
var http_client = require('./http_client.js'); var http_client = require('./http_client.js');
var alert_api = require('./api/alert.js'); var alert_api = require('./api/alert.js');
var dash_api = require('./api/dash.js'); var dash_api = require('./api/dash.js');
var screen_api = require('./api/screen.js');
var event_api = require('./api/event.js'); var event_api = require('./api/event.js');
var tag_api = require('./api/tag.js'); var tag_api = require('./api/tag.js');
var metric_api = require('./api/metric.js'); var metric_api = require('./api/metric.js');
@ -16,6 +17,7 @@ extend(dogapi.prototype,
http_client.prototype, http_client.prototype,
alert_api.prototype, alert_api.prototype,
dash_api.prototype, dash_api.prototype,
screen_api.prototype,
event_api.prototype, event_api.prototype,
tag_api.prototype, tag_api.prototype,
metric_api.prototype, metric_api.prototype,


+ 1
- 1
package.json View File

@ -1,6 +1,6 @@
{ {
"name": "dogapi", "name": "dogapi",
"version": "0.1.1",
"version": "0.1.2",
"description": "Datadog API Node.JS Client", "description": "Datadog API Node.JS Client",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {


Loading…
Cancel
Save