Browse Source

Let and Const all the things 🛠️

pull/61/head
Adriean Khisbe 7 years ago
parent
commit
404e362717
17 changed files with 269 additions and 269 deletions
  1. +9
    -9
      lib/api/comment.js
  2. +8
    -8
      lib/api/downtime.js
  3. +17
    -17
      lib/api/embed.js
  4. +22
    -22
      lib/api/event.js
  5. +12
    -12
      lib/api/graph.js
  6. +11
    -11
      lib/api/host.js
  7. +2
    -2
      lib/api/index.js
  8. +5
    -5
      lib/api/infrastructure.js
  9. +24
    -24
      lib/api/metric.js
  10. +46
    -46
      lib/api/monitor.js
  11. +30
    -30
      lib/api/screenboard.js
  12. +5
    -5
      lib/api/search.js
  13. +7
    -7
      lib/api/serviceCheck.js
  14. +22
    -22
      lib/api/tag.js
  15. +32
    -32
      lib/api/timeboard.js
  16. +5
    -5
      lib/api/user.js
  17. +12
    -12
      lib/client.js

+ 9
- 9
lib/api/comment.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var util = require("util");
const client = require("../client");
const util = require("util");
/*section: comment
*comment: create a new comment
@ -29,7 +29,7 @@ function create(message, properties, callback){
properties = {};
}
var params = {
const params = {
body: {
message: message
}
@ -73,7 +73,7 @@ function update(commentId, message, handle, callback){
handle = undefined;
}
var params = {
const params = {
body: {
message: message
}
@ -134,8 +134,8 @@ module.exports = {
},
handleCli: function(subcommand, args, callback){
if(subcommand === "create"){
var message = args._[4];
var properties = {};
const message = args._[4];
const properties = {};
if(args["handle"]){
properties.handle = args["handle"];
}
@ -144,11 +144,11 @@ module.exports = {
}
create(message, properties, callback);
} else if(subcommand === "update"){
var commentId = args._[4];
var message = args._[5];
const commentId = args._[4];
const message = args._[5];
update(commentId, message, args["handle"], callback);
} else if(subcommand === "remove"){
var commentId = args._[4];
const commentId = args._[4];
remove(commentId, callback);
} else {
callback("unknown subcommand or arguments try `dogapi comment --help` for help", false);


+ 8
- 8
lib/api/downtime.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var util = require("util");
const client = require("../client");
const util = require("util");
/*section: downtime
*comment: schedule a new downtime
@ -30,7 +30,7 @@ function create(scope, properties, callback){
properties = {};
}
var params = {
const params = {
body: {
scope: scope
}
@ -81,7 +81,7 @@ function update(downtimeId, properties, callback){
callback = properties;
properties = {};
}
var params = {
const params = {
body: {}
};
if(typeof properties === "object"){
@ -207,8 +207,8 @@ module.exports = {
} else if(subcommand === "remove"){
remove(args._[4], callback);
} else if(subcommand === "create"){
var scope = args._[4];
var properties = {};
const scope = args._[4];
const properties = {};
if(args["start"]){
properties.start = parseInt(args["start"]);
}
@ -220,8 +220,8 @@ module.exports = {
}
create(scope, properties, callback);
} else if(subcommand === "update"){
var downtimeId = args._[4];
var properties = {};
const downtimeId = args._[4];
const properties = {};
if(args["scope"]){
properties.scope = args["scope"];
}


+ 17
- 17
lib/api/embed.js View File

@ -1,7 +1,7 @@
var client = require("../client");
var extend = require("extend");
var json = require("../json");
var querystring = require("querystring");
const client = require("../client");
const extend = require("extend");
const json = require("../json");
const querystring = require("querystring");
/*section: embed
*comment: create an embed graph of a metric query
@ -15,14 +15,14 @@ var querystring = require("querystring");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var query = "system.cpu.idle{*}";
* var graphJSON = {
* const query = "system.cpu.idle{*}";
* const graphJSON = {
* viz: "timeseries",
* requests: [
* {
@ -33,7 +33,7 @@ var querystring = require("querystring");
* }
* ]
* }
* var options = {
* const options = {
* timeframe: "1_hour",
* size: "xlarge",
* legend: "yes",
@ -49,7 +49,7 @@ function create(graphJSON, options, callback){
callback = options;
options = {};
}
var body = {
const body = {
graph_json: JSON.stringify(graphJSON)
};
// Use `extend` to merge `options` into `body`
@ -57,7 +57,7 @@ function create(graphJSON, options, callback){
extend(body, options || {});
// Create the request
var params = {
const params = {
body: querystring.stringify(body),
contentType: "application/x-www-form-urlencoded"
};
@ -72,7 +72,7 @@ function create(graphJSON, options, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var embedid = "foo";
* const embedid = "foo";
* dogapi.embed.revoke(embedid, function(err, res){
* console.dir(res);
* });
@ -105,7 +105,7 @@ function getAll(callback) {
* callback: function(err, res)
*example: |
* ```javascript
* var embedId = "foo";
* const embedId = "foo";
* dogapi.embed.get(embedId, function(err, res){
* console.dir(res);
* });
@ -147,8 +147,8 @@ module.exports = {
},
handleCli: function(subcommand, args, callback) {
if (args._.length > 4 && subcommand === "create") {
var graph_json = json.parse(args._[4]);
var options = {
const graph_json = json.parse(args._[4]);
const options = {
timeframe: args["timeframe"],
size: args["size"],
legend: args["legend"],
@ -156,10 +156,10 @@ module.exports = {
};
create(graph_json, options, callback);
} else if (args._.length > 4 && subcommand === "revoke") {
var embedId = args._[4];
const embedId = args._[4];
revoke(embedId, callback);
} else if (args._.length > 4 && subcommand === "get") {
var embedId = args._[4];
const embedId = args._[4];
get(embedId, callback);
} else if (subcommand === "getall") {
getAll(callback);


+ 22
- 22
lib/api/event.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var util = require("util");
const client = require("../client");
const util = require("util");
/*section: event
*comment: |
@ -20,20 +20,20 @@ var util = require("util");
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var title = "some new event";
* var text = "IT HAPPENED!";
* const title = "some new event";
* const text = "IT HAPPENED!";
* dogapi.event.create(title, text, function(err, res){
* console.dir(res);
* });
* title = "another event";
* text = "IT HAPPENED AGAIN!";
* var properties = {
* const properties = {
* tags: ["some:tag"],
* alert_type: "error"
* };
@ -54,7 +54,7 @@ function create(title, text, properties, callback){
properties.title = title;
properties.text = text;
var params = {
const params = {
body: properties
};
client.request("POST", "/events", params, callback);
@ -70,8 +70,8 @@ function create(title, text, properties, callback){
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -100,15 +100,15 @@ function get(eventId, callback){
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const 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 = {
* const now = parseInt(new Date().getTime() / 1000);
* const then = now - 3600; // an hour ago
* const parameters = {
* tags: "some:tag",
* sources: "jenkins"
* };
@ -129,7 +129,7 @@ function query(start, end, parameters, callback){
parameters.start = start;
parameters.end = end;
var params = {
const params = {
query: parameters
};
@ -169,9 +169,9 @@ module.exports = {
if(subcommand === "get" && args._.length > 4){
get(parseInt(args._[4]), callback);
} else if(subcommand === "query" && args._.length > 5){
var from = parseInt(args._[4]);
var to = parseInt(args._[5]);
var parameters = {};
const from = parseInt(args._[4]);
const to = parseInt(args._[5]);
const parameters = {};
if(args["sources"]){
parameters.sources = args["sources"];
}
@ -180,9 +180,9 @@ module.exports = {
}
query(from, to, parameters, callback);
} else if(subcommand === "create" && args._.length > 5){
var title = args._[4];
var text = args._[5];
var properties = {};
const title = args._[4];
const text = args._[5];
const properties = {};
if(args["priority"]){
properties.priority = args["priority"];
}


+ 12
- 12
lib/api/graph.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var embed = require("./embed");
const client = require("../client");
const embed = require("./embed");
/*section: graph
*comment: take a snapshot of a metric query
@ -11,15 +11,15 @@ var embed = require("./embed");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var query = "system.cpu.idle{*}";
* var to = dogapi.now();
* var from = to - 3600; // an hour ago
* const query = "system.cpu.idle{*}";
* const to = dogapi.now();
* const from = to - 3600; // an hour ago
* dogapi.graph.snapshot(query, from, to, function(err, res){
* console.dir(res);
* });
@ -30,7 +30,7 @@ function snapshot(query, from, to, eventQuery, callback){
callback = eventQuery;
eventQuery = undefined;
}
var params = {
const params = {
query: {
metric_query: query,
start: parseInt(from),
@ -63,10 +63,10 @@ module.exports = {
},
handleCli: function(subcommand, args, callback){
if (args._.length > 5 && subcommand === "snapshot"){
var query = args._[4];
var from = parseInt(args._[5]);
var to = parseInt(args._[6]);
var eventQuery = args["events"];
const query = args._[4];
const from = parseInt(args._[5]);
const to = parseInt(args._[6]);
const eventQuery = args["events"];
snapshot(query, from, to, eventQuery, callback);
} else {
callback("unknown subcommand or arguments try `dogapi graph --help` for help", false);


+ 11
- 11
lib/api/host.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var util = require("util");
const client = require("../client");
const util = require("util");
/*section: host
*comment: mute the given host, if it is not already muted
@ -12,8 +12,8 @@ var util = require("util");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -28,7 +28,7 @@ function mute(hostname, options, callback){
callback = options;
options = {};
}
var params = {};
const params = {};
if(typeof options === "object"){
params.body = {}; // create body property
if(options.end){
@ -50,8 +50,8 @@ function mute(hostname, options, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -62,7 +62,7 @@ function mute(hostname, options, callback){
* ```
*/
function unmute(hostname, callback){
var params = {body: ""}; // create empty body
const params = {body: ""}; // create empty body
client.request("POST", util.format("/host/%s/unmute", hostname), params, callback);
}
@ -89,8 +89,8 @@ module.exports = {
},
handleCli: function(subcommand, args, callback){
if(subcommand === "mute"){
var hostname = args._[4];
var options = {};
const hostname = args._[4];
const options = {};
if(args["end"]){
options.end = parseInt(args["end"]);
}
@ -99,7 +99,7 @@ module.exports = {
}
mute(hostname, options, callback);
} else if(subcommand === "unmute"){
var hostname = args._[4];
const hostname = args._[4];
unmute(hostname, callback);
} else {
callback("unknown subcommand or arguments try `dogapi host --help` for help", false);


+ 2
- 2
lib/api/index.js View File

@ -1,4 +1,4 @@
var api = {
const api = {
comment: require("./comment"),
downtime: require("./downtime"),
embed: require("./embed"),
@ -17,7 +17,7 @@ var api = {
};
module.exports = function(obj){
for(var key in api){
for(const key in api){
obj[key] = api[key];
}
};

+ 5
- 5
lib/api/infrastructure.js View File

@ -1,4 +1,4 @@
var client = require("../client");
const client = require("../client");
/*section: infrastructure
*comment: |
@ -10,8 +10,8 @@ var client = require("../client");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -22,7 +22,7 @@ var client = require("../client");
* ```
*/
function search(query, callback){
var params = {
const params = {
query: {
q: query
}
@ -46,7 +46,7 @@ module.exports = {
];
},
handleCli: function(subcommand, args, callback){
var query = args._[4];
const query = args._[4];
search(query, callback);
}
};

+ 24
- 24
lib/api/metric.js View File

@ -1,4 +1,4 @@
var client = require("../client");
const client = require("../client");
/*section: metric
*comment: |
@ -17,8 +17,8 @@ var client = require("../client");
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -29,7 +29,7 @@ var client = require("../client");
* dogapi.metric.send("my.metric", [500, 1000], function(err, results){
* console.dir(results);
* });
* var now = parseInt(new Date().getTime() / 1000);
* const now = parseInt(new Date().getTime() / 1000);
* dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){
* console.dir(results);
* });
@ -44,7 +44,7 @@ function send(metric, points, extra, callback){
extra = {};
}
extra = extra || {};
var series = [
const series = [
{
metric: metric,
points: points,
@ -73,14 +73,14 @@ function send(metric, points, extra, callback){
* function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var now = parseInt(new Date().getTime() / 1000);
* var metrics = [
* const now = parseInt(new Date().getTime() / 1000);
* const metrics = [
* {
* metric: "my.metric",
* points: [[now, 1000]],
@ -101,15 +101,15 @@ function send(metric, points, extra, callback){
* ```
*/
function send_all(metrics, callback){
var now = parseInt(new Date().getTime() / 1000);
for(var i = 0; i < metrics.length; ++i){
const now = parseInt(new Date().getTime() / 1000);
for(let i = 0; i < metrics.length; ++i){
// Try to normalize `points`
// DEV: We need `points` to be an array of arrays regardless of what they give us
// Always wrap points in an array, this way we will get:
// 500 => [500]
// [500, 100] => [[<timestamp>, 500], [<timestamp>, 1000]]
// [[<timestamp>, 500]] => [[<timestamp>, 500]]
var points = metrics[i].points;
let points = metrics[i].points;
if(!Array.isArray(metrics[i].points)){
points = [points];
}
@ -118,7 +118,7 @@ function send_all(metrics, callback){
// 500 => [<timestamp>, 500]
// [<timestamp>, 500] => unchanged
if(!Array.isArray(point)){
var now = parseInt(new Date().getTime() / 1000);
const now = parseInt(new Date().getTime() / 1000);
point = [now, point];
}
return point;
@ -133,7 +133,7 @@ function send_all(metrics, callback){
delete metrics[i].metric_type;
}
var params = {
const params = {
body: {
series: metrics
}
@ -151,22 +151,22 @@ function send_all(metrics, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const 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}";
* const now = parseInt(new Date().getTime() / 1000);
* const then = now - 3600; // one hour ago
* const query = "system.cpu.idle{*}by{host}";
* dogapi.metric.query(then, now, query, function(err, res){
* console.dir(res);
* });
* ```
*/
function query(from, to, query, callback){
var params = {
const params = {
query: {
from: from,
to: to,
@ -201,7 +201,7 @@ module.exports = {
},
handleCli: function(subcommand, args, callback){
if(args._.length > 5 && subcommand === "send"){
var extra = {};
const extra = {};
if(args.tags){
extra.tags = args.tags.split(",");
}
@ -209,9 +209,9 @@ module.exports = {
extra.type = args.type;
send(args._[4], args._[5], extra, callback);
} else if(subcommand === "query" && args._.length > 6){
var from = parseInt(args._[4]);
var to = parseInt(args._[5]);
var q = args._[6];
const from = parseInt(args._[4]);
const to = parseInt(args._[5]);
const q = args._[6];
query(from, to, q, callback);
} else {
callback("unknown subcommand or arguments try `dogapi metric --help` for help", false);


+ 46
- 46
lib/api/monitor.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var util = require("util");
const client = require("../client");
const util = require("util");
/*section: monitor
*comment: create a new monitor
@ -15,14 +15,14 @@ var util = require("util");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var metricType = "metric alert";
* var query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100";
* const metricType = "metric alert";
* const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100";
* dogapi.monitor.create(metricType, query, function(err, res){
* console.dir(res);
* });
@ -34,7 +34,7 @@ function create(type, query, properties, callback){
properties = {};
}
var params = {
const params = {
body: {
type: type,
query: query
@ -66,8 +66,8 @@ function create(type, query, properties, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -83,7 +83,7 @@ function get(monitorId, groupStates, callback){
groupStates = undefined;
}
var params = {};
const params = {};
if(groupStates){
params.query = {
group_states: groupStates.join(",")
@ -104,8 +104,8 @@ function get(monitorId, groupStates, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -120,7 +120,7 @@ function getAll(options, callback){
callback = options;
options = {};
}
var params = {};
const params = {};
if(typeof options === "object"){
params.query = {};
if(options.group_states){
@ -150,13 +150,13 @@ function getAll(options, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100";
* const query = "avg(last_1h):sum:system.net.bytes_rcvd{host:host0} > 100";
* dogapi.monitor.update(1234, query, function(err, res){
* console.dir(res);
* });
@ -168,7 +168,7 @@ function update(monitorId, query, properties, callback){
properties = {};
}
var params = {
const params = {
body: {
query: query
}
@ -198,8 +198,8 @@ function update(monitorId, query, properties, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -224,8 +224,8 @@ function remove(monitorId, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -240,7 +240,7 @@ function mute(monitorId, options, callback){
callback = options;
options = {};
}
var params = {};
const params = {};
if(typeof options === "object"){
params.body = {};
if(options.scope){
@ -261,8 +261,8 @@ function mute(monitorId, options, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -284,8 +284,8 @@ function muteAll(callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -300,7 +300,7 @@ function unmute(monitorId, scope, callback){
callback = scope;
scope = undefined;
}
var params = {};
const params = {};
if(scope){
params.body = {
scope: scope
@ -317,8 +317,8 @@ function unmute(monitorId, scope, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -379,24 +379,24 @@ module.exports = {
];
},
handleCli: function(subcommand, args, callback){
var states = [];
const states = [];
if(args["states"]){
states = args["states"].split(",");
}
var tags = [];
const tags = [];
if(args["tags"]){
tags = args["tags"].split(",");
}
var name = args["name"];
var message = args["message"];
const name = args["name"];
const message = args["message"];
if(subcommand === "get"){
var monitorId = args._[4];
const monitorId = args._[4];
get(monitorId, states, callback);
} else if(subcommand === "getall"){
var options = {};
const options = {};
if(states.length){
options.group_states = states;
}
@ -405,8 +405,8 @@ module.exports = {
}
getAll(options, callback);
} else if(subcommand === "mute"){
var monitorId = args._[4];
var options = {};
const monitorId = args._[4];
const options = {};
if(args["scope"]){
options.scope = args["scope"];
}
@ -415,20 +415,20 @@ module.exports = {
}
mute(monitorId, options, callback);
} else if(subcommand === "unmute"){
var monitorId = args._[4];
var scope = args["scope"];
const monitorId = args._[4];
const scope = args["scope"];
unmute(monitorId, scope, callback);
} else if(subcommand === "unmuteall"){
unmuteAll(callback);
} else if(subcommand === "muteall"){
muteAll(callback);
} else if(subcommand === "remove"){
var monitorId = args._[4];
const monitorId = args._[4];
remove(monitorId, callback);
} else if(subcommand === "create" && args._.length > 5){
var type = args._[4];
var query = args._[5];
var properties = {};
const type = args._[4];
const query = args._[5];
const properties = {};
if(name){
properties.name = name;
}
@ -437,9 +437,9 @@ module.exports = {
}
create(type, query, properties, callback);
} else if(subcommand === "update" && args._.length > 5){
var monitorId = args._[4];
var query = args._[5];
var properties = {};
const monitorId = args._[4];
const query = args._[5];
const properties = {};
if(name){
properties.name = name;
}


+ 30
- 30
lib/api/screenboard.js View File

@ -1,6 +1,6 @@
var client = require("../client");
var json = require("../json");
var util = require("util");
const client = require("../client");
const json = require("../json");
const util = require("util");
/*section: screenboard
@ -22,14 +22,14 @@ var util = require("util");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var boardTitle = "my screenboard";
* var widgets = [
* const boardTitle = "my screenboard";
* const widgets = [
* {
* type: "image",
* height: 20,
@ -39,7 +39,7 @@ var util = require("util");
* url: "https://path/to/image.jpg"
* }
* ];
* var options = {
* const options = {
* templateVariables: [
* {
* name: "host1",
@ -66,7 +66,7 @@ function create(boardTitle, widgets, options, callback){
options = {};
}
var params = {
const params = {
body: {
board_title: boardTitle,
widgets: widgets
@ -112,14 +112,14 @@ function create(boardTitle, widgets, options, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var boardTitle = "my screenboard";
* var widgets = [
* const boardTitle = "my screenboard";
* const widgets = [
* {
* type: "image",
* height: 20,
@ -129,7 +129,7 @@ function create(boardTitle, widgets, options, callback){
* url: "https://path/to/image.jpg"
* }
* ];
* var options = {
* const options = {
* description: "it is super awesome"
* };
* dogapi.screenboard.update(
@ -149,7 +149,7 @@ function update(boardId, boardTitle, widgets, options, callback) {
options = {};
}
var params = {
const params = {
body: {
board_title: boardTitle,
widgets: widgets
@ -182,8 +182,8 @@ function update(boardId, boardTitle, widgets, options, callback) {
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -204,8 +204,8 @@ function remove(boardId, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -225,8 +225,8 @@ function get(boardId, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -247,8 +247,8 @@ function getAll(callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -306,11 +306,11 @@ module.exports = {
} else if(subcommand === "share"){
share(args._[4], callback);
} else if (subcommand === "update"){
var boardId = args._[4];
var boardTitle = args._[5];
var widgets = json.parse(args._[6]);
const boardId = args._[4];
const boardTitle = args._[5];
const widgets = json.parse(args._[6]);
var options = {};
const options = {};
if(args["description"]) {
options.description = args["description"];
}
@ -326,10 +326,10 @@ module.exports = {
update(boardId, boardTitle, widgets, options, callback);
} else if(subcommand === "create"){
var boardTitle = args._[4];
var widgets = json.parse(args._[5]);
const boardTitle = args._[4];
const widgets = json.parse(args._[5]);
var options = {};
const options = {};
if(args["description"]) {
options.description = args["description"];
}


+ 5
- 5
lib/api/search.js View File

@ -1,4 +1,4 @@
var client = require("../client");
const client = require("../client");
/*section: search
*comment: |
@ -8,20 +8,20 @@ var client = require("../client");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var query = "app";
* const query = "app";
* dogapi.search.query(query, function(err, res){
* console.dir(res);
* });
* ```
*/
function query(query, callback){
var params = {
const params = {
query: {
q: query
}


+ 7
- 7
lib/api/serviceCheck.js View File

@ -1,4 +1,4 @@
var client = require("../client");
const client = require("../client");
/*section: serviceCheck
*comment: |
@ -15,14 +15,14 @@ var client = require("../client");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var check = "app.ok";
* var hostName = "some.machine";
* const check = "app.ok";
* const hostName = "some.machine";
* dogapi.serviceCheck.check(
* check, hostName, dogapi.WARNING, function(err, res){
* console.dir(res);
@ -43,7 +43,7 @@ function check(check, hostName, status, parameters, callback){
parameters.host_name = hostName,
parameters.status = status;
var params = {
const params = {
body: parameters
};
client.request("POST", "/check_run", params, callback);
@ -71,7 +71,7 @@ module.exports = {
},
handleCli: function(subcommand, args, callback){
if(args._.length > 6){
var parameters = {};
const parameters = {};
if(args["time"]){
parameters.time = parseInt(args["time"]);
}


+ 22
- 22
lib/api/tag.js View File

@ -1,5 +1,5 @@
var client = require("../client");
var util = require('util');
const client = require("../client");
const util = require('util');
/*section: tag
@ -12,8 +12,8 @@ var util = require('util');
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -29,7 +29,7 @@ function getAll(source, callback){
source = undefined;
}
var params = {
const params = {
query: {
source: source
}
@ -52,8 +52,8 @@ function getAll(source, callback){
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -70,7 +70,7 @@ function get(hostname, options, callback){
}
options = options || {};
var params = {
const params = {
query: {
}
};
@ -98,8 +98,8 @@ function get(hostname, options, callback){
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -115,7 +115,7 @@ function create(hostname, tags, source, callback){
source = undefined;
}
var params = {
const params = {
body: {
tags: tags,
source: source
@ -140,8 +140,8 @@ function create(hostname, tags, source, callback){
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -157,7 +157,7 @@ function update(hostname, tags, source, callback){
source = undefined;
}
var params = {
const params = {
body: {
tags: tags,
source: source
@ -178,8 +178,8 @@ function update(hostname, tags, source, callback){
* function callback(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -195,7 +195,7 @@ function remove(hostname, source, callback){
source = undefined;
}
var params = {
const params = {
query: {
source: source
}
@ -235,13 +235,13 @@ module.exports = {
];
},
handleCli: function(subcommand, args, callback){
var source = args["source"];
var host = args._[4];
const source = args["source"];
const host = args._[4];
if(subcommand === "getall"){
getAll(source, callback);
} else if(subcommand === "get"){
var options = {};
const options = {};
if(source){
options.source = source;
}
@ -250,10 +250,10 @@ module.exports = {
}
get(host, options, callback);
} else if(subcommand === "create"){
var tags = args._[5].split(",");
const tags = args._[5].split(",");
create(host, tags, source, callback);
} else if(subcommand === "update"){
var tags = args._[5].split(",");
const tags = args._[5].split(",");
update(host, tags, source, callback);
} else if(subcommand === "delete"){
remove(host, source, callback);


+ 32
- 32
lib/api/timeboard.js View File

@ -1,6 +1,6 @@
var client = require("../client");
var json = require("../json");
var util = require("util");
const client = require("../client");
const json = require("../json");
const util = require("util");
/*section: timeboard
*comment: add a new timeboard
@ -19,15 +19,15 @@ var util = require("util");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var title = "Time Keeps on Slipping";
* var description = "Into the Future";
* var graphs = [
* const title = "Time Keeps on Slipping";
* const description = "Into the Future";
* const graphs = [
* {
* definition: {
* events: [],
@ -39,7 +39,7 @@ var util = require("util");
* title: "Average Memory Free"
* }
* ];
* var templateVariables = [
* const templateVariables = [
* {
* name: "host1",
* prefix: "host",
@ -60,7 +60,7 @@ function create(title, description, graphs, templateVariables, callback){
templateVariables = [];
}
var params = {
const params = {
body: {
title: title,
description: description,
@ -92,15 +92,15 @@ function create(title, description, graphs, templateVariables, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var title = "Time Keeps on Slipping";
* var description = "Into the Future";
* var graphs = [
* const title = "Time Keeps on Slipping";
* const description = "Into the Future";
* const graphs = [
* {
* definition: {
* events: [],
@ -112,7 +112,7 @@ function create(title, description, graphs, templateVariables, callback){
* title: "Average Memory Free"
* }
* ];
* var templateVariables = [
* const templateVariables = [
* {
* name: "host1",
* prefix: "host",
@ -133,7 +133,7 @@ function update(dashId, title, description, graphs, templateVariables, callback)
templateVariables = [];
}
var params = {
const params = {
body: {
title: title,
description: description,
@ -154,8 +154,8 @@ function update(dashId, title, description, graphs, templateVariables, callback)
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -175,8 +175,8 @@ function remove(dashId, callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -197,8 +197,8 @@ function getAll(callback){
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
@ -248,21 +248,21 @@ module.exports = {
} else if(subcommand === "remove"){
remove(args._[4], callback);
} else if(subcommand === "create"){
var title = args._[4];
var description = args._[5];
var graphs = json.parse(args._[6]);
var templateVariables = [];
const title = args._[4];
const description = args._[5];
const graphs = json.parse(args._[6]);
const templateVariables = [];
if(args["tmpvars"]){
templateVariables = json.parse(args["tmpvars"]);
}
create(title, description, graphs, templateVariables, callback);
} else if(subcommand === "update"){
var dashId = parseInt(args._[4]);
var title = args._[5];
var description = args._[6];
var graphs = json.parse(args._[7]);
var templateVariables = [];
const dashId = parseInt(args._[4]);
const title = args._[5];
const description = args._[6];
const graphs = json.parse(args._[7]);
const templateVariables = [];
if(args["tmpvars"]){
templateVariables = json.parse(args["tmpvars"]);
}


+ 5
- 5
lib/api/user.js View File

@ -1,4 +1,4 @@
var client = require("../client");
const client = require("../client");
/*section: user
*comment: invite users via e-mail
@ -7,20 +7,20 @@ var client = require("../client");
* callback: function(err, res)
*example: |
* ```javascript
* var dogapi = require("dogapi");
* var options = {
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* var emails = ["me@domain.com", "you@domain.com"];
* const emails = ["me@domain.com", "you@domain.com"];
* dogapi.user.invite(emails, fuction(err, res){
* console.dir(res):
* });
* ```
*/
function invite(emails, callback){
var params = {
const params = {
body: {
emails: emails
}


+ 12
- 12
lib/client.js View File

@ -1,9 +1,9 @@
var extend = require("extend");
var https = require("https");
var json = require("./json");
var url = require("url");
var util = require("util");
var _ = require('lodash');
const https = require("https");
const url = require("url");
const util = require("util");
const extend = require("extend");
const _ = require('lodash');
const json = require("./json");
/*section: client
*comment: |
@ -52,8 +52,8 @@ client.prototype.request = function(method, path, params, callback){
params = {body: ''}; // create params with empty body property
}
var body = (typeof params["body"] === "object") ? json.stringify(params["body"]) : params["body"];
var query = {
const body = (typeof params["body"] === "object") ? json.stringify(params["body"]) : params["body"];
const query = {
"api_key": this.api_key,
"application_key": this.app_key,
};
@ -67,7 +67,7 @@ client.prototype.request = function(method, path, params, callback){
"query": query,
});
var http_options = _.assign({
const http_options = _.assign({
hostname: this.api_host,
port: 443,
method: method.toUpperCase(),
@ -85,20 +85,20 @@ client.prototype.request = function(method, path, params, callback){
};
}
var req = https.request(http_options, function(res){
const req = https.request(http_options, function(res){
res.on("error", function(err){
if(typeof callback == "function"){
callback(err, null, res.statusCode);
}
});
var data = "";
let data = "";
res.on("data", function(chunk){
data += chunk;
});
res.on("end", function(){
var error = null;
let error = null;
try{ data = json.parse(data); }catch(e){}
if(data["errors"]){
error = data["errors"];


Loading…
Cancel
Save