diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:07 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:07 +0000 |
commit | 732d7a2ea5ac46a4255da9194521b5120e8d34ec (patch) | |
tree | a65fbd55f24f51d2397da13cf3e90ba3f98a29d4 /public/js/module.js | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-statusmap-732d7a2ea5ac46a4255da9194521b5120e8d34ec.tar.xz icingaweb2-module-statusmap-732d7a2ea5ac46a4255da9194521b5120e8d34ec.zip |
Adding upstream version 20160720.upstream/20160720upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'public/js/module.js')
-rw-r--r-- | public/js/module.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/public/js/module.js b/public/js/module.js new file mode 100644 index 0000000..d5298d6 --- /dev/null +++ b/public/js/module.js @@ -0,0 +1,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)); |