forked from plmwong/librato-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrato-cli-annotate-list
executable file
·37 lines (30 loc) · 1.24 KB
/
librato-cli-annotate-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
var config = require('./modules/librato-cli-config');
var client = require('./modules/librato-cli-client');
var flow = require('./modules/librato-cli-flow');
var program = require('commander');
program
.option('-t --type [annotation_type]', 'specifies the type of annotations to list (either \'alert\' or \'annotation\')')
.parse(process.argv);
var args = program.args;
if (program.type && program.type !== 'alert' && program.type !== 'annotation') {
program.outputHelp();
flow.error('--type/-t can only be set to either \'alert\' or \'annotation\'');
return;
}
var endPoint = config.baseUrl + 'v1/annotations';
client.get(endPoint, function (data, response) {
var annotations = data.annotations;
var filteredAnnotations = annotations.filter(function(annotation) {
if (!program.type) {
return true;
}
if (program.type === 'annotation') {
return !annotation.annotation_type;
}
if (program.type === 'alert') {
return annotation.annotation_type && annotation.annotation_type === 'alert';
}
});
console.log(JSON.stringify(filteredAnnotations, null, 2));
});