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
68
69
70
71
72
|
(function(Icinga) {
var StatusMap = function(module) {
/**
* The Icinga.Module instance
*/
this.module = module;
this.initialize();
};
StatusMap.prototype = {
initialize: function() {
this.module.on('rendered', this.createGraph);
this.module.icinga.logger.debug('StatusMap module loaded');
},
createGraph: function() {
var container = $('#yolocontainer');
var hosts_data = container.data('hosts');
var dependency_data = container.data('dependencies');
var node_data = [];
for (var i in hosts_data) {
host = hosts_data[i];
node_data.push({
id: host.host_name,
label: host.display_name,
color: this.stateToColor(host.state),
font: {
color: "#ffffff",
},
});
}
// create an array with nodes
var nodes = new vis.DataSet(node_data);
var edge_data = [];
for (var i in dependency_data) {
dependency = dependency_data[i];
edge_data.push({
from: dependency.parent,
to: dependency.child
});
}
// create an array with edges
var edges = new vis.DataSet(edge_data);
// create a network
var data = {
nodes: nodes,
edges: edges,
};
var options = {};
var network = new vis.Network(container.get(0), data, options);
},
stateToColor: function(state) {
switch(state) {
case 0: return '#44bb77'; // UP
case 1: return '#ff5566'; // DOWN
case 2: return '#aa44ff'; // UNREACHABLE
case 99: return '#77aaff'; // PENDING
}
return '#0095BF'; // icinga-blue
},
}
Icinga.availableModules.statusmap = StatusMap;
}(Icinga));
|