aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/js
diff options
context:
space:
mode:
Diffstat (limited to 'web/nms.gathering.org/js')
-rw-r--r--web/nms.gathering.org/js/nms-color-util.js3
-rw-r--r--web/nms.gathering.org/js/nms-data.js30
-rw-r--r--web/nms.gathering.org/js/nms-info-box.js949
-rw-r--r--web/nms.gathering.org/js/nms-map-handlers.js235
-rw-r--r--web/nms.gathering.org/js/nms-map.js178
-rw-r--r--web/nms.gathering.org/js/nms.js246
6 files changed, 1249 insertions, 392 deletions
diff --git a/web/nms.gathering.org/js/nms-color-util.js b/web/nms.gathering.org/js/nms-color-util.js
index f50ee04..6b5a4b5 100644
--- a/web/nms.gathering.org/js/nms-color-util.js
+++ b/web/nms.gathering.org/js/nms-color-util.js
@@ -89,6 +89,5 @@ function getColor(x,y) {
var data = imageData.data;
if (data.length < 4)
return false;
- var ret = 'rgb(' + data[0] + ',' + data[1] + ',' + data[2] + ')';
- return ret;
+ return 'rgb(' + data[0] + ',' + data[1] + ',' + data[2] + ')';
}
diff --git a/web/nms.gathering.org/js/nms-data.js b/web/nms.gathering.org/js/nms-data.js
index 155b5a8..14e5fed 100644
--- a/web/nms.gathering.org/js/nms-data.js
+++ b/web/nms.gathering.org/js/nms-data.js
@@ -82,7 +82,7 @@ var nmsData = nmsData || {
nmsData._dropData = function (name) {
delete this[name];
delete this.old[name];
-}
+};
nmsData.removeSource = function (name) {
if (this._sources[name] == undefined) {
@@ -94,7 +94,7 @@ nmsData.removeSource = function (name) {
clearInterval(this._sources[name]['handle']);
}
delete this._sources[name];
-}
+};
/*
* Register a source.
@@ -121,7 +121,7 @@ nmsData.registerSource = function(name, target) {
}
this.stats.pollSets++;
-}
+};
/*
* Add a handler (callback) for a source, using an id.
@@ -142,7 +142,7 @@ nmsData.addHandler = function(name, id, cb, cbdata) {
}
this._sources[name].cbs[id] = cbob;
this.updateSource(name);
-}
+};
/*
* Unregister all handlers with the "id" for all sources.
@@ -154,11 +154,11 @@ nmsData.unregisterHandlerWildcard = function(id) {
for (var v in nmsData._sources) {
this.unregisterHandler(v, id);
}
-}
+};
nmsData.unregisterHandler = function(name, id) {
delete this._sources[name].cbs[id];
-}
+};
/*
* Updates a source.
@@ -181,11 +181,11 @@ nmsData.updateSource = function(name) {
return;
}
this._genericUpdater(name, true);
-}
+};
nmsData.invalidate = function(name) {
this._genericUpdater(name, false);
-}
+};
/*
* Reset a source, deleting all data, including old.
*
@@ -195,7 +195,7 @@ nmsData.resetSource = function(name) {
this[name] = {};
this.old[name] = {};
this.updateSource(name);
-}
+};
/*
* Updates nmsData[name] and nmsData.old[name], issuing any callbacks where
@@ -236,16 +236,16 @@ nmsData._genericUpdater = function(name, cacheok) {
nmsData[name] = data;
nmsMap.drawNow();
for (var i in nmsData._sources[name].cbs) {
- var tmp = nmsData._sources[name].cbs[i];
- if (tmp.cb != undefined) {
- tmp.cb(tmp.cbdata);
+ var tmp2 = nmsData._sources[name].cbs[i];
+ if (tmp2.cb != undefined) {
+ tmp2.cb(tmp2.cbdata);
}
}
} else {
- for (var i in nmsData._sources[name].cbs) {
- var tmp = nmsData._sources[name].cbs[i];
+ for (var j in nmsData._sources[name].cbs) {
+ var tmp = nmsData._sources[name].cbs[j];
if (tmp.cb != undefined && tmp.fresh) {
- nmsData._sources[name].cbs[i].fresh = false;
+ nmsData._sources[name].cbs[j].fresh = false;
tmp.cb(tmp.cbdata);
}
}
diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js
index 6b13498..01bac94 100644
--- a/web/nms.gathering.org/js/nms-info-box.js
+++ b/web/nms.gathering.org/js/nms-info-box.js
@@ -1,71 +1,665 @@
"use strict";
/*
- * Handle the info-box for switches (e.g.: what's shown when a switch is
- * clicked).
+ * NMS info window controller
+ *
+ * Interface: nmsInfoBox.showWindow(windowType,optionalParameter), nmsInfoBox.hide(), nmsInfoBox.refresh()
+ *
+ * Any windowTypes should at a minimum implement load, update, unload, getTitle, getContent, getChildContent
*
- * Interfaces: show(switch), hide(), click(switch).
*/
-
var nmsInfoBox = nmsInfoBox || {
- stats: {},
- _showing:"" // Which switch we are displaying (if any).
-}
+ stats: {},
+ _container: false, //Container window
+ _window: false, //Active window (reference to _windowTypes object or false)
+ _windowTypes: [] //List of all avaliable window types
+};
/*
- * Show the infobox for a switch.
- *
- * Just a wrapper for _show, but adds a handler for comments. Could easily
- * add a handler for other events too. E.g.: switches.
+ * Shows a window from the _windowTypes list
*/
-nmsInfoBox.show = function(x) {
- nmsData.addHandler("comments","switchshower",nmsInfoBox._show,x);
- nmsData.addHandler("switches","switchshower",nmsInfoBox._show,x);
- nmsData.addHandler("smanagement","switchshower",nmsInfoBox._show,x);
- nmsInfoBox._show(x);
+nmsInfoBox.showWindow = function (windowName,argument) {
+ if(windowName == "switchInfo" && argument != '' && argument == this._window.sw) {
+ nmsInfoBox.hide();
+ return;
+ }
+ nmsInfoBox.hide();
+ for(var win in this._windowTypes) {
+ if(windowName == win) {
+ this._window = this._windowTypes[win];
+ this._show(argument);
+ return;
+ }
+ }
+};
+
+/*
+ * Refresh the active window
+ */
+nmsInfoBox.refresh = function(argument) {
+ if(!nmsInfoBox._window)
+ return;
+ nmsInfoBox._show(argument);
+};
+nmsInfoBox.update = function(argument) {
+ if(!nmsInfoBox._window)
+ return;
+ nmsInfoBox._window.update(argument);
}
/*
- * Hide switch info-box and remove handler.
+ * Internal function to show the active _window and pass along any arguments
+ */
+nmsInfoBox._show = function(argument) {
+ nmsData.addHandler("comments","switchshower",nmsInfoBox.update,'comments');
+ nmsData.addHandler("switches","switchshower",nmsInfoBox.update,'switches');
+ nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,'smanagement');
+ nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,'snmp');
+
+ if(argument != "soft")
+ this._window.load(argument);
+
+ this._container = document.getElementById("info-panel-container");
+ var panel = document.createElement("div");
+ panel.classList.add("panel", "panel-default");
+ var title = document.createElement("div");
+ title.classList.add("panel-heading");
+ var body = document.createElement("div");
+ body.classList.add("panel-body");
+
+ title.innerHTML = this._window.getTitle() + '<button type="button" class="close" aria-label="Close" onclick="nmsInfoBox.hide();" style="float: right;"><span aria-hidden="true">&times;</span></button>';
+ var content = this._window.getContent();
+ if(!content.nodeName) {
+ body.innerHTML = this._window.content;
+ } else {
+ body.appendChild(content);
+ }
+ var childContent = this._window.getChildContent();
+ if(childContent != false) {
+ body.appendChild(childContent);
+ }
+
+ panel.appendChild(title);
+ panel.appendChild(body);
+ while(this._container.firstChild) {
+ this._container.removeChild(this._container.firstChild);
+ }
+ this._container.appendChild(panel);
+ this._container.style.display = "block";
+ $('[data-toggle="popover"]').popover({placement:"top",container:'body'});
+ $(".collapse-controller").on("click", function(e) {
+ $(e.target.dataset.target).collapse('toggle');
+ });
+};
+
+/*
+ * Hide the active window and tell it to unload
*/
nmsInfoBox.hide = function() {
- nmsInfoBox._hide();
+ if(!this._container || !this._window)
+ return;
+ this._container.style.display = "none";
+ this._window.unload();
+ this._window = false;
nmsData.unregisterHandler("comments","switchshower");
nmsData.unregisterHandler("switches","switchshower");
nmsData.unregisterHandler("smanagement","switchshower");
-}
+ nmsData.unregisterHandler("snmp","switchshower");
+};
+
+/*
+ * Window type: Add Switch
+ *
+ * Basic window that lets you create a new switch
+ *
+ */
+nmsInfoBox._windowTypes.addSwitch = {
+ title: 'Add new switch',
+ content: '<input type="text" class="form-control" id="create-sysname" placeholder="Sysname id"><button class="btn btn-default" onclick="nmsInfoBox._windowTypes.addSwitch.save();">Add switch</button>',
+ childContent: false,
+ getTitle: function() {
+ return this.title;
+ },
+ getContent: function() {
+ return this.content;
+ },
+ getChildContent: function() {
+ return this.childContent;
+ },
+ load: function(argument) {
+ },
+ update: function(type) {
+ },
+ unload: function() {
+ },
+ save: function() {
+ var sysname = document.getElementById('create-sysname').value;
+ var myData = JSON.stringify([{'sysname':sysname}]);
+ $.ajax({
+ type: "POST",
+ url: "/api/write/switch-add",
+ dataType: "text",
+ data:myData,
+ success: function (data, textStatus, jqXHR) {
+ var result = JSON.parse(data);
+ if(result.switches_addded.length > 0) { // FIXME unresolved variable switches_addded
+ nmsInfoBox.hide();
+ }
+ nmsData.invalidate("switches");
+ nmsData.invalidate("smanagement");
+ }
+ });
+ }
+};
+
+/*
+ * Window type: Switch info
+ *
+ * Advanced window with information about a specific switch, and basic editing options
+ *
+ * Custom interfaces: showSummary, showInfoTable, showComments, showSNMP, showEdit, save
+ *
+ */
+nmsInfoBox._windowTypes.switchInfo = {
+ title: '',
+ content: '',
+ childContent: false,
+ sw: '',
+ swi: '',
+ swm: '',
+ commentsHash: false,
+ activeView: '',
+ load: function(sw) {
+ if(sw) {
+ this.sw = sw;
+ }
+ if(!this.swi) {
+ try {
+ this.swi = nmsData.switches["switches"][this.sw];
+ } catch(e) {
+ this.swi = [];
+ }
+ }
+ if(!this.swm) {
+ try {
+ this.swm = nmsData.smanagement.switches[this.sw];
+ } catch(e) {
+ this.swm = [];
+ }
+ }
+ nmsInfoBox._windowTypes.switchInfo.showSummary();
+ nmsData.addHandler("ticker","switchInfo",nmsInfoBox._windowTypes.switchInfo.update,"tick");
+ },
+ update: function(type) {
+ switch (type) {
+ case 'comments':
+ if(this.activeView == "summary" && this.commentsHash != nmsData.comments.hash) {
+ nmsInfoBox._windowTypes.switchInfo.showComments();
+ }
+ break;
+ }
+ },
+ getTitle: function() {
+ var sshButton = '';
+ try {
+ var mgmt = nmsInfoBox._window.swm.mgmt_v4_addr;
+ sshButton = mgmt.split("/")[0];
+ } catch(e) {}
+ if(sshButton != null && sshButton != undefined && sshButton != '') {
+ sshButton = ' <button type="button" class="ssh btn btn-xs btn-default"><a href="ssh://' + sshButton + '">SSH</a></button>';
+ }
+ return '<h4>' + this.sw + '</h4><button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._windowTypes.switchInfo.showEdit();">Edit</button> <button type="button" class="summary btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSummary();">Summary</button> <button type="button" class="details btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showInfoTable();">Details</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._windowTypes.switchInfo.showSNMP(\'misc\');">Misc</button>' + sshButton;
+ },
+ getContent: function() {
+ return this.content;
+ },
+ getChildContent: function() {
+ return this.childContent;
+ },
+ showSummary: function(argument) {
+ this.activeView = "summary";
+ var content = [];
+
+ //Get DHCP info
+ var lastDhcp = undefined;
+ try {
+ var tempDhcp = nmsData.dhcp.dhcp[this.sw];
+ var now = Date.now();
+ now = Math.floor(now / 1000);
+ tempDhcp = now - parseInt(tempDhcp);
+ tempDhcp = tempDhcp + " s";
+ } catch(e) {}
+
+ //Get SNMP status
+ var snmpStatus = undefined;
+ try {
+ if (nmsData.snmp.snmp[this.sw].misc.sysName[0] != sw) {
+ snmpStatus = "Sysname mismatch";
+ } else {
+ snmpStatus = "OK";
+ }
+ } catch(e) {}
+
+ //Get CPU usage
+ var cpuUsage = undefined;
+ try {
+ var cpu = 0;
+ for (var u in nmsData.snmp.snmp[this.sw].misc.jnxOperatingCPU) {
+ var local = nmsData.snmp.snmp[this.sw].misc['jnxOperatingCPU'][u];
+ cpu = Math.max(nmsData.snmp.snmp[this.sw].misc.jnxOperatingCPU[u],cpu);
+ }
+ cpuUsage = cpu + " %";
+ } catch (e) {}
+
+ //Get traffic data
+ var uplinkTraffic = undefined;
+ try {
+ var speed = 0;
+ var t = parseInt(nmsData.switchstate.then[this.sw].uplinks.ifHCOutOctets);
+ var n = parseInt(nmsData.switchstate.switches[this.sw].uplinks.ifHCOutOctets);
+ var tt = parseInt(nmsData.switchstate.then[this.sw].time);
+ var nt = parseInt(nmsData.switchstate.switches[this.sw].time);
+ var tdiff = nt - tt;
+ var diff = n - t;
+ speed = diff / tdiff;
+ if(!isNaN(speed)) {
+ uplinkTraffic = byteCount(speed*8,0);
+ }
+ } catch (e) {};
+
+ //Get uptime data
+ var uptime = "";
+ try {
+ uptime = nmsData.snmp.snmp[this.sw]["misc"]["sysUpTimeInstance"][""] / 60 / 60 / 100;
+ uptime = Math.floor(uptime) + " t";
+ } catch(e) {}
+
+ //Get temperature data
+ var temp = "";
+ try {
+ temp = nmsData.switchstate.switches[this.sw].temp + " °C";
+ } catch(e) {}
+
+ content.push(["Ping latency:",(nmsData.ping.switches[this.sw].latency + " ms" || undefined)]);
+ content.push(["Last DHCP lease:",lastDhcp]);
+ content.push(["SNMP status:",snmpStatus]);
+ content.push(["CPU usage:",cpuUsage]);
+ content.push(["Uplink traffic:",uplinkTraffic]);
+ content.push(["System uptime:",uptime]);
+ content.push(["Temperature",temp]);
+ content.push(["Management (v4):",(this.swm.mgmt_v4_addr || '')]);
+ content.push(["Management (v6):",(this.swm.mgmt_v6_addr || '')]);
+ content.push(["Subnet (v4):",(this.swm.subnet4 || '')]);
+ content.push(["Subnet (v6):",(this.swm.subnet6 || '')]);
+
+ var contentCleaned = [];
+ for(var i in content) {
+ if(content[i][1] == '' || content[i][1] == null)
+ continue;
+ if(content[i][1] == undefined || content[i][1])
+ content[i][1] == "No data";
+ contentCleaned.push(content[i]);
+ }
+
+ var table = nmsInfoBox._makeTable(contentCleaned);
+ table.id = this.sw + "-summary";
+
+ this.content = table;
+
+ if(argument == "tick") {
+ var myObj = document.getElementById(this.sw + "-summary");
+ var oldObj = myObj.parentNode.replaceChild(this.content,myObj);
+ return;
+ }
+
+ this.childContent = '';
+ nmsInfoBox._windowTypes.switchInfo.showComments();
+ nmsInfoBox.refresh("soft");
+ },
+ showInfoTable: function() {
+ this.activeView = "infotable";
+ var content = [];
+
+ for (var v in this.swi) {
+ if (v == "placement") {
+ var place = JSON.stringify(this.swi[v]);
+ content.push([v,place]);
+ continue;
+ }
+ content.push([v, this.swi[v]]);
+ }
+
+ for (var v in this.swm) {
+ content.push([v, this.swm[v]]);
+ }
+ content.sort();
+
+ var infotable = nmsInfoBox._makeTable(content);
+ infotable.id = "info-switch-table";
+
+ this.content = infotable;
+ this.childContent = '';
+ nmsInfoBox.refresh("soft");
+ },
+ update: function(type) {
+ switch (type) {
+ case 'comments':
+ if(nmsInfoBox._windowTypes.switchInfo.activeView == "summary" && this.commentsHash != nmsData.comments.hash) {
+ nmsInfoBox._windowTypes.switchInfo.showComments();
+ }
+ break;
+ case 'tick':
+ if(nmsInfoBox._windowTypes.switchInfo.activeView == "summary")
+ nmsInfoBox._windowTypes.switchInfo.showSummary("tick");
+ break;
+ }
+ },
+ showComments: function() {
+ var domObj = document.createElement("div");
+ var comments = [];
+
+ var commentbox = document.createElement("div");
+ commentbox.id = "commentbox";
+ commentbox.className = "panel-body";
+ commentbox.style.width = "100%";
+ commentbox.innerHTML = '<div class="input-group"><input type="text" class="form-control" placeholder="Comment" id="' + this.sw + '-comment"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="addComment(\'' + this.sw + '\',document.getElementById(\'' + this.sw + '-comment\').value); document.getElementById(\'' + this.sw + '-comment\').value = \'\'; document.getElementById(\'' + this.sw + '-comment\').placeholder = \'Comment added. Wait for next refresh.\';">Add comment</button></span></div>';
+
+ // If we have no switch data, so just show comment form
+ if(!nmsData.comments || !nmsData.comments.comments) {
+ this.commentsHash = false;
+
+ // We have data, refresh
+ } else if(nmsData.comments.comments[this.sw]) {
+ this.commentsHash = nmsData.comments.hash;
+ for (var c in nmsData.comments.comments[this.sw]["comments"]) {
+ var comment = nmsData.comments.comments[this.sw]["comments"][c];
+ if (comment["state"] == "active" || comment["state"] == "persist" || comment["state"] == "inactive") {
+ comments.push(comment);
+ }
+ }
+
+ if (comments.length > 0) {
+ var commenttable = nmsInfoBox._makeCommentTable(comments);
+ commenttable.id = "info-switch-comments-table";
+ domObj.appendChild(commenttable);
+ }
+
+ // We have no data for this switch, but its still correct
+ } else {
+ this.commentsHash = nmsData.comments.hash;
+ }
+
+ domObj.appendChild(commentbox);
+ this.childContent = domObj;
+ nmsInfoBox.refresh("soft");
+ },
+ showEdit: function() {
+ this.activeView = "edit";
+ var domObj = document.createElement("div");
+ var template = {};
+
+ nmsInfoBox._editValues = {};
+ var place;
+ for (var v in this.swi) {
+ if (v == "placement") {
+ place = JSON.stringify(this.swi[v]);
+ template[v] = place;
+ continue;
+ }
+ template[v] = nmsInfoBox._nullBlank(this.swi[v]);
+ }
+ for (var v in this.swm) {
+ template[v] = nmsInfoBox._nullBlank(this.swm[v]);
+ }
+ var content = [];
+ for (v in template) {
+ var tmpsw = '\'' + this.sw + '\'';
+ var tmpv = '\'' + v + '\'';
+ var tmphandler = '"nmsInfoBox._editChange(' + tmpsw + ',' + tmpv + ');"';
+ var html = "<input type=\"text\" class=\"form-control\" value='" + template[v] + "' id=\"edit-"+ this.sw + "-" + v + '" onchange=' + tmphandler + ' oninput=' + tmphandler + '/>';
+ content.push([v, html]);
+ }
+
+ content.sort();
+
+ var table = nmsInfoBox._makeTable(content, "edit");
+ domObj.appendChild(table);
+
+ var submit = document.createElement("button");
+ submit.innerHTML = "Save changes";
+ submit.classList.add("btn", "btn-primary");
+ submit.id = "edit-submit-" + this.sw;
+ submit.onclick = function(e) { nmsInfoBox._windowTypes.switchInfo.save(); };
+ domObj.appendChild(submit);
+
+ var output = document.createElement("output");
+ output.id = "edit-output";
+ domObj.appendChild(output);
+
+ if (place) {
+ var pval = document.getElementById("edit-" + this.sw + "-placement");
+ if (pval) {
+ pval.value = place;
+ }
+ }
+
+ this.content = domObj;
+ this.childContent = '';
+ nmsInfoBox.refresh("soft");
+ },
+ showSNMP: function(tree) {
+ this.activeView = "snmp";
+ var domObj = document.createElement("div");
+ domObj.classList.add("panel-group");
+
+ try {
+ var snmpJson = nmsData.snmp.snmp[this.sw][tree];
+ } catch(e) {
+ this.content = "(no recent data (yet)?)";
+ return;
+ }
+
+ /*
+ * This html-generation code seems unnecessary complex. Must be a
+ * cleaner way to do this. But not today.
+ */
+ for(var obj in snmpJson) {
+
+ var cleanObj = obj.replace(/\W+/g, "");
+
+ var groupObj = document.createElement("div");
+ groupObj.classList.add("panel","panel-default");
+ groupObj.innerHTML = '<a class="panel-heading collapse-controller" style="display:block;" role="button" data-toggle="collapse" href="#'+cleanObj+'-group">' + obj + '</a>';
+
+ var groupObjCollapse = document.createElement("div");
+ groupObjCollapse.id = cleanObj + "-group";
+ groupObjCollapse.classList.add("collapse");
+
+ var panelBodyObj = document.createElement("div");
+ panelBodyObj.classList.add("panel-body");
+
+ var tableObj = document.createElement("table");
+ tableObj.classList.add("table","table-condensed");
+
+ var tbody = document.createElement("tbody");
+
+ for(var prop in snmpJson[obj]) {
+ var propObj = document.createElement("tr");
+ propObj.innerHTML = '<td>' + prop + '</td><td>' + snmpJson[obj][prop] + '</td>';
+ tbody.appendChild(propObj);
+ }
+
+ tableObj.appendChild(tbody);
+ panelBodyObj.appendChild(tableObj);
+ groupObjCollapse.appendChild(panelBodyObj);
+ groupObj.appendChild(groupObjCollapse);
+ domObj.appendChild(groupObj);
+
+ }
+ this.content = domObj;
+ this.childContent = '';
+
+ nmsInfoBox.refresh("soft");
+ },
+ unload: function() {
+ this.title = '';
+ this.content = '';
+ this.childContent = false;
+ this.sw = '';
+ this.swi = '';
+ this.swm = '';
+ this.commentsHash = false;
+ this.activeView = '';
+ nmsData.unregisterHandler("ticker","switchInfo");
+ },
+ save: function() {
+ var myData = nmsInfoBox._editStringify(this.sw);
+ $.ajax({
+ type: "POST",
+ url: "/api/write/switch-update",
+ dataType: "text",
+ data:myData,
+ success: function (data, textStatus, jqXHR) {
+ var result = JSON.parse(data);
+ if(result.switches_updated.length > 0) { // FIXME unresolved variable switches_addded
+ nmsInfoBox.hide();
+ }
+ nmsData.invalidate("switches");
+ nmsData.invalidate("smanagement");
+ }
+ });
+ }
+};
+
+/*
+ * Window type: Show inventory listing
+ *
+ * Basic window that displays a list of all devices with simple summary information
+ *
+ * TODO: Set up more complex views with more columns, sorting, etc.
+ *
+ */
+nmsInfoBox._windowTypes.inventoryListing = {
+ content: '',
+ childContent: false,
+ activeView: '',
+ activeFilter: '',
+ getTitle: function() {
+ return '<h4>Inventory listing</h4><button type="button" class="distro-name btn btn-xs btn-default" onclick="nmsInfoBox.showWindow(\'inventoryListing\',\'distro_name\');">Distro name</button> <button type="button" class="distro-name btn btn-xs btn-default" onclick="nmsInfoBox.showWindow(\'inventoryListing\',\'sysDescr\');">System Description</button>';
+ },
+ getContent: function() {
+ return this.content;
+ },
+ getChildContent: function() {
+ return this.childContent;
+ },
+ setFilter: function(filter) {
+ this.activeFilter = filter.toLowerCase();
+ nmsInfoBox._windowTypes.inventoryListing.load("refresh");
+ },
+ getFilter: function() {
+ return this.activeFilter;
+ },
+ load: function(list) {
+ var hasSnmp = false;
+ var targetArray = [];
+ var listTitle = '';
+ var needRefresh = false;
+ var needSnmp = false;
+ var contentObj = document.createElement("div");
+ var inputObj = document.createElement("div");
+ inputObj.innerHTML = '<div class="input-group"><input type="text" class="form-control" placeholder="Filter" id="inventorylisting-filter" value="' + this.activeFilter + '" onkeyup="if (event.keyCode == 13) {nmsInfoBox._windowTypes.inventoryListing.setFilter(document.getElementById(\'inventorylisting-filter\').value);}"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="nmsInfoBox._windowTypes.inventoryListing.setFilter(document.getElementById(\'inventorylisting-filter\').value);">Filtrer</button></span></div>';
+ contentObj.appendChild(inputObj);
+
+
+ if(!nmsData.switches || !nmsData.switches.switches)
+ return;
+ if(!(!nmsData.snmp || !nmsData.snmp.snmp)) {
+ hasSnmp = true;
+ }
+ if(list == "refresh") {
+ list = this.activeView;
+ needRefresh = true;
+ }
+
+ switch (list) {
+ case 'distro_name':
+ listTitle = 'Distro names';
+ break;
+ case 'sysDescr':
+ if(hasSnmp)
+ listTitle = 'System description';
+ needSnmp = true;
+ break;
+ default:
+ listTitle = 'Distro names';
+ list = 'distro_name';
+ }
+ this.activeView = list;
+
+ if(needSnmp && !hasSnmp) {
+ this.content = "No SNMP data loaded. Reloading shortly.";
+ nmsData.addHandler("snmp","inventoryListing",nmsInfoBox._windowTypes.inventoryListing.update,"snmp-request");
+ return;
+ }
+
+ var resultArray = [];
+ for(var sw in nmsData.switches.switches) {
+ var value = '';
+ if(this.activeFilter != '') {
+ if(sw.toLowerCase().indexOf(this.activeFilter) == -1 && !nmsInfoBox._searchSmart(this.activeFilter,sw))
+ continue;
+ }
+ try {
+ switch (list) {
+ case 'distro_name':
+ value = nmsData.switches.switches[sw]["distro_name"];
+ break;
+ case 'sysDescr':
+ value = nmsData.snmp.snmp[sw]["misc"]["sysDescr"][0];
+ break;
+ }
+ } catch (e) {
+ //console.log(e);
+ }
+ resultArray.push([sw, value]);
+ }
+
+ resultArray.sort();
+
+ var infotable = nmsInfoBox._makeTable(resultArray,listTitle);
+ infotable.id = "inventory-table";
+
+ contentObj.appendChild(infotable);
+ this.content = contentObj;
+ if(needRefresh)
+ nmsInfoBox.refresh("soft");
+ },
+ update: function(type) {
+ if(type == "snmp-request") {
+ nmsData.unregisterHandler("snmp","inventoryListing");
+ nmsInfoBox._windowTypes.inventoryListing.load("refresh");
+ }
+ },
+ unload: function() {
+ nmsData.unregisterHandler("snmp","inventoryListing");
+ this.content = '';
+ this.activeView = '';
+ this.activeFilter = '';
+ },
+ save: function() {
+ }
+};
/*
- * Click a switch: If it's currently showing: hide it, otherwise display
+ * Click a switch and display it
* it.
*/
nmsInfoBox.click = function(sw)
{
- if (nmsInfoBox._showing == sw)
- nmsInfoBox.hide();
- else
- nmsInfoBox.show(sw);
-}
-
-nmsInfoBox._hide = function()
-{
- var swtop = document.getElementById("info-switch-parent");
- var switchele = document.getElementById("info-switch-table");
- var comments = document.getElementById("info-switch-comments-table");
- var commentbox;
- if (switchele != undefined)
- switchele.parentNode.removeChild(switchele);
- if (comments != undefined)
- comments.parentNode.removeChild(comments);
- commentbox = document.getElementById("commentbox");
- if (commentbox != undefined)
- commentbox.parentNode.removeChild(commentbox);
- swtop.style.display = 'none';
- nmsInfoBox._showing = "";
- nmsInfoBox._editHide();
- nmsInfoBox._snmpHide();
-}
+ this.showWindow("switchInfo",sw);
+};
/*
* General-purpose table-maker?
@@ -89,13 +683,14 @@ nmsInfoBox._makeTable = function(content, caption) {
}
for (var v in content) {
tr = table.insertRow(-1);
+ tr.className = content[v][0].toLowerCase();
td1 = tr.insertCell(0);
td2 = tr.insertCell(1);
td1.innerHTML = content[v][0];
td2.innerHTML = content[v][1];
}
return table;
-}
+};
/*
* Create and return a table for comments.
@@ -138,7 +733,65 @@ nmsInfoBox._makeCommentTable = function(content) {
td2.innerHTML = comment["comment"];
}
return table;
-}
+};
+
+nmsInfoBox._searchSmart = function(id, sw) {
+ try {
+ try {
+ if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) {
+ return true;
+ }
+ } catch (e) {}
+ try {
+ if (id.match("active")) {
+ var limit = id;
+ limit = limit.replace("active>","");
+ limit = limit.replace("active<","");
+ limit = limit.replace("active=","");
+ var operator = id.replace("active","")[0];
+ if (limit == parseInt(limit)) {
+ var ports = parseInt(nmsData.switchstate.switches[sw].ifs.ge.live);
+ limit = parseInt(limit);
+ if (operator == ">" ) {
+ if (ports > limit) {
+ return true;
+ }
+ } else if (operator == "<") {
+ if (ports < limit) {
+ return true;
+ }
+ } else if (operator == "=") {
+ if (ports == limit) {
+ return true;
+ }
+ }
+ }
+ }
+ } catch (e) {}
+ try {
+ if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) {
+ return true;
+ }
+ if (nmsData.smanagement.switches[sw].mgmt_v6_addr.match(id)) {
+ return true;
+ }
+ } catch (e) {}
+ try {
+ if (nmsData.smanagement.switches[sw].subnet4.match(id)) {
+ return true;
+ }
+ if (nmsData.smanagement.switches[sw].subnet6.match(id)) {
+ return true;
+ }
+ } catch (e) {}
+ if (nmsData.snmp.snmp[sw].misc.sysDescr[0].toLowerCase().match(id)) {
+ return true;
+ }
+ } catch (e) {
+ return false;
+ }
+ return false;
+};
/*
* FIXME: Not sure this belongs here, it's really part of the "Core" ui,
@@ -147,174 +800,58 @@ nmsInfoBox._makeCommentTable = function(content) {
nmsInfoBox._search = function() {
var el = document.getElementById("searchbox");
var id = false;
- var hits = 0;
+ var matches = [];
if (el) {
- id = el.value;
+ id = el.value.toLowerCase();
}
if(id) {
+ nmsMap.enableHighlights();
for(var sw in nmsData.switches.switches) {
- if(sw.indexOf(id) > -1) {
- hits++;
+ if(sw.toLowerCase().indexOf(id) > -1) {
+ matches.push(sw);
+ nmsMap.setSwitchHighlight(sw,true);
+ } else if (nmsInfoBox._searchSmart(id,sw)) {
+ matches.push(sw);
nmsMap.setSwitchHighlight(sw,true);
} else {
nmsMap.setSwitchHighlight(sw,false);
}
}
} else {
- nmsMap.removeAllSwitchHighlights();
- }
-}
-
-nmsInfoBox._snmp = function(x,tree)
-{
-
- nmsInfoBox._snmpHide();
- var container = document.createElement("div");
- container.id = "nmsInfoBox-snmp-show";
-
- var swtop = document.getElementById("info-switch-parent");
- var output = document.createElement("output");
- output.id = "edit-output";
- output.style = "white-space: pre;";
- try {
- output.value = JSON.stringify(nmsData.snmp.snmp[x][tree],null,4);
- } catch(e) {
- output.value = "(no recent data (yet)?)";
+ nmsMap.disableHighlights();
}
- container.appendChild(output);
- swtop.appendChild(container);
-}
-/*
- * Display info on switch "x" in the info-box
- *
- * Use nmsInfoBox.show(), otherwise changes wont be picked up.
- */
-nmsInfoBox._show = function(x)
-{
- var sw = nmsData.switches["switches"][x];
- var swm = nmsData.smanagement.switches[x];
- var swtop = document.getElementById("info-switch-parent");
- var swpanel = document.getElementById("info-switch-panel-body");
- var swtitle = document.getElementById("info-switch-title");
- var content = [];
-
-
- nmsInfoBox._hide();
- nmsInfoBox._showing = x;
-
- swtitle.innerHTML = ' <button type="button" class="edit btn btn-xs btn-warning" onclick="nmsInfoBox._edit(\'' + x + '\');">Edit</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._snmp(\'' + x + '\',\'ports\');">Ports</button> <button type="button" class="edit btn btn-xs btn-default" onclick="nmsInfoBox._snmp(\'' + x + '\',\'misc\');">Misc</button> ' + x + ' <button type="button" class="close" aria-label="Close" onclick="nmsInfoBox.hide();" style="float: right;"><span aria-hidden="true">&times;</span></button>';
-
- for (var v in sw) {
- if (v == "placement") {
- var place = JSON.stringify(sw[v]);
- content.push([v,place]);
- continue;
- }
- content.push([v, sw[v]]);
+ if(matches.length == 1) {
+ document.getElementById("searchbox-submit").classList.add("btn-primary");
+ document.getElementById("searchbox").dataset.match = matches[0];
+ } else {
+ document.getElementById("searchbox-submit").classList.remove("btn-primary");
+ document.getElementById("searchbox").dataset.match = '';
}
+};
- for (var v in swm) {
- content.push([v, swm[v]]);
- }
- content.sort();
-
- var comments = [];
- if (nmsData.comments.comments != undefined && nmsData.comments.comments[x] != undefined) {
- for (var c in nmsData.comments.comments[x]["comments"]) {
- var comment = nmsData.comments.comments[x]["comments"][c];
- if (comment["state"] == "active" || comment["state"] == "persist" || comment["state"] == "inactive") {
- comments.push(comment);
+nmsInfoBox._searchKeyListener = function(e) {
+ switch (e.keyCode) {
+ case 13:
+ var sw = document.getElementById("searchbox").dataset.match;
+ if(sw != '') {
+ nmsInfoBox.showWindow("switchInfo",sw);
}
- }
+ break;
+ case 27:
+ document.getElementById("searchbox").dataset.match = '';
+ document.getElementById("searchbox").value = '';
+ nmsInfoBox._search();
+ nmsInfoBox.hide();
+ break;
}
-
- var infotable = nmsInfoBox._makeTable(content);
- infotable.id = "info-switch-table";
- swtop.appendChild(infotable);
- if (comments.length > 0) {
- var commenttable = nmsInfoBox._makeCommentTable(comments);
- commenttable.id = "info-switch-comments-table";
- swtop.appendChild(commenttable);
- $(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) })
- }
- var commentbox = document.createElement("div");
- commentbox.id = "commentbox";
- commentbox.className = "panel-body";
- commentbox.style.width = "100%";
- commentbox.innerHTML = '<div class="input-group"><input type="text" class="form-control" placeholder="Comment" id="' + x + '-comment"><span class=\"input-group-btn\"><button class="btn btn-default" onclick="addComment(\'' + x + '\',document.getElementById(\'' + x + '-comment\').value); document.getElementById(\'' + x + '-comment\').value = \'\'; document.getElementById(\'' + x + '-comment\').placeholder = \'Comment added. Wait for next refresh.\';">Add comment</button></span></div>';
- swtop.appendChild(commentbox);
- swtop.style.display = 'block';
-}
+};
nmsInfoBox._nullBlank = function(x) {
if (x == null || x == false || x == undefined)
return "";
return x;
-}
+};
-nmsInfoBox._editHide = function() {
- var container = document.getElementById("nmsInfoBox-edit-box");
- if (container != undefined)
- container.parentNode.removeChild(container);
-}
-nmsInfoBox._snmpHide = function() {
- var container = document.getElementById("nmsInfoBox-snmp-show");
- if (container != undefined)
- container.parentNode.removeChild(container);
-}
-
-nmsInfoBox._edit = function(sw) {
- var template = {};
- var place = false;
- nmsInfoBox._editHide();
- nmsInfoBox._snmpHide();
- var container = document.createElement("div");
- container.id = "nmsInfoBox-edit-box";
-
- nmsInfoBox._editValues = {};
- if (nmsData.switches.switches[sw] != undefined) {
- for (var v in nmsData.switches.switches[sw]) {
- if (v == "placement") {
- place = JSON.stringify(nmsData.switches.switches[sw][v]);
- template[v] = "";
- continue;
- }
- template[v] = this._nullBlank(nmsData.switches.switches[sw][v]);
- }
- }
- if (nmsData.smanagement.switches[sw] != undefined) {
- for (var v in nmsData.smanagement.switches[sw]) {
- template[v] = this._nullBlank(nmsData.smanagement.switches[sw][v]);
- }
- }
- var content = [];
- for (v in template) {
- var tmpsw = '\'' + sw + '\'';
- var tmpv = '\'' + v + '\'';
- var tmphandler = '"nmsInfoBox._editChange(' + tmpsw + ',' + tmpv + ');"';
- var html = "<input type=\"text\" class=\"form-control\" value=\"" + template[v] + "\" id=\"edit-"+ sw + "-" + v + '" onchange=' + tmphandler + ' oninput=' + tmphandler + '/>';
- content.push([v, html]);
- }
- var table = nmsInfoBox._makeTable(content, "edit");
- var swtop = document.getElementById("info-switch-parent");
- container.appendChild(table);
- var submit = document.createElement("button");
- submit.innerHTML = "Save changes";
- submit.classList.add("btn", "btn-primary");
- submit.id = "edit-submit-" + sw;
- submit.onclick = function(e) { nmsInfoBox._editSave(sw, e); };
- container.appendChild(submit);
- var output = document.createElement("output");
- output.id = "edit-output";
- container.appendChild(output);
- swtop.appendChild(container);
- if (place) {
- var pval = document.getElementById("edit-" + sw + "-placement");
- if (pval) {
- pval.value = place;
- }
- }
-}
nmsInfoBox._editChange = function(sw, v) {
var el = document.getElementById("edit-" + sw + "-" + v);
@@ -334,27 +871,9 @@ nmsInfoBox._editChange = function(sw, v) {
var myData = nmsInfoBox._editStringify(sw);
var out = document.getElementById("edit-output");
out.value = myData;
-}
+};
nmsInfoBox._editStringify = function(sw) {
- for (var key in nmsInfoBox._editValues) {
- var val = nmsInfoBox._editValues[key];
- }
- nmsInfoBox._editValues['sysname'] = sw;
- var myData = JSON.stringify([nmsInfoBox._editValues]);
- return myData;
-}
-nmsInfoBox._editSave = function(sw, e) {
- var myData = nmsInfoBox._editStringify(sw);
- $.ajax({
- type: "POST",
- url: "/api/private/switch-add",
- dataType: "text",
- data:myData,
- success: function (data, textStatus, jqXHR) {
- nmsData.invalidate("switches");
- nmsData.invalidate("smanagement");
- }
- });
- nmsInfoBox._editHide();
-}
+ nmsInfoBox._editValues['sysname'] = sw;
+ return JSON.stringify([nmsInfoBox._editValues]);
+};
diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js
index fa33bad..474e8ef 100644
--- a/web/nms.gathering.org/js/nms-map-handlers.js
+++ b/web/nms.gathering.org/js/nms-map-handlers.js
@@ -49,6 +49,12 @@ var handler_traffic_tot = {
name:"Switch traffic map"
};
+var handler_dhcp = {
+ init:dhcpInit,
+ tag:"dhcp",
+ name:"DHCP map"
+};
+
var handler_disco = {
init:discoInit,
tag:"disco",
@@ -61,6 +67,18 @@ var handler_comment = {
name:"Fresh comment spotter"
};
+var handler_snmp = {
+ init:snmpInit,
+ tag:"snmp",
+ name:"SNMP state"
+};
+
+var handler_cpu = {
+ init:cpuInit,
+ tag:"cpu",
+ name:"CPU utilization"
+};
+
var handlers = [
handler_uplinks,
handler_temp,
@@ -68,7 +86,10 @@ var handlers = [
handler_traffic,
handler_disco,
handler_comment,
- handler_traffic_tot
+ handler_traffic_tot,
+ handler_dhcp,
+ handler_snmp,
+ handler_cpu
];
/*
@@ -84,7 +105,7 @@ function uplinkUpdater()
return;
if (!nmsData.switchstate.switches)
return;
- for (sw in nmsData.switches.switches) {
+ for (var sw in nmsData.switches.switches) {
var uplinks=0;
if (nmsData.switchstate.switches[sw] == undefined || nmsData.switchstate.switches[sw].uplinks == undefined) {
uplinks=0;
@@ -95,12 +116,12 @@ function uplinkUpdater()
if (uplinks == 0) {
nmsMap.setSwitchColor(sw,"white");
- } else if (nuplinks == uplinks) {
- nmsMap.setSwitchColor(sw,green);
- } else if (nuplinks - uplinks == 1) {
- nmsMap.setSwitchColor(sw, orange);
- } else if (nuplinks - uplinks == 2) {
+ } else if (uplinks == 1) {
nmsMap. setSwitchColor(sw, red);
+ } else if (uplinks == 2) {
+ nmsMap.setSwitchColor(sw, orange);
+ } else if (uplinks == 3) {
+ nmsMap.setSwitchColor(sw,green);
} else if (uplinks > 3) {
nmsMap.setSwitchColor(sw, blue);
}
@@ -115,9 +136,9 @@ function uplinkInit()
nmsData.addHandler("switches","mapHandler",uplinkUpdater);
nmsData.addHandler("switchstate","mapHandler",uplinkUpdater);
setLegend(1,"white","0 uplinks");
- setLegend(2,red,"2 missing");
- setLegend(3,orange,"1 missing");
- setLegend(4,green,"0 missing");
+ setLegend(2,red,"1 uplink");
+ setLegend(3,orange,"2 uplinks");
+ setLegend(4,green,"3 uplinks");
setLegend(5,blue,"4 uplinks");
}
@@ -126,44 +147,43 @@ function uplinkInit()
*/
function trafficInit()
{
+ nmsData.addHandler("switches","mapHandler",trafficUpdater);
+ nmsData.addHandler("switchstate","mapHandler",trafficUpdater);
var m = 1024 * 1024 / 8;
drawGradient([lightgreen,green,orange,red]);
setLegend(1,colorFromSpeed(0),"0 (N/A)");
- setLegend(5,colorFromSpeed(2000 * m) , "2000Mb/s");
- setLegend(4,colorFromSpeed(1500 * m),"1500Mb/s");
- setLegend(3,colorFromSpeed(500 * m),"500Mb/s");
+ setLegend(5,colorFromSpeed(1100 * m) , "1100Mb/s");
+ setLegend(4,colorFromSpeed(600 * m),"600Mb/s");
+ setLegend(3,colorFromSpeed(300 * m),"300Mb/s");
setLegend(2,colorFromSpeed(10 * m),"10Mb/s");
}
function trafficUpdater()
{
- if (!nms.switches_now["switches"])
+ if (!nmsData.switchstate.switches || !nmsData.switchstate.then)
return;
- for (sw in nms.switches_now["switches"]) {
+ for (var sw in nmsData.switchstate.switches) {
var speed = 0;
- for (port in nms.switches_now["switches"][sw]["ports"]) {
- if (/ge-0\/0\/44$/.exec(port) ||
- /ge-0\/0\/45$/.exec(port) ||
- /ge-0\/0\/46$/.exec(port) ||
- /ge-0\/0\/47$/.exec(port))
- {
- if (!nms.switches_then["switches"][sw] ||
- !nms.switches_then["switches"][sw]["ports"] ||
- !nms.switches_then["switches"][sw]["ports"][port])
- continue;
- var t = nms.switches_then["switches"][sw]["ports"][port];
- var n = nms.switches_now["switches"][sw]["ports"][port];
- speed += (parseInt(t["ifhcoutoctets"]) -parseInt(n["ifhcoutoctets"])) / (parseInt(t["time"] - n["time"]));
- speed += (parseInt(t["ifhcinoctets"]) -parseInt(n["ifhcinoctets"])) / (parseInt(t["time"] - n["time"]));
- }
+ try {
+ var t = parseInt(nmsData.switchstate.then[sw].uplinks.ifHCOutOctets);
+ var n = parseInt(nmsData.switchstate.switches[sw].uplinks.ifHCOutOctets);
+ var tt = parseInt(nmsData.switchstate.then[sw].time);
+ var nt = parseInt(nmsData.switchstate.switches[sw].time);
+ } catch (e) { continue;};
+ var tdiff = nt - tt;
+ var diff = n - t;
+ speed = diff / tdiff;
+ if(!isNaN(speed)) {
+ nmsMap.setSwitchColor(sw,colorFromSpeed(speed));
+ nmsMap.setSwitchInfo(sw,byteCount(speed*8,0));
}
- if(!isNaN(speed))
- setSwitchColor(sw,colorFromSpeed(speed));
}
}
function trafficTotInit()
{
+ nmsData.addHandler("switches","mapHandler",trafficTotUpdater);
+ nmsData.addHandler("switchstate","mapHandler",trafficTotUpdater);
var m = 1024 * 1024 / 8;
drawGradient([lightgreen,green,orange,red]);
setLegend(1,colorFromSpeed(0),"0 (N/A)");
@@ -175,20 +195,21 @@ function trafficTotInit()
function trafficTotUpdater()
{
- if (!nms.switches_now["switches"])
+ if (!nmsData.switchstate.switches || !nmsData.switchstate.then)
return;
- for (sw in nms.switches_now["switches"]) {
+ for (var sw in nmsData.switchstate.switches) {
var speed = 0;
- for (port in nms.switches_now["switches"][sw]["ports"]) {
- if (!nms.switches_then["switches"][sw] ||
- !nms.switches_then["switches"][sw]["ports"] ||
- !nms.switches_then["switches"][sw]["ports"][port])
- continue;
- var t = nms.switches_then["switches"][sw]["ports"][port];
- var n = nms.switches_now["switches"][sw]["ports"][port];
- speed += (parseInt(t["ifhcoutoctets"]) -parseInt(n["ifhcoutoctets"])) / (parseInt(t["time"] - n["time"]));
- }
- setSwitchColor(sw,colorFromSpeed(speed,5));
+ try {
+ var t = parseInt(nmsData.switchstate.then[sw].totals.ifHCOutOctets);
+ var n = parseInt(nmsData.switchstate.switches[sw].totals.ifHCOutOctets);
+ var tt = parseInt(nmsData.switchstate.then[sw].time);
+ var nt = parseInt(nmsData.switchstate.switches[sw].time);
+ } catch (e) { continue;};
+ var tdiff = nt - tt;
+ var diff = n - t;
+ speed = diff / tdiff;
+ if(!isNaN(speed))
+ nmsMap.setSwitchColor(sw,colorFromSpeed(speed));
}
}
@@ -196,14 +217,13 @@ function colorFromSpeed(speed,factor)
{
var m = 1024 * 1024 / 8;
if (factor == undefined)
- factor = 2;
+ factor = 1.1;
if (speed == 0)
return blue;
speed = speed < 0 ? 0 : speed;
return getColorStop( 1000 * (speed / (factor * (1000 * m))));
}
-
/*
* Tweaked this to scale from roughly 20C to 35C. Hence the -20 and /15
* thing (e.g., "0" is 20 and "15" is 35 by the time we pass it to
@@ -222,27 +242,35 @@ function temp_color(t)
function tempUpdater()
{
- for (sw in nms.switches_now["switches"]) {
+ if(!nmsData.switches)
+ return;
+
+ for ( var sw in nmsData.switches["switches"]) {
var t = "white";
var temp = "";
- if (nms.switches_now["switches"][sw]["temp"]) {
- t = temp_color(nms.switches_now["switches"][sw]["temp"]);
- temp = nms.switches_now["switches"][sw]["temp"] + "°C";
- }
- setSwitchColor(sw, t);
- switchInfoText(sw, temp);
+ if(!nmsData.switchstate || !nmsData.switchstate.switches || !nmsData.switchstate.switches[sw] || !nmsData.switchstate.switches[sw].temp)
+ continue;
+
+ var t = nmsData.switchstate.switches[sw].temp;
+ temp = t + "°C";
+ t = temp_color(temp);
+ nmsMap.setSwitchColor(sw, t);
+ nmsMap.setSwitchInfo(sw, temp);
+
}
}
function tempInit()
-{
+{
+ //Padded the gradient with extra colors for the upper unused values
drawGradient(["black",blue,lightblue,lightgreen,green,orange,red]);
setLegend(1,temp_color(15),"15 °C");
setLegend(2,temp_color(20),"20 °C");
setLegend(3,temp_color(25),"25 °C");
setLegend(4,temp_color(30),"30 °C");
setLegend(5,temp_color(35),"35 °C");
+ nmsData.addHandler("switchstate","mapHandler",tempUpdater);
}
function pingUpdater()
@@ -252,6 +280,7 @@ function pingUpdater()
}
for (var sw in nmsData.switches.switches) {
try {
+ var c;
if (nmsData.ping.switches[sw].age > 0) {
c = red;
} else {
@@ -284,6 +313,8 @@ function commentUpdater()
if (nmsData.comments == undefined || nmsData.comments.comments == undefined) {
return
}
+ if(!nmsData.switches)
+ return;
for (var sw in nmsData.switches.switches) {
var c = "white";
if (nmsData.comments.comments[sw] == undefined) {
@@ -329,6 +360,55 @@ function commentInit()
setLegend(5,green ,"Old/inactive only");
}
+function getDhcpColor(stop)
+{
+ stop = parseInt(stop);
+ stop = stop * 0.85;
+ if (stop < 0)
+ stop = 1000;
+ if (stop > 1000)
+ stop = 1000;
+ return getColorStop(stop);
+}
+
+function dhcpUpdater()
+{
+ var realnow = Date.now();
+ var now = Math.floor(realnow / 1000);
+ if (nmsData.dhcp == undefined || nmsData.dhcp.dhcp == undefined) {
+ return
+ }
+ if (nmsData.switches == undefined || nmsData.switches.switches == undefined) {
+ return;
+ }
+ try {
+ for (var sw in nmsData.switches.switches) {
+ var c = blue;
+ if (nmsData.dhcp.dhcp[sw] == undefined) {
+ nmsMap.setSwitchColor(sw,c);
+ continue;
+ }
+ var s = nmsData.dhcp.dhcp[sw];
+ var then = parseInt(s);
+ c = getDhcpColor(now - then);
+ nmsMap.setSwitchColor(sw, c);
+ }
+ } catch(e) {
+ console.log(e);
+ }
+}
+
+function dhcpInit()
+{
+ drawGradient([green,lightgreen,orange,red]);
+ nmsData.addHandler("dhcp","mapHandler",dhcpUpdater);
+ setLegend(1,"white","Undefined");
+ setLegend(2,getDhcpColor(1),"1 Second old");
+ setLegend(3,getDhcpColor(300),"300 Seconds old");
+ setLegend(4,getDhcpColor(900),"900 Seconds old");
+ setLegend(5,getDhcpColor(1200),"1200 Seconds old");
+}
+
/*
* Testing-function to randomize colors of linknets and switches
*/
@@ -362,3 +442,50 @@ function discoInit()
setLegend(5,"white","!");
}
+function snmpUpdater() {
+ for (var sw in nmsData.switches.switches) {
+ if (nmsData.snmp.snmp[sw] == undefined || nmsData.snmp.snmp[sw].misc == undefined) {
+ nmsMap.setSwitchColor(sw, red);
+ } else if (nmsData.snmp.snmp[sw].misc.sysName[0] != sw) {
+ nmsMap.setSwitchColor(sw, orange);
+ } else {
+ nmsMap.setSwitchColor(sw, green);
+ }
+ }
+}
+function snmpInit() {
+ nmsData.addHandler("snmp", "mapHandler", snmpUpdater);
+
+ setLegend(1,green,"OK");
+ setLegend(2,orange, "Sysname mismatch");
+ setLegend(3,red,"No SNMP data");
+ setLegend(4,green, "");
+ setLegend(5,green,"");
+
+}
+function cpuUpdater() {
+ for (var sw in nmsData.switches.switches) {
+ try {
+ var cpu = 0;
+ for (var u in nmsData.snmp.snmp[sw].misc.jnxOperatingCPU) {
+ var local = nmsData.snmp.snmp[sw].misc['jnxOperatingCPU'][u];
+ cpu = Math.max(nmsData.snmp.snmp[sw].misc.jnxOperatingCPU[u],cpu);
+ }
+ nmsMap.setSwitchColor(sw, getColorStop(cpu * 10));
+ nmsMap.setSwitchInfo(sw, cpu + " % ");
+ } catch (e) {
+ nmsMap.setSwitchColor(sw, "white");
+ nmsMap.setSwitchInfo(sw, "N/A");
+ }
+ }
+}
+
+function cpuInit() {
+ nmsData.addHandler("snmp", "mapHandler", cpuUpdater);
+ drawGradient([green,orange,red]);
+ setLegend(1,getColorStop(0),"0 %");
+ setLegend(2,getColorStop(250),"25 %");
+ setLegend(3,getColorStop(600),"60 %");
+ setLegend(4,getColorStop(1000),"100 %");
+ setLegend(5,"white","N/A");
+}
diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js
index 9bba1bf..c64a387 100644
--- a/web/nms.gathering.org/js/nms-map.js
+++ b/web/nms.gathering.org/js/nms-map.js
@@ -10,7 +10,8 @@
* nmsMap.setSwitchColor(switch,color)
* nmsMap.setSwitchInfo(switch,info)
* nmsMap.setSwitchHighlight(switch,true/false)
- * nmsMap.removeAllSwitchHighlights()
+ * nmsMap.enableHighlights()
+ * nmsMap.disableHighlights()
*/
@@ -46,21 +47,24 @@ var nmsMap = nmsMap || {
},
_color: { },
+ _linknets: {} ,
_highlight: { },
+ _highlightActive: false,
_c: {}
-}
+};
nmsMap._loadEvent = function(e) {
nmsMap._init = false;
nmsMap._drawAllSwitches();
-}
+};
+
nmsMap.init = function() {
this._initContexts();
this._init = true;
nmsData.addHandler("switches","nmsMap",function(){nmsMap._resizeEvent();});
window.addEventListener('resize',nmsMap._resizeEvent,true);
- document.addEventListener('load',nmsMap._loadEvent,true);
-}
+ window.addEventListener('load',nmsMap._loadEvent,true);
+};
nmsMap.setSwitchColor = function(sw, color) {
if (this._color[sw] != color) {
@@ -70,22 +74,30 @@ nmsMap.setSwitchColor = function(sw, color) {
} else {
this.stats.colorSame++;
}
-}
+};
+
nmsMap.setSwitchHighlight = function(sw, highlight) {
- if(highlight)
- highlight == true;
- if (this._highlight[sw] != highlight) {
- this._highlight[sw] = highlight;
- this._drawSwitch(sw);
- this.stats.highlightChange++;
- }
-}
+ if( highlight )
+ highlight = true;
+ if ( this._highlight[sw] != highlight ) {
+ this.stats.highlightChange++;
+ this._highlight[sw] = highlight;
+ }
+ this._drawSwitch(sw);
+};
+
+
+nmsMap.enableHighlights = function() {
+ this._highlightActive = true;
+};
+
+
+nmsMap.disableHighlights = function() {
+ this._highlightActive = false;
+ this._drawAllSwitches();
+};
-nmsMap.removeAllSwitchHighlights = function() {
- for(var sw in this._highlight)
- this.setSwitchHighlight(sw,false);
-}
nmsMap.reset = function() {
for (var sw in this._color) {
@@ -94,7 +106,7 @@ nmsMap.reset = function() {
for (var sw in this._info) {
nmsMap.setSwitchInfo(sw, undefined);
}
-}
+};
nmsMap.setSwitchInfo = function(sw,info) {
if (this._info[sw] != info) {
@@ -104,19 +116,19 @@ nmsMap.setSwitchInfo = function(sw,info) {
} else {
this.stats.switchInfoSame++;
}
-}
+};
nmsMap._initContext = function(name) {
this._c[name] = {};
this._c[name].c = document.getElementById(name + "Canvas");
this._c[name].ctx = this._c[name].c.getContext('2d');
-}
+};
nmsMap._initContexts = function() {
for (var context in this.contexts) {
this._initContext(this.contexts[context]);
}
-}
+};
nmsMap._resizeEvent = function() {
var width = window.innerWidth - nmsMap._c.bg.c.offsetLeft;
@@ -138,16 +150,19 @@ nmsMap._resizeEvent = function() {
continue;
nmsMap._c[a].c.height = nmsMap._canvas.height;
nmsMap._c[a].c.width = nmsMap._canvas.width;
+ if(a == 'bg') {
+ nmsMap._drawBG();
+ }
}
if (nmsMap._init != true) {
- console.log("Drawing shit");
nmsMap._blurDrawn = false;
nmsMap._drawBG();
nmsMap._drawAllSwitches();
+ nmsMap._drawAllLinknets();
nmsMap.drawNow();
nmsMap.stats.resizeEvents++;
}
-}
+};
/*
* Draw current time-window
@@ -157,10 +172,16 @@ nmsMap._resizeEvent = function() {
*
* FIXME: 2: Should really just use _drawText() instead somehow. Font size
* being an issue.
+ *
+ * FIXME 3: Currently assuming that time from api is UTC and converting to
+ * local time zone with js. Should find a more robust solution.
+ *
*/
nmsMap.drawNow = function ()
{
var now = nmsData.now;
+ now = new Date(nmsData.now); //Date assumes UTC
+ now = now.toString().split(' ').splice(1,4).join(' '); //Date returns local time
if (nmsMap._lastNow == now) {
nmsMap.stats.nowDups++;
return;
@@ -175,10 +196,10 @@ nmsMap.drawNow = function ()
ctx.fillStyle = "white";
ctx.strokeStyle = "black";
ctx.lineWidth = nms.fontLineFactor;
- ctx.strokeText(now, 0 + this._settings.textMargin, 25);
- ctx.fillText(now, 0 + this._settings.textMargin, 25);
+ ctx.strokeText(now, this._settings.textMargin, 25);
+ ctx.fillText(now, this._settings.textMargin, 25);
ctx.restore();
-}
+};
nmsMap.setNightMode = function(toggle) {
if (this._nightmode == toggle)
@@ -194,14 +215,14 @@ nmsMap.setNightMode = function(toggle) {
this._c.blur.c.style.display = "";
}
nmsMap._drawBG();
-}
+};
nmsMap._drawBG = function() {
var imageObj = document.getElementById('source');
this._c.bg.ctx.drawImage(imageObj, 0, 0, nmsMap._canvas.width, nmsMap._canvas.height);
if(this._nightmode)
nmsMap._invertBG();
-}
+};
nmsMap._invertBG = function() {
var imageData = this._c.bg.ctx.getImageData(0, 0, nmsMap._canvas.width, nmsMap._canvas.height);
@@ -213,7 +234,7 @@ nmsMap._invertBG = function() {
data[i + 2] = 255 - data[i + 2];
}
this._c.bg.ctx.putImageData(imageData, 0, 0);
-}
+};
nmsMap._getBox = function(sw) {
var box = nmsData.switches.switches[sw]['placement'];
@@ -222,7 +243,7 @@ nmsMap._getBox = function(sw) {
box.width = parseInt(box.width);
box.height = parseInt(box.height);
return box;
-}
+};
nmsMap._drawSwitchBlur = function(sw)
{
@@ -233,10 +254,11 @@ nmsMap._drawSwitchBlur = function(sw)
this._c.blur.ctx.fillStyle = "red";
this._c.blur.ctx.shadowBlur = 30;
this._c.blur.ctx.shadowColor = "white";
- this._c.blur.ctx.scale(this.scale, this.scale); // FIXME
+ this._c.blur.ctx.scale(this.scale, this.scale); // FIXME <- fix what?!
this._c.blur.ctx.fillRect(box['x'],box['y'],box['width'],box['height']);
this._c.blur.ctx.restore();
-}
+};
+
nmsMap._drawSwitch = function(sw)
{
// XXX: If a handler sets a color before switches are loaded... The
@@ -245,8 +267,12 @@ nmsMap._drawSwitch = function(sw)
return;
var box = this._getBox(sw);
var color = nmsMap._color[sw];
- if(nmsMap._highlight[sw]) {
- color = red;
+ if(this._highlightActive) {
+ if(nmsMap._highlight[sw]) {
+ color = green;
+ } else {
+ color = white;
+ }
}
if (color == undefined) {
color = blue;
@@ -255,7 +281,10 @@ nmsMap._drawSwitch = function(sw)
this._drawBox(this._c.switch.ctx, box['x'],box['y'],box['width'],box['height']);
this._c.switch.ctx.shadowBlur = 0;
this._drawText(this._c.text.ctx, sw,box);
-}
+
+ if(this._info[sw])
+ this._drawSwitchInfo(sw);
+};
nmsMap._drawSwitchInfo = function(sw) {
var box = this._getBox(sw);
@@ -264,14 +293,14 @@ nmsMap._drawSwitchInfo = function(sw) {
} else {
this._drawText(this._c.textInfo.ctx, this._info[sw], box, "right");
}
-}
+};
nmsMap._clearBox = function(ctx,box) {
ctx.save();
ctx.scale(this.scale,this.scale);
ctx.clearRect(box['x'], box['y'], box['width'], box['height']);
ctx.restore();
-}
+};
nmsMap._drawText = function(ctx, text, box, align) {
var rotate = false;
@@ -307,8 +336,42 @@ nmsMap._drawText = function(ctx, text, box, align) {
ctx.strokeText(text, 0, 0);
ctx.fillText(text, 0, 0);
ctx.restore();
-}
+};
+nmsMap._setLinknetColor = function(l, color1, color2)
+{
+ var oldcolor1;
+ var oldcolor2;
+ try {
+ oldcolor1 = nmsMap._linknets[l].sysname1;
+ oldcolor2 = nmsMap._linknets[l].sysname2;
+ if (oldcolor1 == color1 && oldcolor2 == color2) {
+ return ;
+ }
+ } catch (e) {}
+ nmsMap._linknets[l] = {};
+ nmsMap._linknets[l].sysname1 = color1;
+ nmsMap._linknets[l].sysname2 = color2;
+ nmsMap._drawLinknet(l)
+}
+
+nmsMap._drawLinknet = function(l) {
+ try {
+ var color1 = blue;
+ var color2 = blue;
+ try {
+ color1 = nmsMap._linknets[l].sysname1;
+ color2 = nmsMap._linknets[l].sysname2;
+ } catch(e) { }
+ nmsMap._connectSwitches(nmsData.switches.linknets[l].sysname1, nmsData.switches.linknets[l].sysname2, color1, color2);
+ } catch(e) { }
+}
+
+nmsMap._drawAllLinknets = function() {
+ for (var l in nmsData.switches.linknets) {
+ nmsMap._drawLinknet(l);
+ }
+}
nmsMap._drawAllSwitches = function() {
if (nmsData.switches == undefined) {
this.stats.earlyDrawAll++;
@@ -319,7 +382,7 @@ nmsMap._drawAllSwitches = function() {
}
if (this._nightmode)
this._drawAllBlur();
-}
+};
nmsMap._drawAllBlur = function() {
if (nmsMap._blurDrawn == true)
@@ -328,22 +391,22 @@ nmsMap._drawAllBlur = function() {
for (var sw in nmsData.switches.switches) {
nmsMap._drawSwitchBlur(sw);
}
-}
+};
nmsMap._drawBox = function(ctx, x, y, boxw, boxh) {
ctx.save();
- ctx.scale(this.scale, this.scale); // FIXME
+ ctx.scale(this.scale, this.scale); // FIXME <- what?!
ctx.fillRect(x,y, boxw, boxh);
ctx.lineWidth = 1;
ctx.strokeStyle = "#000000";
ctx.strokeRect(x,y, boxw, boxh);
ctx.restore();
-}
+};
nmsMap._connectSwitches = function(sw1, sw2, color1, color2) {
nmsMap._connectBoxes(this._getBox(sw1), this._getBox(sw2),
color1, color2);
-}
+};
/*
* Draw a line between two boxes, with a gradient going from color1 to
@@ -365,18 +428,20 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) {
gradient.addColorStop(0, color1);
gradient.addColorStop(1, color2);
ctx.strokeStyle = gradient;
+ ctx.beginPath();
ctx.moveTo(x0,y0);
ctx.lineTo(x1,y1);
ctx.lineWidth = 5;
ctx.stroke();
+ ctx.closePath();
ctx.restore();
-}
+};
nmsMap.moveSet = function(toggle) {
nmsMap._moveInProgress = toggle;
if (!toggle)
nmsMap._moveStopListen();
-}
+};
/*
* onclick handler for the canvas.
@@ -392,8 +457,10 @@ nmsMap.canvasClick = function(e)
} else {
nmsInfoBox.click(sw);
}
+ } else {
+ nmsInfoBox.hide();
}
-}
+};
nmsMap._clearOld = function(box) {
if (box) {
@@ -403,7 +470,7 @@ nmsMap._clearOld = function(box) {
nmsMap._c.top.ctx.clearRect(box['x'] - 5, box['y'] - 5, box['width'] + 10, box['height'] + 10);
nmsMap._c.top.ctx.restore();
}
-}
+};
nmsMap._moveMove = function(e) {
nmsMap._moveX = (e.pageX - e.target.offsetLeft) / nmsMap.scale;
@@ -421,28 +488,29 @@ nmsMap._moveMove = function(e) {
nmsMap._c.top.ctx.fillStyle = "red";
nmsMap._drawBox(nmsMap._c.top.ctx, box['x'], box['y'], box['width'], box['height']);
nmsMap._c.top.ctx.restore();
-}
+};
nmsMap._moveSubmit = function() {
var data = {
sysname: nmsMap._moving,
placement: nmsMap._moveOldBox
- }
+ };
var myData = JSON.stringify([data]);
$.ajax({
type: "POST",
- url: "/api/private/switch-add",
+ url: "/api/write/switch-update",
dataType: "text",
data:myData,
success: function (data, textStatus, jqXHR) {
nmsData.invalidate("switches");
}
});
-}
+};
+
nmsMap._moveStopListen = function() {
nmsMap._c.input.c.removeEventListener('mousemove',nmsMap._moveMove, true);
nmsMap._c.input.c.removeEventListener('mouseup',nmsMap._moveDone, true);
-}
+};
nmsMap._moveDone = function(e) {
nmsMap._moveStopListen();
@@ -451,7 +519,7 @@ nmsMap._moveDone = function(e) {
}
nmsMap._moveSubmit();
nmsMap._clearOld(nmsMap._moveOldBox);
-}
+};
nmsMap._moveStart = function(sw, e)
{
@@ -462,7 +530,7 @@ nmsMap._moveStart = function(sw, e)
nmsMap._moveBox = nmsData.switches.switches[sw].placement;
nmsMap._c.input.c.addEventListener('mousemove',nmsMap._moveMove,true);
nmsMap._c.input.c.addEventListener('mouseup',nmsMap._moveDone,true);
-}
+};
/*
diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js
index 1270a7f..0c4790c 100644
--- a/web/nms.gathering.org/js/nms.js
+++ b/web/nms.gathering.org/js/nms.js
@@ -17,7 +17,8 @@ var nms = {
*/
timers: {
playback:false,
- },
+ tvmode: false
+ },
menuShowing:true,
/*
@@ -29,7 +30,7 @@ var nms = {
'menuShowing'
],
keyBindings:{
- '?':toggleMenu,
+ '-':toggleMenu,
'n':toggleNightMode,
'1':setMapModeFromN,
'2':setMapModeFromN,
@@ -38,12 +39,17 @@ var nms = {
'5':setMapModeFromN,
'6':setMapModeFromN,
'7':setMapModeFromN,
+ '8':setMapModeFromN,
+ '9':setMapModeFromN,
+ 'c':toggleConnect,
'h':moveTimeFromKey,
'j':moveTimeFromKey,
'k':moveTimeFromKey,
'l':moveTimeFromKey,
'p':moveTimeFromKey,
- 'r':moveTimeFromKey
+ 'r':moveTimeFromKey,
+ 'Escape':hideWindow,
+ '?':toggleHelp
},
/*
* Playback controllers and variables
@@ -54,7 +60,16 @@ var nms = {
playing: false,
replayTime: 0,
replayIncrement: 60 * 60
- }
+ },
+ tvmode: {
+ handlers: [],
+ currentIndex: 0,
+ interval: 20000,
+ hideMenu: false,
+ active: false,
+ nightMode: false,
+ vertical: false
+ }
};
/*
@@ -82,7 +97,7 @@ function nmsTimer(handler, interval, name, description) {
};
this.setInterval = function(interval) {
- var started = this.handle == false ? false : true;
+ var started = this.handle != false;
this.stop();
this.interval = parseInt(interval);
if (started)
@@ -95,14 +110,16 @@ function nmsTimer(handler, interval, name, description) {
* Convenience function that doesn't support huge numbers, and it's easier
* to comment than to fix. But not really, but I'm not fixing it anyway.
*/
-function byteCount(bytes) {
+function byteCount(bytes,precision) {
+ if (precision ==undefined)
+ precision = 1;
var units = ['', 'K', 'M', 'G', 'T', 'P'];
var i = 0;
while (bytes > 1024) {
bytes = bytes / 1024;
i++;
}
- return bytes.toFixed(1) + units[i];
+ return bytes.toFixed(precision) + units[i];
}
/*
@@ -160,27 +177,27 @@ function stringToEpoch(t)
function epochToString(t)
{
// Adjust for timezone when converting from epoch (UTC) to string (local)
- var d = new Date(parseInt(t) * parseInt(1000));
- var timezoneOffset = d.getTimezoneOffset() * -60;
+ var date = new Date(parseInt(t) * parseInt(1000));
+ var timezoneOffset = date.getTimezoneOffset() * -60;
t = t - timezoneOffset;
- var d = new Date(parseInt(t) * parseInt(1000));
- var str = d.getFullYear() + "-";
- if (parseInt(d.getMonth()) < 9)
+ date = new Date(parseInt(t) * parseInt(1000));
+ var str = date.getFullYear() + "-";
+ if (parseInt(date.getMonth()) < 9)
str += "0";
- str += (parseInt(d.getMonth())+1) + "-";
- if (d.getDate() < 10)
+ str += (parseInt(date.getMonth())+1) + "-";
+ if (date.getDate() < 10)
str += "0";
- str += d.getDate() + "T";
- if (d.getHours() < 10)
+ str += date.getDate() + "T";
+ if (date.getHours() < 10)
str += "0";
- str += d.getHours() + ":";
- if (d.getMinutes() < 10)
+ str += date.getHours() + ":";
+ if (date.getMinutes() < 10)
str += "0";
- str += d.getMinutes() + ":";
- if (d.getSeconds() < 10)
+ str += date.getMinutes() + ":";
+ if (date.getSeconds() < 10)
str += "0";
- str += d.getSeconds();
+ str += date.getSeconds();
return str;
}
@@ -205,7 +222,7 @@ nms.playback.startReplay = function(startTime,stopTime) {
nms.playback.stopTime = stringToEpoch(stopTime);
nms.now = epochToString(nms.playback.startTime);
nms.playback.play();
-}
+};
/*
* Pause playback
@@ -213,7 +230,7 @@ nms.playback.startReplay = function(startTime,stopTime) {
nms.playback.pause = function() {
nms.timers.playback.stop();
nms.playback.playing = false;
-}
+};
/*
* Start playback
@@ -222,7 +239,7 @@ nms.playback.play = function() {
nms.playback.tick();
nms.timers.playback.start();
nms.playback.playing = true;
-}
+};
/*
* Toggle playback
@@ -233,19 +250,18 @@ nms.playback.toggle = function() {
} else {
nms.playback.play();
}
-}
+};
/*
* Jump to place in time
*/
nms.playback.setNow = function(now) {
- var now = parseNow(now);
- nms.now = now;
+ nms.now = parseNow(now);
nms.playback.stopTime = false;
nms.playback.startTime = false;
nms.playback.tick();
-}
+};
/*
* Step forwards or backwards in timer
@@ -258,7 +274,7 @@ nms.playback.stepTime = function(n)
if(!nms.playback.playing)
nms.playback.tick();
-}
+};
/*
* Ticker to trigger updates, and advance time if replaying
@@ -286,7 +302,7 @@ nms.playback.tick = function()
if(nms.now !== false && nms.playback.playing) {
nms.playback.stepTime(nms.playback.replayIncrement);
}
-}
+};
/*
* Helper function for safely getting a valid now-epoch
@@ -307,13 +323,64 @@ function getNowEpoch() {
*/
function setLegend(x,color,name)
{
- var el = document.getElementById("legend-" + x);
+ if(nms.tvmode.active) {
+ var el = document.getElementById("tv-mode-legend-" + x);
+ } else {
+ var el = document.getElementById("legend-" + x);
+ }
el.style.background = color;
el.title = name;
el.textContent = name;
}
/*
+ * Start TV-mode
+ *
+ * Loops trough a list of views/updaters at a set interval.
+ * Arguments: array of views, interval in seconds, use nightmode, hide menus
+ */
+nms.tvmode.start = function(views,interval,nightMode,hideMenus,displayVertical) {
+ nms.tvmode.handlers = [];
+ for(var view in views) {
+ for(var handler in handlers) {
+ if(views[view] == handlers[handler].tag) {
+ nms.tvmode.handlers.push(handlers[handler]);
+ }
+ }
+ }
+ if (nms.tvmode.handlers.length > 1) {
+ if(interval > 0)
+ nms.tvmode.interval = interval * 1000;
+ setNightMode(nightMode);
+ if(nms.menuShowing && hideMenus)
+ toggleMenu();
+ if(displayVertical)
+ nms.tvmode.vertical = true;
+ nms.timers.tvmode = new nmsTimer(nms.tvmode.tick, nms.tvmode.interval, "TV-mode ticker", "Handler used to advance tv-mode");
+ nms.timers.tvmode.start();
+ nms.tvmode.tick();
+ nms.tvmode.active = true;
+
+ document.body.classList.add("tvmode");
+ if(nms.tvmode.vertical)
+ document.body.classList.add("vertical");
+ }
+}
+nms.tvmode.tick = function() {
+ if(nms.tvmode.currentIndex > nms.tvmode.handlers.length - 1) {
+ nms.tvmode.currentIndex = 0;
+ }
+ setUpdater(nms.tvmode.handlers[nms.tvmode.currentIndex]);
+ nms.tvmode.currentIndex++;
+}
+nms.tvmode.stop = function() {
+ nms.timers.tvmode.stop();
+ document.body.classList.remove("tvmode");
+ document.body.classList.remove("vertical");
+ nms.tvmode.active = false;
+}
+
+/*
* Change map handler (e.g., change from uplink map to ping map)
*/
function setUpdater(fo)
@@ -333,6 +400,8 @@ function setUpdater(fo)
}
var foo = document.getElementById("updater_name");
foo.innerHTML = fo.name + " ";
+ var foo = document.getElementById("map-mode-title");
+ foo.innerHTML = fo.name;
document.location.hash = fo.tag;
}
@@ -344,6 +413,10 @@ function toggleLayer(layer) {
l.style.display = 'none';
}
+function toggleConnect() {
+ toggleLayer("linkCanvas");
+}
+
function commentInactive(id)
{
commentChange(id,"inactive");
@@ -375,7 +448,7 @@ function commentChange(id,state)
myData = JSON.stringify(myData);
$.ajax({
type: "POST",
- url: "/api/private/comment-change",
+ url: "/api/write/comment-change",
dataType: "text",
data:myData,
success: function (data, textStatus, jqXHR) {
@@ -393,7 +466,7 @@ function addComment(sw,comment)
myData = JSON.stringify(myData);
$.ajax({
type: "POST",
- url: "/api/private/comment-add",
+ url: "/api/write/comment-add",
dataType: "text",
data:myData,
success: function (data, textStatus, jqXHR) {
@@ -410,11 +483,7 @@ function addComment(sw,comment)
*/
function isIn(box, x, y)
{
- if ((x >= box.x) && (x <= (box.x + box.width)) && (y >= box.y) && (y <= (box.y + box.height))) {
- return true;
- }
- return false;
-
+ return ((x >= box.x) && (x <= (box.x + box.width)) && (y >= box.y) && (y <= (box.y + box.height)));
}
/*
@@ -445,8 +514,10 @@ function setNightMode(toggle) {
var nav = document.getElementsByTagName("nav")[0];
if (toggle) {
nav.classList.add('navbar-inverse');
+ document.body.classList.add("nightmode");
} else {
nav.classList.remove('navbar-inverse');
+ document.body.classList.remove("nightmode");
}
nmsMap.setNightMode(toggle);
}
@@ -465,6 +536,8 @@ function initNMS() {
nmsData.registerSource("ping", "/api/public/ping");
nmsData.registerSource("switches","/api/public/switches");
nmsData.registerSource("switchstate","/api/public/switch-state");
+ nmsData.registerSource("dhcpsummary","/api/public/dhcp-summary");
+ nmsData.registerSource("dhcp","/api/public/dhcp");
// This is a magic dummy-source, it's purpose is to give a unified
// way to get ticks every second. It is mainly meant to allow map
@@ -474,26 +547,56 @@ function initNMS() {
nmsData.registerSource("ticker","bananabananbanana");
// Private
- nmsData.registerSource("snmp","/api/private/snmp");
- nmsData.registerSource("comments", "/api/private/comments");
- nmsData.registerSource("smanagement","/api/private/switches-management");
+ nmsData.registerSource("snmp","/api/read/snmp");
+ nmsData.registerSource("comments", "/api/read/comments");
+ nmsData.registerSource("smanagement","/api/read/switches-management");
restoreSettings();
nmsMap.init();
detectHandler();
nms.playback.play();
setupKeyhandler();
+ setupSearchKeyHandler();
}
function detectHandler() {
- var url = document.URL;
for (var i in handlers) {
if (('#' + handlers[i].tag) == document.location.hash) {
setUpdater(handlers[i]);
return;
}
}
- setUpdater(handler_ping);
+ if(document.location.hash == "#tvmode") {
+ var views = getUrlVars()["views"];
+ var nightMode = parseInt(getUrlVars()["nightmode"]);
+ var vertical = parseInt(getUrlVars()["vertical"]);
+ var interval = parseInt(getUrlVars()["interval"]);
+
+ views = views.split(",");
+ if(nightMode == "0") {
+ nightMode = false;
+ } else {
+ nightMode = true;
+ }
+ if(vertical == 1) {
+ vertical = true;
+ } else {
+ vertical = false;
+ }
+
+ nms.tvmode.start(views,interval,nightMode,true,vertical);
+ return;
+ } else {
+ setUpdater(handler_ping);
+ }
+}
+
+function getUrlVars() {
+ var vars = {};
+ var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
+ vars[key] = value;
+ });
+ return vars;
}
function setMenu()
@@ -508,6 +611,13 @@ function toggleMenu()
setMenu();
saveSettings();
}
+function hideWindow(e,key)
+{
+ nmsInfoBox.hide();
+}
+function toggleHelp(e,key) {
+ toggleLayer('aboutKeybindings');
+}
function setMapModeFromN(e,key)
{
@@ -519,18 +629,24 @@ function setMapModeFromN(e,key)
setUpdater(handler_uplinks);
break;
case '3':
- setUpdater(handler_temp);
+ setUpdater(handler_dhcp);
break;
case '4':
- setUpdater(handler_traffic);
+ setUpdater(handler_comment);
break;
case '5':
- setUpdater(handler_comment);
+ setUpdater(handler_temp);
break;
case '6':
- setUpdater(handler_traffic_tot);
+ setUpdater(handler_traffic);
break;
case '7':
+ setUpdater(handler_traffic_tot);
+ break;
+ case '8':
+ setUpdater(handler_snmp);
+ break;
+ case '9':
setUpdater(handler_disco);
break;
}
@@ -568,7 +684,26 @@ function keyPressed(e)
if (e.target.nodeName == "INPUT") {
return false;
}
- var key = String.fromCharCode(e.keyCode);
+ if(e.key) {
+ var key = e.key;
+ } else {
+ var key = e.keyCode;
+ switch(key) {
+ case 187:
+ key = '?';
+ break;
+ case 189:
+ key = '-';
+ break;
+ case 27:
+ key = 'Escape';
+ break;
+ default:
+ key = String.fromCharCode(key);
+ key = key.toLowerCase();
+ break;
+ }
+ }
if (nms.keyBindings[key])
return nms.keyBindings[key](e,key);
if (nms.keyBindings['default'])
@@ -579,7 +714,16 @@ function keyPressed(e)
function setupKeyhandler()
{
var b = document.getElementsByTagName("body")[0];
- b.onkeypress = function(e){keyPressed(e);};
+ $( "body" ).keyup(function(e) {
+ keyPressed(e);
+ });
+}
+
+function setupSearchKeyHandler()
+{
+ $("#searchbox").keyup(function(e) {
+ nmsInfoBox._searchKeyListener(e);
+ });
}
@@ -599,8 +743,8 @@ function getCookie(cname) {
function saveSettings()
{
var foo={};
- for (var v in nms.settingsList) {
- foo[nms.settingsList[v]] = nms[nms.settingsList[v]];
+ for ( var v in nms.settingsList ) {
+ foo[ nms.settingsList[v] ] = nms[ nms.settingsList[v] ];
}
document.cookie = 'nms='+btoa(JSON.stringify(foo));
}