From a39e47202c108453cac8402b810cc0029c21c1c9 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sat, 19 Mar 2016 20:50:02 +0000 Subject: NMS: Intelligent, undocumented active-ports-search --- web/nms.gathering.org/js/nms-info-box.js | 48 +++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 6b13498..0175b6f 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -140,6 +140,38 @@ nmsInfoBox._makeCommentTable = function(content) { return table; } +nmsInfoBox._searchSmart = function(id, sw) { + if (nmsData.smanagement.switches[sw].distro == id) { + console.log("ieh"); + return true; + } + if (id.match("[a-z]+.active")) { + console.log("hei: " + sw); + var family = id.match("[a-z]+"); + var limit = id; + limit = limit.replace(family + ".active>",""); + limit = limit.replace(family + ".active<",""); + limit = limit.replace(family + ".active=",""); + var operator = id.replace(family + ".active","")[0]; + if (limit == parseInt(limit)) { + if (operator == ">" ) { + if (nmsData.switchstate.switches[sw][family].live > limit) { + return true; + } + } else if (operator == "<") { + if (nmsData.switchstate.switches[sw][family].live < limit) { + return true; + } + } else if (operator == "=") { + if (nmsData.switchstate.switches[sw][family].live == limit) { + return true; + } + } + } + } + return false; +} + /* * FIXME: Not sure this belongs here, it's really part of the "Core" ui, * not just the infobox. @@ -153,11 +185,19 @@ nmsInfoBox._search = function() { } if(id) { for(var sw in nmsData.switches.switches) { - if(sw.indexOf(id) > -1) { - hits++; - nmsMap.setSwitchHighlight(sw,true); + if (id[0] == "/") { + if (nmsInfoBox._searchSmart(id.slice(1),sw)) { + nmsMap.setSwitchHighlight(sw,true); + } else { + nmsMap.setSwitchHighlight(sw,false); + } } else { - nmsMap.setSwitchHighlight(sw,false); + if(sw.indexOf(id) > -1) { + hits++; + nmsMap.setSwitchHighlight(sw,true); + } else { + nmsMap.setSwitchHighlight(sw,false); + } } } } else { -- cgit v1.2.3 From 38a97f8e3fa5a5a008ed591fc8b2fdfb6fef7abc Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 19 Mar 2016 19:54:14 +0100 Subject: NMS: Add basic add-switch interface --- web/nms.gathering.org/js/nms-info-box.js | 45 +++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 0175b6f..7e27ce7 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -65,6 +65,7 @@ nmsInfoBox._hide = function() nmsInfoBox._showing = ""; nmsInfoBox._editHide(); nmsInfoBox._snmpHide(); + nmsInfoBox._createHide(); } /* @@ -388,7 +389,7 @@ nmsInfoBox._editSave = function(sw, e) { var myData = nmsInfoBox._editStringify(sw); $.ajax({ type: "POST", - url: "/api/private/switch-add", + url: "/api/private/switch-update", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -398,3 +399,45 @@ nmsInfoBox._editSave = function(sw, e) { }); nmsInfoBox._editHide(); } + + +/* + * Display infobox for new switch + * + * TODO: Integrate and rebuild info-box display logic + */ +nmsInfoBox._createShow = function() +{ + var container = document.createElement("div"); + container.className = "col-md-5"; + container.id = "nmsInfoBox-create"; + container.style.zIndex = "999"; + + var swtop = document.getElementById("wrap"); + nmsInfoBox._hide(); + + container.innerHTML = '
Add new switch
'; + + swtop.appendChild(container); +} +nmsInfoBox._createSave = function(sw) { + var feedback = document.getElementById("create-switch-feedback"); + var myData = JSON.stringify([{'sysname':sw}]); + $.ajax({ + type: "POST", + url: "/api/private/switch-add", + dataType: "text", + data:myData, + success: function (data, textStatus, jqXHR) { + var result = JSON.parse(data); + if(result.switches_addded.length > 0) { + nmsInfoBox._createHide(); + } + } + }); +} +nmsInfoBox._createHide = function() { + var container = document.getElementById("nmsInfoBox-create"); + if (container != undefined) + container.parentNode.removeChild(container); +} -- cgit v1.2.3 From 925af79d0cceb61755a0846f78fa46fbf0012406 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sun, 20 Mar 2016 22:08:38 +0100 Subject: NMS: Rewrite infoBox to enable multiple windowTypes --- web/nms.gathering.org/js/nms-info-box.js | 526 +++++++++++++++++-------------- 1 file changed, 286 insertions(+), 240 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 7e27ce7..49825bc 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -1,71 +1,316 @@ "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, unload, getTitle, getContent, getChildContent + * + * TODO: Implement useful update methods on windowTypes * - * 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 +} + +/* + * Shows a window from the _windowTypes list + */ +nmsInfoBox.showWindow = function (windowName,argument) { + nmsInfoBox.hide(); + for(var win in this._windowTypes) { + if(windowName == win) { + this._window = this._windowTypes[win]; + this._show(argument); + return; + } + } } /* - * Show the infobox for a switch. + * Refresh the active window * - * Just a wrapper for _show, but adds a handler for comments. Could easily - * add a handler for other events too. E.g.: switches. + * Todo: Could use a less aggressive refresh that doesn't hide-show everything + * + */ +nmsInfoBox.refresh = function() { + nmsInfoBox._show(); +} + +/* + * Internal function to show the active _window and pass along any arguments */ -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._show = function(argument) { + nmsData.addHandler("comments","switchshower",nmsInfoBox.update,argument); + nmsData.addHandler("switches","switchshower",nmsInfoBox.update,argument); + nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,argument); + nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,argument); + + 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() + ''; + 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"; } /* - * Hide switch info-box and remove handler. + * Hide the active window and tell it to unload */ nmsInfoBox.hide = function() { - nmsInfoBox._hide(); + if(this._container == false || this._window == false) + 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"); } /* - * Click a switch: If it's currently showing: hide it, otherwise display + * Window type: Add Switch + * + * Basic window that lets you create a new switch + * + */ +nmsInfoBox._windowTypes.addSwitch = { + title: 'Add new switch', + content: '', + childContent: false, + getTitle: function() { + return this.title; + }, + getContent: function() { + return this.content; + }, + getChildContent: function() { + return this.childContent; + }, + load: function(argument) { + }, + unload: function() { + }, + save: function() { + var sysname = document.getElementById('create-sysname').value; + var myData = JSON.stringify([{'sysname':sysname}]); + $.ajax({ + type: "POST", + url: "/api/private/switch-add", + dataType: "text", + data:myData, + success: function (data, textStatus, jqXHR) { + var result = JSON.parse(data); + if(result.switches_addded.length > 0) { + nmsInfoBox.hide(); + } + } + }); + } +}; + +/* + * Window type: Switch info + * + * Advanced window with information about a specific switch, and basic editing options + * + * Custom interfaces: showComments, showSNMP, showEdit, save + * + */ +nmsInfoBox._windowTypes.switchInfo = { + title: '', + content: '', + childContent: false, + sw: '', + swi: '', + swm: '', + load: function(sw) { + if(sw) { + this.sw = sw; + } + this.swi = nmsData.switches["switches"][this.sw]; + this.swm = nmsData.smanagement.switches[this.sw]; + + 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; + + }, + getTitle: function() { + return ' ' + this.sw + ''; + }, + getContent: function() { + return this.content; + }, + getChildContent: function() { + return this.childContent; + }, + showComments: function() { + var domObj = document.createElement("div"); + var comments = []; + if (nmsData.comments.comments != undefined && nmsData.comments.comments[this.sw] != undefined) { + 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); + $(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 = '
'; + domObj.appendChild(commentbox); + + this.childContent = domObj; + nmsInfoBox.refresh(); + }, + showEdit: function() { + var domObj = document.createElement("div"); + var template = {}; + + nmsInfoBox._editValues = {}; + for (var v in this.swi) { + if (v == "placement") { + var 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 = "'; + content.push([v, html]); + } + + 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.childContent = domObj; + nmsInfoBox.refresh(); + }, + showSNMP: function(tree) { + var domObj = document.createElement("div"); + + var output = document.createElement("output"); + output.id = "edit-output"; + output.style = "white-space: pre;"; + try { + output.value = JSON.stringify(nmsData.snmp.snmp[this.sw][tree],null,4); + } catch(e) { + output.value = "(no recent data (yet)?)"; + } + domObj.appendChild(output); + + this.childContent = domObj; + nmsInfoBox.refresh(); + }, + unload: function() { + this.childContent = false; + }, + save: function() { + var myData = nmsInfoBox._editStringify(this.sw); + console.log(myData); + $.ajax({ + type: "POST", + url: "/api/private/switch-update", + dataType: "text", + data:myData, + success: function (data, textStatus, jqXHR) { + nmsData.invalidate("switches"); + nmsData.invalidate("smanagement"); + } + }); + nmsInfoBox.hide(); + } +}; + +/* + * 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(); - nmsInfoBox._createHide(); + this.showWindow("switchInfo",sw); } /* @@ -206,86 +451,6 @@ nmsInfoBox._search = function() { } } -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)?)"; - } - 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 = ' ' + x + ' '; - - for (var v in sw) { - if (v == "placement") { - var place = JSON.stringify(sw[v]); - content.push([v,place]); - continue; - } - content.push([v, sw[v]]); - } - - 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); - } - } - } - - 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 = '
'; - swtop.appendChild(commentbox); - swtop.style.display = 'block'; -} nmsInfoBox._nullBlank = function(x) { if (x == null || x == false || x == undefined) @@ -293,69 +458,6 @@ nmsInfoBox._nullBlank = function(x) { 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 = "'; - 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); @@ -385,59 +487,3 @@ nmsInfoBox._editStringify = function(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-update", - dataType: "text", - data:myData, - success: function (data, textStatus, jqXHR) { - nmsData.invalidate("switches"); - nmsData.invalidate("smanagement"); - } - }); - nmsInfoBox._editHide(); -} - - -/* - * Display infobox for new switch - * - * TODO: Integrate and rebuild info-box display logic - */ -nmsInfoBox._createShow = function() -{ - var container = document.createElement("div"); - container.className = "col-md-5"; - container.id = "nmsInfoBox-create"; - container.style.zIndex = "999"; - - var swtop = document.getElementById("wrap"); - nmsInfoBox._hide(); - - container.innerHTML = '
Add new switch
'; - - swtop.appendChild(container); -} -nmsInfoBox._createSave = function(sw) { - var feedback = document.getElementById("create-switch-feedback"); - var myData = JSON.stringify([{'sysname':sw}]); - $.ajax({ - type: "POST", - url: "/api/private/switch-add", - dataType: "text", - data:myData, - success: function (data, textStatus, jqXHR) { - var result = JSON.parse(data); - if(result.switches_addded.length > 0) { - nmsInfoBox._createHide(); - } - } - }); -} -nmsInfoBox._createHide = function() { - var container = document.getElementById("nmsInfoBox-create"); - if (container != undefined) - container.parentNode.removeChild(container); -} -- cgit v1.2.3 From e763a7874093d7c36b89424b116dd99fc2966312 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sun, 20 Mar 2016 23:53:39 +0100 Subject: NMS: Enable search GO-button --- web/nms.gathering.org/js/nms-info-box.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 49825bc..d484cc8 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -425,7 +425,7 @@ nmsInfoBox._searchSmart = function(id, sw) { nmsInfoBox._search = function() { var el = document.getElementById("searchbox"); var id = false; - var hits = 0; + var matches = []; if (el) { id = el.value; } @@ -433,13 +433,14 @@ nmsInfoBox._search = function() { for(var sw in nmsData.switches.switches) { if (id[0] == "/") { if (nmsInfoBox._searchSmart(id.slice(1),sw)) { + matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else { nmsMap.setSwitchHighlight(sw,false); } } else { if(sw.indexOf(id) > -1) { - hits++; + matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else { nmsMap.setSwitchHighlight(sw,false); @@ -449,6 +450,16 @@ nmsInfoBox._search = function() { } else { nmsMap.removeAllSwitchHighlights(); } + if(matches.length == 1) { + document.getElementById("searchbox-submit").classList.add("btn-primary"); + document.getElementById("searchbox").addEventListener("keydown",function(e) { + if(e.keyCode == 13) + nmsInfoBox.showWindow("switchInfo",matches[0]); + }); + } else { + document.getElementById("searchbox-submit").classList.remove("btn-primary"); + document.getElementById("searchbox").removeEventListener("keydown",false); + } } -- cgit v1.2.3 From 3d840d42ab7a05059b457fd5ffb22b6c3beea8a6 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Mon, 21 Mar 2016 00:26:14 +0100 Subject: NMS: Improve search GO-button event listener --- web/nms.gathering.org/js/nms-info-box.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index d484cc8..88bc7d7 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -452,13 +452,19 @@ nmsInfoBox._search = function() { } if(matches.length == 1) { document.getElementById("searchbox-submit").classList.add("btn-primary"); - document.getElementById("searchbox").addEventListener("keydown",function(e) { - if(e.keyCode == 13) - nmsInfoBox.showWindow("switchInfo",matches[0]); - }); + document.getElementById("searchbox").dataset.match = matches[0]; + document.getElementById("searchbox").addEventListener("keydown",nmsInfoBox._searchKeyListener,false); } else { document.getElementById("searchbox-submit").classList.remove("btn-primary"); - document.getElementById("searchbox").removeEventListener("keydown",false); + document.getElementById("searchbox").dataset.match = ''; + document.getElementById("searchbox").removeEventListener("keydown",nmsInfoBox._searchKeyListener,false); + } +} + +nmsInfoBox._searchKeyListener = function(e) { + if(e.keyCode == 13) { + var sw = document.getElementById("searchbox").dataset.match; + nmsInfoBox.showWindow("switchInfo",sw); } } -- cgit v1.2.3 From 9294a2f2b20a9289a9b5c4a4b72f308de85d8c30 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 21 Mar 2016 11:57:33 +0100 Subject: NMS: Fix switch movement and poll timeout --- web/nms.gathering.org/js/nms-info-box.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 88bc7d7..dc993a9 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -133,6 +133,8 @@ nmsInfoBox._windowTypes.addSwitch = { if(result.switches_addded.length > 0) { nmsInfoBox.hide(); } + nmsData.invalidate("switches"); + nmsData.invalidate("smanagement"); } }); } -- cgit v1.2.3 From de396b689bb2ad8241d19ddf8cb97197e7054bec Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Mon, 21 Mar 2016 14:15:29 +0100 Subject: NMS: Add click-toggle to switchInfo window --- web/nms.gathering.org/js/nms-info-box.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index dc993a9..5f16ec2 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -22,6 +22,10 @@ var nmsInfoBox = nmsInfoBox || { * Shows a window from the _windowTypes list */ 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) { -- cgit v1.2.3 From 90632b710fa8798c0eeda1bb10ff25b328634e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Mon, 21 Mar 2016 16:25:14 +0100 Subject: js linting / code fixup. --- web/nms.gathering.org/js/nms-info-box.js | 43 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index dc993a9..e93ab55 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -15,8 +15,8 @@ var nmsInfoBox = nmsInfoBox || { stats: {}, _container: false, //Container window _window: false, //Active window (reference to _windowTypes object or false) - _windowTypes: [], //List of all avaliable window types -} + _windowTypes: [] //List of all avaliable window types +}; /* * Shows a window from the _windowTypes list @@ -30,7 +30,7 @@ nmsInfoBox.showWindow = function (windowName,argument) { return; } } -} +}; /* * Refresh the active window @@ -40,7 +40,7 @@ nmsInfoBox.showWindow = function (windowName,argument) { */ nmsInfoBox.refresh = function() { nmsInfoBox._show(); -} +}; /* * Internal function to show the active _window and pass along any arguments @@ -80,7 +80,7 @@ nmsInfoBox._show = function(argument) { } this._container.appendChild(panel); this._container.style.display = "block"; -} +}; /* * Hide the active window and tell it to unload @@ -95,7 +95,7 @@ nmsInfoBox.hide = function() { nmsData.unregisterHandler("switches","switchshower"); nmsData.unregisterHandler("smanagement","switchshower"); nmsData.unregisterHandler("snmp","switchshower"); -} +}; /* * Window type: Add Switch @@ -130,7 +130,7 @@ nmsInfoBox._windowTypes.addSwitch = { data:myData, success: function (data, textStatus, jqXHR) { var result = JSON.parse(data); - if(result.switches_addded.length > 0) { + if(result.switches_addded.length > 0) { // FIXME unresolved variable switches_addded nmsInfoBox.hide(); } nmsData.invalidate("switches"); @@ -226,9 +226,10 @@ nmsInfoBox._windowTypes.switchInfo = { var template = {}; nmsInfoBox._editValues = {}; + var place; for (var v in this.swi) { if (v == "placement") { - var place = JSON.stringify(this.swi[v]); + place = JSON.stringify(this.swi[v]); template[v] = place; continue; } @@ -313,7 +314,7 @@ nmsInfoBox._windowTypes.switchInfo = { nmsInfoBox.click = function(sw) { this.showWindow("switchInfo",sw); -} +}; /* * General-purpose table-maker? @@ -343,7 +344,7 @@ nmsInfoBox._makeTable = function(content, caption) { td2.innerHTML = content[v][1]; } return table; -} +}; /* * Create and return a table for comments. @@ -386,7 +387,7 @@ nmsInfoBox._makeCommentTable = function(content) { td2.innerHTML = comment["comment"]; } return table; -} +}; nmsInfoBox._searchSmart = function(id, sw) { if (nmsData.smanagement.switches[sw].distro == id) { @@ -418,7 +419,7 @@ nmsInfoBox._searchSmart = function(id, sw) { } } return false; -} +}; /* * FIXME: Not sure this belongs here, it's really part of the "Core" ui, @@ -461,21 +462,21 @@ nmsInfoBox._search = function() { document.getElementById("searchbox").dataset.match = ''; document.getElementById("searchbox").removeEventListener("keydown",nmsInfoBox._searchKeyListener,false); } -} +}; nmsInfoBox._searchKeyListener = function(e) { if(e.keyCode == 13) { var sw = document.getElementById("searchbox").dataset.match; nmsInfoBox.showWindow("switchInfo",sw); } -} +}; nmsInfoBox._nullBlank = function(x) { if (x == null || x == false || x == undefined) return ""; return x; -} +}; nmsInfoBox._editChange = function(sw, v) { @@ -496,13 +497,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._editValues['sysname'] = sw; + return JSON.stringify([nmsInfoBox._editValues]); +}; -- cgit v1.2.3 From 2c0576644afc26f4153ad316d2af216919c04fe4 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 21 Mar 2016 18:50:25 +0100 Subject: NMS: Tweak searching of switch active ports etc --- web/nms.gathering.org/js/nms-info-box.js | 52 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 5f16ec2..545e62a 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -393,33 +393,37 @@ nmsInfoBox._makeCommentTable = function(content) { } nmsInfoBox._searchSmart = function(id, sw) { - if (nmsData.smanagement.switches[sw].distro == id) { - console.log("ieh"); - return true; - } - if (id.match("[a-z]+.active")) { - console.log("hei: " + sw); - var family = id.match("[a-z]+"); - var limit = id; - limit = limit.replace(family + ".active>",""); - limit = limit.replace(family + ".active<",""); - limit = limit.replace(family + ".active=",""); - var operator = id.replace(family + ".active","")[0]; - if (limit == parseInt(limit)) { - if (operator == ">" ) { - if (nmsData.switchstate.switches[sw][family].live > limit) { - return true; - } - } else if (operator == "<") { - if (nmsData.switchstate.switches[sw][family].live < limit) { - return true; - } - } else if (operator == "=") { - if (nmsData.switchstate.switches[sw][family].live == limit) { - return true; + try { + if (nmsData.smanagement.switches[sw].distro == id) { + return true; + } + 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)) { + if (operator == ">" ) { + if (nmsData.switchstate.switches[sw]['totals'].live > limit) { + return true; + } + } else if (operator == "<") { + if (nmsData.switchstate.switches[sw]['totals'].live < limit) { + return true; + } + } else if (operator == "=") { + if (nmsData.switchstate.switches[sw]['totals'].live == limit) { + return true; + } } } } + if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) { + return true; + } + } catch (e) { + return false; } return false; } -- cgit v1.2.3 From d528cad67897dd2c3b98ec15a82868ac2764e2c7 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Mon, 21 Mar 2016 20:26:58 +0100 Subject: NMS: Tweak search highlight and hotkeys --- web/nms.gathering.org/js/nms-info-box.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 5f16ec2..8527a03 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -436,6 +436,7 @@ nmsInfoBox._search = function() { id = el.value; } if(id) { + nmsMap.enableHighlights(); for(var sw in nmsData.switches.switches) { if (id[0] == "/") { if (nmsInfoBox._searchSmart(id.slice(1),sw)) { @@ -454,23 +455,30 @@ nmsInfoBox._search = function() { } } } else { - nmsMap.removeAllSwitchHighlights(); + nmsMap.disableHighlights(); } if(matches.length == 1) { document.getElementById("searchbox-submit").classList.add("btn-primary"); document.getElementById("searchbox").dataset.match = matches[0]; - document.getElementById("searchbox").addEventListener("keydown",nmsInfoBox._searchKeyListener,false); } else { document.getElementById("searchbox-submit").classList.remove("btn-primary"); document.getElementById("searchbox").dataset.match = ''; - document.getElementById("searchbox").removeEventListener("keydown",nmsInfoBox._searchKeyListener,false); } } nmsInfoBox._searchKeyListener = function(e) { - if(e.keyCode == 13) { - var sw = document.getElementById("searchbox").dataset.match; - nmsInfoBox.showWindow("switchInfo",sw); + 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; } } -- cgit v1.2.3 From a90e2a42b2a082e4c92f991d16b552640ca8455a Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 00:06:54 +0100 Subject: NMS: Sort switch edit fields alphabeticaly --- web/nms.gathering.org/js/nms-info-box.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index cbdf942..a484706 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -250,6 +250,8 @@ nmsInfoBox._windowTypes.switchInfo = { content.push([v, html]); } + content.sort(); + var table = nmsInfoBox._makeTable(content, "edit"); domObj.appendChild(table); -- cgit v1.2.3 From 13ae4dfb0952f604c527bdd3662be61a15b6fcb7 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 00:27:11 +0100 Subject: NMS: Show comments by default when click/searching --- web/nms.gathering.org/js/nms-info-box.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index a484706..7975bae 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -319,6 +319,7 @@ nmsInfoBox._windowTypes.switchInfo = { nmsInfoBox.click = function(sw) { this.showWindow("switchInfo",sw); + this._windowTypes.switchInfo.showComments(); } /* @@ -476,8 +477,10 @@ nmsInfoBox._searchKeyListener = function(e) { switch (e.keyCode) { case 13: var sw = document.getElementById("searchbox").dataset.match; - if(sw != '') + if(sw != '') { nmsInfoBox.showWindow("switchInfo",sw); + this._windowTypes.switchInfo.showComments(); + } break; case 27: document.getElementById("searchbox").dataset.match = ''; -- cgit v1.2.3 From ef480bf237b88e667ff525a1dfb881cb8bd7cf0a Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 13:04:23 +0100 Subject: NMS: Ping increase delay, better search --- web/nms.gathering.org/js/nms-info-box.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 7975bae..e3956d8 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -422,6 +422,15 @@ nmsInfoBox._searchSmart = function(id, sw) { } } } + if (nmsData.smanagement.switches[sw].ip.match(id)) { + return true; + } + if (nmsData.smanagement.switches[sw].subnet4.match(id)) { + return true; + } + if (nmsData.smanagement.switches[sw].subnet6.match(id)) { + return true; + } if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) { return true; } @@ -445,20 +454,14 @@ nmsInfoBox._search = function() { if(id) { nmsMap.enableHighlights(); for(var sw in nmsData.switches.switches) { - if (id[0] == "/") { - if (nmsInfoBox._searchSmart(id.slice(1),sw)) { - matches.push(sw); - nmsMap.setSwitchHighlight(sw,true); - } else { - nmsMap.setSwitchHighlight(sw,false); - } + if(sw.indexOf(id) > -1) { + matches.push(sw); + nmsMap.setSwitchHighlight(sw,true); + } else if (nmsInfoBox._searchSmart(id,sw)) { + matches.push(sw); + nmsMap.setSwitchHighlight(sw,true); } else { - if(sw.indexOf(id) > -1) { - matches.push(sw); - nmsMap.setSwitchHighlight(sw,true); - } else { - nmsMap.setSwitchHighlight(sw,false); - } + nmsMap.setSwitchHighlight(sw,false); } } } else { -- cgit v1.2.3 From e3a11ccb7f67d036c1556f51efc509ee8038ca8a Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 13:18:52 +0100 Subject: NMS: Implement read/write separation in frontend --- web/nms.gathering.org/js/nms-info-box.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index b6b9d7e..b360beb 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -129,7 +129,7 @@ nmsInfoBox._windowTypes.addSwitch = { var myData = JSON.stringify([{'sysname':sysname}]); $.ajax({ type: "POST", - url: "/api/private/switch-add", + url: "/api/write/switch-add", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { @@ -301,7 +301,7 @@ nmsInfoBox._windowTypes.switchInfo = { console.log(myData); $.ajax({ type: "POST", - url: "/api/private/switch-update", + url: "/api/write/switch-update", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { -- cgit v1.2.3 From 20b6b7d37e2ae126c9e133604634d657a026283a Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 13:46:48 +0100 Subject: NMS: Fix some infoBox content checks --- web/nms.gathering.org/js/nms-info-box.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index b360beb..1a457b7 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -164,7 +164,11 @@ nmsInfoBox._windowTypes.switchInfo = { this.sw = sw; } this.swi = nmsData.switches["switches"][this.sw]; - this.swm = nmsData.smanagement.switches[this.sw]; + try { + this.swm = nmsData.smanagement.switches[this.sw]; + } catch(e) { + this.swm = []; + } var content = []; @@ -200,7 +204,7 @@ nmsInfoBox._windowTypes.switchInfo = { showComments: function() { var domObj = document.createElement("div"); var comments = []; - if (nmsData.comments.comments != undefined && nmsData.comments.comments[this.sw] != undefined) { + if(!(!nmsData.comments || !nmsData.comments.comments || !nmsData.comments.comments[this.sw])) { 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") { -- cgit v1.2.3 From e23b661a82431a518338d8da7c26347d809bf35c Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 16:07:27 +0100 Subject: NMS: Updated comment interface refresh-logic --- web/nms.gathering.org/js/nms-info-box.js | 89 ++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 26 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 1a457b7..11dbb93 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -38,22 +38,26 @@ nmsInfoBox.showWindow = function (windowName,argument) { /* * Refresh the active window - * - * Todo: Could use a less aggressive refresh that doesn't hide-show everything - * */ nmsInfoBox.refresh = function() { + if(!nmsInfoBox._window) + return; nmsInfoBox._show(); }; +nmsInfoBox.update = function(argument) { + if(!nmsInfoBox._window) + return; + nmsInfoBox._window.update(argument); +} /* * Internal function to show the active _window and pass along any arguments */ nmsInfoBox._show = function(argument) { - nmsData.addHandler("comments","switchshower",nmsInfoBox.update,argument); - nmsData.addHandler("switches","switchshower",nmsInfoBox.update,argument); - nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,argument); - nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,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'); this._window.load(argument); @@ -90,7 +94,7 @@ nmsInfoBox._show = function(argument) { * Hide the active window and tell it to unload */ nmsInfoBox.hide = function() { - if(this._container == false || this._window == false) + if(!this._container || !this._window) return; this._container.style.display = "none"; this._window.unload(); @@ -122,6 +126,8 @@ nmsInfoBox._windowTypes.addSwitch = { }, load: function(argument) { }, + update: function(type) { + }, unload: function() { }, save: function() { @@ -159,6 +165,8 @@ nmsInfoBox._windowTypes.switchInfo = { sw: '', swi: '', swm: '', + commentsHash: false, + activeView: '', load: function(sw) { if(sw) { this.sw = sw; @@ -192,6 +200,17 @@ nmsInfoBox._windowTypes.switchInfo = { this.content = infotable; }, + update: function(type) { + console.log("Updating switch info: " + type); + switch (type) { + case 'comments': + if(this.activeView == "comments" && this.commentsHash != nmsData.comments.hash) { + nmsInfoBox._windowTypes.switchInfo.showComments(); + console.log("change"); + } + break; + } + }, getTitle: function() { return ' ' + this.sw + ''; }, @@ -202,34 +221,52 @@ nmsInfoBox._windowTypes.switchInfo = { return this.childContent; }, showComments: function() { + this.activeView = "comments"; var domObj = document.createElement("div"); var comments = []; - if(!(!nmsData.comments || !nmsData.comments.comments || !nmsData.comments.comments[this.sw])) { - 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); - $(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 = '
'; - domObj.appendChild(commentbox); + commentbox.innerHTML = '
'; + // If we have no switch data, so just show comment form + if(!nmsData.comments || !nmsData.comments.comments || !nmsData.comments.comments[this.sw]) { + this.commentsHash = false; + domObj.appendChild(commentbox); + this.childContent = domObj; + nmsInfoBox.refresh(); + return; + + // We have data, but its old, so don't change data + } else if(this.commentsHash == nmsData.comments.hash) { + return; + + // We have new data, refresh + } else { + 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); + $(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) }) + } + } + + domObj.appendChild(commentbox); this.childContent = domObj; nmsInfoBox.refresh(); }, showEdit: function() { + this.activeView = "edit"; var domObj = document.createElement("div"); var template = {}; @@ -282,6 +319,7 @@ nmsInfoBox._windowTypes.switchInfo = { nmsInfoBox.refresh(); }, showSNMP: function(tree) { + this.activeView = "snmp"; var domObj = document.createElement("div"); var output = document.createElement("output"); @@ -299,10 +337,10 @@ nmsInfoBox._windowTypes.switchInfo = { }, unload: function() { this.childContent = false; + this.activeView = ""; }, save: function() { var myData = nmsInfoBox._editStringify(this.sw); - console.log(myData); $.ajax({ type: "POST", url: "/api/write/switch-update", @@ -313,7 +351,6 @@ nmsInfoBox._windowTypes.switchInfo = { nmsData.invalidate("smanagement"); } }); - nmsInfoBox.hide(); } }; -- cgit v1.2.3 From 1ed577bcb4b6650e89659485e69e6ffc29bcf7fd Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 16:23:23 +0100 Subject: NMS: Fix bug in comment refresh logic --- web/nms.gathering.org/js/nms-info-box.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 11dbb93..2d12d56 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -201,12 +201,10 @@ nmsInfoBox._windowTypes.switchInfo = { }, update: function(type) { - console.log("Updating switch info: " + type); switch (type) { case 'comments': if(this.activeView == "comments" && this.commentsHash != nmsData.comments.hash) { nmsInfoBox._windowTypes.switchInfo.showComments(); - console.log("change"); } break; } @@ -232,19 +230,15 @@ nmsInfoBox._windowTypes.switchInfo = { commentbox.innerHTML = '
'; // If we have no switch data, so just show comment form - if(!nmsData.comments || !nmsData.comments.comments || !nmsData.comments.comments[this.sw]) { + if(!nmsData.comments || !nmsData.comments.comments) { this.commentsHash = false; - domObj.appendChild(commentbox); - this.childContent = domObj; - nmsInfoBox.refresh(); - return; // We have data, but its old, so don't change data - } else if(this.commentsHash == nmsData.comments.hash) { + } else if(this.commentsHash != false && this.commentsHash == nmsData.comments.hash) { return; - // We have new data, refresh - } else { + // 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]; @@ -259,6 +253,10 @@ nmsInfoBox._windowTypes.switchInfo = { domObj.appendChild(commenttable); $(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) }) } + + // We have no data for this switch, but its still correct + } else { + this.commentsHash = nmsData.comments.hash; } domObj.appendChild(commentbox); @@ -337,6 +335,7 @@ nmsInfoBox._windowTypes.switchInfo = { }, unload: function() { this.childContent = false; + this.commentsHash = false; this.activeView = ""; }, save: function() { -- cgit v1.2.3 From 3e0ad5edff8cf33493b8b6aab92838c939fe5d69 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 20:13:35 +0100 Subject: NMS: Fix searching (again) --- web/nms.gathering.org/js/nms-info-box.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 2d12d56..0080127 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -438,7 +438,7 @@ nmsInfoBox._makeCommentTable = function(content) { nmsInfoBox._searchSmart = function(id, sw) { try { - if (nmsData.smanagement.switches[sw].distro == id) { + if (nmsData.switches.switches[sw].distro_name == id) { return true; } if (id.match("active")) { @@ -463,15 +463,22 @@ nmsInfoBox._searchSmart = function(id, sw) { } } } - if (nmsData.smanagement.switches[sw].ip.match(id)) { - return true; - } - if (nmsData.smanagement.switches[sw].subnet4.match(id)) { - return true; - } - if (nmsData.smanagement.switches[sw].subnet6.match(id)) { - return true; - } + 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].match(id)) { return true; } -- cgit v1.2.3 From 83bf82a8388e0207712b1fe9caff8935bcd06d46 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 20:48:31 +0100 Subject: NMS: Fix popovers embeded in info boxes --- web/nms.gathering.org/js/nms-info-box.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 2d12d56..e2c8eb7 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -88,6 +88,7 @@ nmsInfoBox._show = function(argument) { } this._container.appendChild(panel); this._container.style.display = "block"; + $('[data-toggle="popover"]').popover({placement:"top",container:'body'}); }; /* @@ -251,7 +252,6 @@ nmsInfoBox._windowTypes.switchInfo = { var commenttable = nmsInfoBox._makeCommentTable(comments); commenttable.id = "info-switch-comments-table"; domObj.appendChild(commenttable); - $(function () { $('[data-toggle="popover"]').popover({placement:"top",continer:'body'}) }) } // We have no data for this switch, but its still correct -- cgit v1.2.3 From 047b729a1e92446a1c5ce68f806b932b79c98642 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 21:00:57 +0100 Subject: NMS: Hide infobox when clicking empty canvas area --- web/nms.gathering.org/js/nms-info-box.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index e2c8eb7..a2d4f86 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -5,9 +5,7 @@ * * Interface: nmsInfoBox.showWindow(windowType,optionalParameter), nmsInfoBox.hide(), nmsInfoBox.refresh() * - * Any windowTypes should at a minimum implement load, unload, getTitle, getContent, getChildContent - * - * TODO: Implement useful update methods on windowTypes + * Any windowTypes should at a minimum implement load, update, unload, getTitle, getContent, getChildContent * */ -- cgit v1.2.3 From ebb539842ccad977a721b4eb515099ced8bc30c0 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Wed, 23 Mar 2016 04:43:16 +0100 Subject: Hide info-box on successful save --- web/nms.gathering.org/js/nms-info-box.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 0b90d49..ba07275 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -344,6 +344,10 @@ nmsInfoBox._windowTypes.switchInfo = { 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"); } -- cgit v1.2.3 From 19cc542fc388edf953211c0c19bb2ed7b8da536f Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Wed, 23 Mar 2016 05:02:14 +0100 Subject: NMS: Switch info window style adjustments --- web/nms.gathering.org/js/nms-info-box.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index ba07275..304a8d9 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -209,7 +209,7 @@ nmsInfoBox._windowTypes.switchInfo = { } }, getTitle: function() { - return ' ' + this.sw + ''; + return '

' + this.sw + '

'; }, getContent: function() { return this.content; @@ -387,6 +387,7 @@ 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]; -- cgit v1.2.3 From 1f88d1f2ba1e304abe4cd20f0bd3aae9347f4be8 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Wed, 23 Mar 2016 10:07:43 +0100 Subject: NMS: Fix comments not triggering after "tab" switching --- web/nms.gathering.org/js/nms-info-box.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 304a8d9..623f6be 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -218,6 +218,7 @@ nmsInfoBox._windowTypes.switchInfo = { return this.childContent; }, showComments: function() { + var oldView = this.activeView; this.activeView = "comments"; var domObj = document.createElement("div"); var comments = []; @@ -233,7 +234,7 @@ nmsInfoBox._windowTypes.switchInfo = { this.commentsHash = false; // We have data, but its old, so don't change data - } else if(this.commentsHash != false && this.commentsHash == nmsData.comments.hash) { + } else if(oldView == "comments" && this.commentsHash != false && this.commentsHash == nmsData.comments.hash) { return; // We have data, refresh -- cgit v1.2.3 From f421bfcac59d211f334842adfc04e41f8a6585ea Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Wed, 23 Mar 2016 10:52:34 +0100 Subject: NMS: Fix comment hash-check logic --- web/nms.gathering.org/js/nms-info-box.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 623f6be..0481420 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -233,10 +233,6 @@ nmsInfoBox._windowTypes.switchInfo = { if(!nmsData.comments || !nmsData.comments.comments) { this.commentsHash = false; - // We have data, but its old, so don't change data - } else if(oldView == "comments" && this.commentsHash != false && this.commentsHash == nmsData.comments.hash) { - return; - // We have data, refresh } else if(nmsData.comments.comments[this.sw]) { this.commentsHash = nmsData.comments.hash; @@ -333,9 +329,14 @@ nmsInfoBox._windowTypes.switchInfo = { nmsInfoBox.refresh(); }, unload: function() { - this.childContent = false; + this.title = ''; + this.content = ''; + this.childContent = false; + this.sw = ''; + this.swi = ''; + this.swm = ''; this.commentsHash = false; - this.activeView = ""; + this.activeView = ''; }, save: function() { var myData = nmsInfoBox._editStringify(this.sw); -- cgit v1.2.3 From a3e395b281406b233a7dc949cefb8878971d8b7d Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Wed, 23 Mar 2016 23:41:36 +0100 Subject: NMS: Add SSH-button to switchInfo window --- web/nms.gathering.org/js/nms-info-box.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 0481420..838ebb8 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -209,7 +209,16 @@ nmsInfoBox._windowTypes.switchInfo = { } }, getTitle: function() { - return '

' + this.sw + '

'; + var sshButton = ''; + try { + sshButton = nmsInfoBox._window.swm.mgmt_v4_addr; + } catch(e) { + console.log(e); + } + if(sshButton != null && sshButton != undefined && sshButton != '') { + sshButton = ' '; + } + return '

' + this.sw + '

' + sshButton; }, getContent: function() { return this.content; -- cgit v1.2.3 From c4e559c1eec4e1280faa09df8846fcfaba233333 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Wed, 23 Mar 2016 23:50:19 +0100 Subject: NMS: Remove subnet from ssh-link --- web/nms.gathering.org/js/nms-info-box.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 838ebb8..6599f5b 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -211,7 +211,8 @@ nmsInfoBox._windowTypes.switchInfo = { getTitle: function() { var sshButton = ''; try { - sshButton = nmsInfoBox._window.swm.mgmt_v4_addr; + var mgmt = nmsInfoBox._window.swm.mgmt_v4_addr; + sshButton = mgmt.split("/")[0]; } catch(e) { console.log(e); } -- cgit v1.2.3 From 91e4dcd96203f12c67936ed5d3fa7a890ea2cf55 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Thu, 24 Mar 2016 02:51:06 +0100 Subject: NMS: Add POC inventory listing to front-end --- web/nms.gathering.org/js/nms-info-box.js | 111 ++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 3 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 6599f5b..85b5d81 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -37,10 +37,10 @@ nmsInfoBox.showWindow = function (windowName,argument) { /* * Refresh the active window */ -nmsInfoBox.refresh = function() { +nmsInfoBox.refresh = function(argument) { if(!nmsInfoBox._window) return; - nmsInfoBox._show(); + nmsInfoBox._show(argument); }; nmsInfoBox.update = function(argument) { if(!nmsInfoBox._window) @@ -57,7 +57,8 @@ nmsInfoBox._show = function(argument) { nmsData.addHandler("smanagement","switchshower",nmsInfoBox.update,'smanagement'); nmsData.addHandler("snmp","switchshower",nmsInfoBox.update,'snmp'); - this._window.load(argument); + if(argument != "soft") + this._window.load(argument); this._container = document.getElementById("info-panel-container"); var panel = document.createElement("div"); @@ -367,6 +368,110 @@ nmsInfoBox._windowTypes.switchInfo = { } }; +/* + * 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: '', + getTitle: function() { + return '

Inventory listing

'; + }, + getContent: function() { + return this.content; + }, + getChildContent: function() { + return this.childContent; + }, + load: function(list) { + var hasSnmp = false; + var targetArray = []; + var listTitle = ''; + var needRefresh = false; + var needSnmp = false; + + if(!nmsData.switches || !nmsData.switches.switches) + return; + if(!(!nmsData.snmp || !nmsData.snmp.snmp)) { + hasSnmp = true; + } + if(list == 'soft') { + list = this.activeView; + needRefresh = true; + } + + switch (list) { + case 'distro_name': + targetArray = nmsData.switches.switches; + listTitle = 'Distro names'; + break; + case 'sysDescr': + if(hasSnmp) + targetArray = nmsData.snmp.snmp; + listTitle = 'System description'; + needSnmp = true; + break; + default: + targetArray = nmsData.switches.switches; + 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,'soft'); + return; + } + + var resultArray = []; + for(var sw in targetArray) { + var value = ''; + try { + switch (list) { + case 'distro_name': + value = targetArray[sw]["distro_name"]; + break; + case 'sysDescr': + value = targetArray[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"; + + this.content = infotable; + if(needRefresh) + nmsInfoBox.refresh("soft"); + }, + update: function(type) { + if(type == "soft") { + nmsData.unregisterHandler("snmp","inventoryListing"); + nmsInfoBox._windowTypes.inventoryListing.load('soft'); + } + }, + unload: function() { + nmsData.unregisterHandler("snmp","inventoryListing"); + this.content = ''; + this.activeView = ''; + }, + save: function() { + } +}; + /* * Click a switch and display it * it. -- cgit v1.2.3 From be83c1a10121d98e0acf6f8a74cb322901d1818a Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Thu, 24 Mar 2016 03:40:27 +0100 Subject: NMS: Change search to all lowercase Does not convert number only fields to lowercase. Is primarily useful when searching system descriptions for version information or similar. --- web/nms.gathering.org/js/nms-info-box.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 85b5d81..a9eda2a 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -558,7 +558,7 @@ nmsInfoBox._makeCommentTable = function(content) { nmsInfoBox._searchSmart = function(id, sw) { try { - if (nmsData.switches.switches[sw].distro_name == id) { + if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { return true; } if (id.match("active")) { @@ -599,7 +599,7 @@ nmsInfoBox._searchSmart = function(id, sw) { return true; } } catch (e) {} - if (nmsData.snmp.snmp[sw].misc.sysDescr[0].match(id)) { + if (nmsData.snmp.snmp[sw].misc.sysDescr[0].toLowerCase().match(id)) { return true; } } catch (e) { @@ -617,12 +617,12 @@ nmsInfoBox._search = function() { var id = false; 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) { + if(sw.toLowerCase().indexOf(id) > -1) { matches.push(sw); nmsMap.setSwitchHighlight(sw,true); } else if (nmsInfoBox._searchSmart(id,sw)) { -- cgit v1.2.3 From 04bd92868c0a4c91936283bd126eacf71bee1999 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Thu, 24 Mar 2016 07:40:18 +0100 Subject: NMS: Add basic filter-field to inventory listing --- web/nms.gathering.org/js/nms-info-box.js | 39 ++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index a9eda2a..6609664 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -380,6 +380,7 @@ nmsInfoBox._windowTypes.inventoryListing = { content: '', childContent: false, activeView: '', + activeFilter: '', getTitle: function() { return '

Inventory listing

'; }, @@ -389,36 +390,45 @@ nmsInfoBox._windowTypes.inventoryListing = { 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 = '
'; + contentObj.appendChild(inputObj); + if(!nmsData.switches || !nmsData.switches.switches) return; if(!(!nmsData.snmp || !nmsData.snmp.snmp)) { hasSnmp = true; } - if(list == 'soft') { + if(list == "refresh") { list = this.activeView; needRefresh = true; } switch (list) { case 'distro_name': - targetArray = nmsData.switches.switches; listTitle = 'Distro names'; break; case 'sysDescr': if(hasSnmp) - targetArray = nmsData.snmp.snmp; listTitle = 'System description'; needSnmp = true; break; default: - targetArray = nmsData.switches.switches; listTitle = 'Distro names'; list = 'distro_name'; } @@ -426,20 +436,24 @@ nmsInfoBox._windowTypes.inventoryListing = { if(needSnmp && !hasSnmp) { this.content = "No SNMP data loaded. Reloading shortly."; - nmsData.addHandler("snmp","inventoryListing",nmsInfoBox._windowTypes.inventoryListing.update,'soft'); + nmsData.addHandler("snmp","inventoryListing",nmsInfoBox._windowTypes.inventoryListing.update,"snmp-request"); return; } var resultArray = []; - for(var sw in targetArray) { + 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 = targetArray[sw]["distro_name"]; + value = nmsData.switches.switches[sw]["distro_name"]; break; case 'sysDescr': - value = targetArray[sw]["misc"]["sysDescr"][0]; + value = nmsData.snmp.snmp[sw]["misc"]["sysDescr"][0]; break; } } catch (e) { @@ -453,20 +467,22 @@ nmsInfoBox._windowTypes.inventoryListing = { var infotable = nmsInfoBox._makeTable(resultArray,listTitle); infotable.id = "inventory-table"; - this.content = infotable; + contentObj.appendChild(infotable); + this.content = contentObj; if(needRefresh) nmsInfoBox.refresh("soft"); }, update: function(type) { - if(type == "soft") { + if(type == "snmp-request") { nmsData.unregisterHandler("snmp","inventoryListing"); - nmsInfoBox._windowTypes.inventoryListing.load('soft'); + nmsInfoBox._windowTypes.inventoryListing.load("refresh"); } }, unload: function() { nmsData.unregisterHandler("snmp","inventoryListing"); this.content = ''; this.activeView = ''; + this.activeFilter = ''; }, save: function() { } @@ -662,7 +678,6 @@ nmsInfoBox._searchKeyListener = function(e) { } }; - nmsInfoBox._nullBlank = function(x) { if (x == null || x == false || x == undefined) return ""; -- cgit v1.2.3 From 7c6589dd177deaba473fdde3fd48c283f5e369bc Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Thu, 24 Mar 2016 21:12:08 +0100 Subject: NMS: Expose ET-interfaces and more --- web/nms.gathering.org/js/nms-info-box.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 6609664..a718f78 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -574,9 +574,11 @@ nmsInfoBox._makeCommentTable = function(content) { nmsInfoBox._searchSmart = function(id, sw) { try { - if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { - return true; - } + try { + if (nmsData.switches.switches[sw].distro_name.toLowerCase() == id) { + return true; + } + } catch (e) {} if (id.match("active")) { var limit = id; limit = limit.replace("active>",""); -- cgit v1.2.3 From 7b39120d069223c5e2cf135f0e89df9a13ded17b Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 26 Mar 2016 01:50:58 +0100 Subject: NMS: Add basic formating to SNMP-data in infobox --- web/nms.gathering.org/js/nms-info-box.js | 61 ++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index a718f78..1728d81 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -88,6 +88,9 @@ nmsInfoBox._show = function(argument) { 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'); + }); }; /* @@ -325,19 +328,55 @@ nmsInfoBox._windowTypes.switchInfo = { showSNMP: function(tree) { this.activeView = "snmp"; var domObj = document.createElement("div"); + domObj.classList.add("panel-group"); - var output = document.createElement("output"); - output.id = "edit-output"; - output.style = "white-space: pre;"; - try { - output.value = JSON.stringify(nmsData.snmp.snmp[this.sw][tree],null,4); - } catch(e) { - output.value = "(no recent data (yet)?)"; - } - domObj.appendChild(output); + try { + var snmpJson = nmsData.snmp.snmp[this.sw][tree]; + } catch(e) { + this.content = "(no recent data (yet)?)"; + return; + } - this.childContent = domObj; - nmsInfoBox.refresh(); + /* + * 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 = '' + obj + ''; + + 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 = '' + prop + '' + snmpJson[obj][prop] + ''; + tbody.appendChild(propObj); + } + + tableObj.appendChild(tbody); + panelBodyObj.appendChild(tableObj); + groupObjCollapse.appendChild(panelBodyObj); + groupObj.appendChild(groupObjCollapse); + domObj.appendChild(groupObj); + + } + this.content = domObj; + + nmsInfoBox.refresh("soft"); }, unload: function() { this.title = ''; -- cgit v1.2.3 From 004f4efcfd0779f4307b90fed139dc87d01ad0b9 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Sat, 26 Mar 2016 03:48:12 +0100 Subject: NMS: Various performance tweaks --- web/nms.gathering.org/js/nms-info-box.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index a718f78..77f5cf5 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -579,6 +579,7 @@ nmsInfoBox._searchSmart = function(id, sw) { return true; } } catch (e) {} + try { if (id.match("active")) { var limit = id; limit = limit.replace("active>",""); @@ -586,21 +587,24 @@ nmsInfoBox._searchSmart = function(id, sw) { 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 (nmsData.switchstate.switches[sw]['totals'].live > limit) { + if (ports > limit) { return true; } } else if (operator == "<") { - if (nmsData.switchstate.switches[sw]['totals'].live < limit) { + if (ports < limit) { return true; } } else if (operator == "=") { - if (nmsData.switchstate.switches[sw]['totals'].live == limit) { + if (ports == limit) { return true; } } } } + } catch (e) {} try { if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) { return true; -- cgit v1.2.3 From 04b13311cedf90f57db5d53feea7349a008f628b Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 26 Mar 2016 07:27:17 +0100 Subject: NMS: Improve switch info window New summary view with live switch-information. Improved SNMP data listing and no more repetition of basic switch data for every view. --- web/nms.gathering.org/js/nms-info-box.js | 437 ++++++++++++++++++++----------- 1 file changed, 280 insertions(+), 157 deletions(-) (limited to 'web/nms.gathering.org/js/nms-info-box.js') diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index 1728d81..42ed505 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -158,176 +158,299 @@ nmsInfoBox._windowTypes.addSwitch = { * * Advanced window with information about a specific switch, and basic editing options * - * Custom interfaces: showComments, showSNMP, showEdit, save + * Custom interfaces: showSummary, showInfoTable, showComments, showSNMP, showEdit, save * */ nmsInfoBox._windowTypes.switchInfo = { - title: '', - content: '', - childContent: false, - sw: '', - swi: '', - swm: '', + title: '', + content: '', + childContent: false, + sw: '', + swi: '', + swm: '', commentsHash: false, activeView: '', - load: function(sw) { - if(sw) { - this.sw = sw; - } - this.swi = nmsData.switches["switches"][this.sw]; - try { - this.swm = nmsData.smanagement.switches[this.sw]; - } catch(e) { - this.swm = []; + load: function(sw) { + if(sw) { + this.sw = sw; } - - 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; - - }, + 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 == "comments" && this.commentsHash != nmsData.comments.hash) { + if(this.activeView == "summary" && this.commentsHash != nmsData.comments.hash) { nmsInfoBox._windowTypes.switchInfo.showComments(); } break; } }, - getTitle: function() { + getTitle: function() { var sshButton = ''; try { var mgmt = nmsInfoBox._window.swm.mgmt_v4_addr; sshButton = mgmt.split("/")[0]; - } catch(e) { - console.log(e); - } + } catch(e) {} if(sshButton != null && sshButton != undefined && sshButton != '') { sshButton = ' '; } - return '

' + this.sw + '

' + sshButton; - }, - getContent: function() { - return this.content; - }, - getChildContent: function() { - return this.childContent; - }, - showComments: function() { - var oldView = this.activeView; - this.activeView = "comments"; - 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 = '
'; - - // If we have no switch data, so just show comment form - if(!nmsData.comments || !nmsData.comments.comments) { - this.commentsHash = false; + return '

' + this.sw + '

' + sshButton; + }, + getContent: function() { + return this.content; + }, + getChildContent: function() { + return this.childContent; + }, + showSummary: function(argument) { + this.activeView = "summary"; + var content = []; - // 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); - } + //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 = '
'; - if (comments.length > 0) { - var commenttable = nmsInfoBox._makeCommentTable(comments); - commenttable.id = "info-switch-comments-table"; - domObj.appendChild(commenttable); + // 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); } + } - // We have no data for this switch, but its still correct - } else { - this.commentsHash = nmsData.comments.hash; + if (comments.length > 0) { + var commenttable = nmsInfoBox._makeCommentTable(comments); + commenttable.id = "info-switch-comments-table"; + domObj.appendChild(commenttable); } - domObj.appendChild(commentbox); - this.childContent = domObj; - nmsInfoBox.refresh(); - }, - showEdit: function() { + // 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 = "'; - content.push([v, html]); - } + 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 = "'; + content.push([v, html]); + } content.sort(); - var table = nmsInfoBox._makeTable(content, "edit"); - domObj.appendChild(table); + 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 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); + 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; - } - } + if (place) { + var pval = document.getElementById("edit-" + this.sw + "-placement"); + if (pval) { + pval.value = place; + } + } - this.childContent = domObj; - nmsInfoBox.refresh(); - }, - showSNMP: function(tree) { + this.content = domObj; + this.childContent = ''; + nmsInfoBox.refresh("soft"); + }, + showSNMP: function(tree) { this.activeView = "snmp"; - var domObj = document.createElement("div"); + var domObj = document.createElement("div"); domObj.classList.add("panel-group"); try { @@ -375,10 +498,11 @@ nmsInfoBox._windowTypes.switchInfo = { } this.content = domObj; - - nmsInfoBox.refresh("soft"); - }, - unload: function() { + this.childContent = ''; + + nmsInfoBox.refresh("soft"); + }, + unload: function() { this.title = ''; this.content = ''; this.childContent = false; @@ -387,24 +511,25 @@ nmsInfoBox._windowTypes.switchInfo = { this.swm = ''; this.commentsHash = false; this.activeView = ''; - }, - 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"); - } - }); - } + 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"); + } + }); + } }; /* @@ -534,7 +659,6 @@ nmsInfoBox._windowTypes.inventoryListing = { nmsInfoBox.click = function(sw) { this.showWindow("switchInfo",sw); - this._windowTypes.switchInfo.showComments(); }; /* @@ -707,7 +831,6 @@ nmsInfoBox._searchKeyListener = function(e) { var sw = document.getElementById("searchbox").dataset.match; if(sw != '') { nmsInfoBox.showWindow("switchInfo",sw); - this._windowTypes.switchInfo.showComments(); } break; case 27: -- cgit v1.2.3