-
Notifications
You must be signed in to change notification settings - Fork 4
/
librato-cli-chart-export
executable file
·47 lines (38 loc) · 1.44 KB
/
librato-cli-chart-export
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
38
39
40
41
42
43
44
45
46
47
#!/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
.usage('<space_id> <chart_id>')
.parse(process.argv);
var args = program.args;
if (args.length < 2) {
program.outputHelp();
flow.error('You must specify the both the id of the space and the id of the chart contained within it in order to export');
return;
}
var removeConflictingCompositeMetrics = function(chartDefinition) {
for(var i = 0; i < chartDefinition.streams.length; i++) {
if (chartDefinition.streams[i].metric && chartDefinition.streams[i].composite) {
delete chartDefinition.streams[i].metric;
delete chartDefinition.streams[i].source;
delete chartDefinition.streams[i].group_function;
}
}
return chartDefinition;
};
var removeIdsFromChart = function(chartDefinition) {
delete chartDefinition.id;
for(var i = 0; i < chartDefinition.streams.length; i++) {
delete chartDefinition.streams[i].id;
}
return chartDefinition;
};
var exportSpace = function(spaceId, chart) {
var endPoint = config.baseUrl + 'v1/spaces/' + spaceId + '/charts/' + chart;
client.get(endPoint, function(data, response) {
console.log(JSON.stringify(removeConflictingCompositeMetrics(removeIdsFromChart(data)), null, 2));
});
};
exportSpace(args[0], args[1]);