-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlibrato-cli-space-export
executable file
·67 lines (56 loc) · 1.88 KB
/
librato-cli-space-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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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>')
.parse(process.argv);
var args = program.args;
if (args.length < 1) {
flow.error('You must specify the id of the space you want to export');
return;
}
var removeConflictingCompositeMetrics = function(data) {
for(var i = 0; i < data.length; i++) {
if (data[i].streams) {
for(var j = 0; j < data[i].streams.length; j++) {
if (data[i].streams[j].metric && data[i].streams[j].composite) {
delete data[i].streams[j].metric;
delete data[i].streams[j].source;
delete data[i].streams[j].group_function;
}
}
}
}
return data;
};
var removeIds = function(data) {
for(var i = 0; i < data.length; i++) {
delete data[i].id;
if (data[i].streams) {
for(var j = 0; j < data[i].streams.length; j++) {
delete data[i].streams[j].id;
}
}
}
return data;
};
var exportCharts = function(spaceId, callback) {
var endPoint = config.baseUrl + 'v1/spaces/' + spaceId + '/charts';
client.get(endPoint, function (data, response) {
callback(data);
});
};
var exportSpace = function(spaceId) {
var spaceDefinition = { };
var endPoint = config.baseUrl + 'v1/spaces/' + spaceId;
client.get(endPoint, function (data, response) {
spaceDefinition = removeIds([ data ])[0];
exportCharts(spaceId, function(data) {
spaceDefinition.charts = removeConflictingCompositeMetrics(removeIds(data));
console.log(JSON.stringify(spaceDefinition, null, 2));
});
});
};
exportSpace(args[0]);