diff options
Diffstat (limited to 'web/js/nms-info-box.js')
-rw-r--r-- | web/js/nms-info-box.js | 298 |
1 files changed, 40 insertions, 258 deletions
diff --git a/web/js/nms-info-box.js b/web/js/nms-info-box.js index e6817dc..cd5594e 100644 --- a/web/js/nms-info-box.js +++ b/web/js/nms-info-box.js @@ -13,15 +13,11 @@ /* * * Currently broken or needs reimplementing: - * - Possibly: Comment CRUD, did not want to test writes on our "historic db copy" - * - Comments popover * - Handler unloading is not working correctly, and many are never removed * - SSH-management link, this should propably be a custom "view" of sorts - * - inventoryListing window is partially broken when first opened. Since it's - * both a window type and a panel with different modes it has some conflicts. * * General TODO: - * - Fix broken stuff + * - Move inventory into a separate tab. * - Add external windows (timetravel, etc) * - Take a critical look at what methods/variables should be marked as "_" * - Currently argument is assumed to be a switch, this should not be the case @@ -44,13 +40,9 @@ var nmsInfoBox = nmsInfoBox || { 'title': 'Switch info', 'views': { 'initial': { - 'name': 'Switch summary', + 'name': 'Summary', 'panels': ['switchSummary','switchComments'] }, - 'details': { - 'name': 'Switch details', - 'panels': ['switchDetails'] - }, 'ports': { 'name': 'SNMP - Ports', 'panels': ['switchSNMP:ports'] @@ -59,9 +51,9 @@ var nmsInfoBox = nmsInfoBox || { 'name': 'SNMP - Misc', 'panels': ['switchSNMP:misc'] }, - 'comments': { - 'name': 'Comments', - 'panels': ['switchComments'] + 'details': { + 'name': 'Settings', + 'panels': ['switchDetails'] }, 'edit': { 'name': 'Edit', @@ -176,8 +168,10 @@ nmsInfoBox.addPanelType = function (id, obj) { */ nmsInfoBox.hide = function() { this._sw = false; - this._windowHandler.hide(); - this._windowHandler.unloadWindow(); + if (this._windowHandler != undefined && this._windowHandler.hide != undefined) { + this._windowHandler.hide(); + this._windowHandler.unloadWindow(); + } }; /* @@ -194,7 +188,7 @@ nmsInfoBox.click = function(sw) * Is based on a hierarchy of objects: Window (itself) > Views > Panels. Where * any object should not interact with any other directly. Panels are special * nmsInfoPanel-objects that handle their own rendering, refreshing, etc. The - * window handler only makes shure these panels are loaded and unloaded when + * window handler only makes sure these panels are loaded and unloaded when * needed in a window or view. * * Does primarily rely on an imported list of panel types and window types to @@ -590,13 +584,7 @@ var searchHelpPanel = function() { nmsInfoPanel.call(this,"searchHelp"); this.refresh = function(reason) { var x = document.createElement("div"); - var searchHelp = [ - "The search box can be used to identify switches in several ways. The simplest is by name.", - "If you are using the non-public version of Gondul, you can also perform smart searches.", - "Distro search: Type the name of a distro-switch and all access switches registered to that distro switch will also be hilighted.", - 'Active ports: Type "active>x", "active<x" or "active=x" to identify switch with "x" amount of active gigabit ethernet (ge) ports. E.g.: "active>30".', - 'IP search: Start typing an IP and any switch with that IP registered either as management IP or part of its subnet will be identified', - 'SNMP search: Type anything found in the "sysDescr" SNMP OID to hilight a switch matching that. Practical examples include version numbers for firmware (e.g.: "JUNOS 12." vs "JUNOS 14.").']; + var searchHelp = nmsSearch.helpText; for (var a in searchHelp) { var c = document.createElement("p"); c.innerText = searchHelp[a]; @@ -704,7 +692,7 @@ var inventoryListingPanel = function() { for(var sw in nmsData.switches.switches) { var value = ''; if(this.filter != '') { - if(sw.toLowerCase().indexOf(this.filter) == -1 && !nmsInfoBox._searchSmart(this.filter,sw)) + if(sw.toLowerCase().indexOf(this.filter) == -1 && !nmsSearch.searchTest(this.filter,sw)) continue; } try { @@ -774,7 +762,7 @@ var switchEditPanel = function () { 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 + '>'; + var html = '<input type="text" class="form-control" value="' + template[v] + '" id="edit-' + this.sw + '-' + v + '" onchange=' + tmphandler + ' oninput=' + tmphandler + ' ' + (v == 'sysname' ? "readonly" : "") + '>'; content.push([v, html]); } @@ -794,6 +782,7 @@ var switchEditPanel = function () { output.id = "edit-output"; domObj.appendChild(output); + this._render(domObj); if (place) { var pval = document.getElementById("edit-" + this.sw + "-placement"); if (pval) { @@ -801,7 +790,6 @@ var switchEditPanel = function () { } } - this._render(domObj); }; this.save = function () { var myData = nmsInfoBox._editStringify(this.sw); @@ -828,8 +816,6 @@ nmsInfoBox.addPanelType("switchEdit",switchEditPanel); * * Displays the current comments and lets you interact with them or add new ones * - * TODO: Test with a dummy-db to make sure everything still works properly - * */ var switchCommentsPanel = function () { nmsInfoPanel.call(this,"switchComments"); @@ -837,28 +823,25 @@ var switchCommentsPanel = function () { this.refresh = function (reason) { var domObj = document.createElement("div"); var comments = []; - var logs = nmsOplog.getSwitchLogs(this.sw); - // We have data - var table = document.createElement("table"); - var tr; - var td1; - var td2; - var td3; - table.className = "table"; - table.classList.add("table"); - table.classList.add("table-condensed"); - for (var v in logs) { - tr = table.insertRow(-1); - tr.className = - td1 = tr.insertCell(0); - td2 = tr.insertCell(1); - td1.textContent = logs[v]['timestamp']; - td2.textContent = "[" + logs[v]['username'] + "] " + logs[v]['log']; - } - domObj.appendChild(table); - - + var table = document.createElement("table"); + var tr; + var td1; + var td2; + var td3; + table.className = "table"; + table.classList.add("table"); + table.classList.add("table-condensed"); + for (var v in logs) { + tr = table.insertRow(-1); + tr.className = + td1 = tr.insertCell(0); + td2 = tr.insertCell(1); + var date = new Date(logs[v]['timestamp']); + td1.textContent = date.toString(); + td2.textContent = "[" + logs[v]['username'] + "] " + logs[v]['log']; + } + domObj.appendChild(table); this._render(domObj); }; }; @@ -878,97 +861,14 @@ var switchSummaryPanel = function() { }; this.refresh = function(reason) { 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); + for ( var h in handlers ) { + if (handlers[h].getInfo != undefined) { + var tmp = handlers[h].getInfo(this.sw); + for (var x in tmp.data) { + content.push([tmp.data[x].description, tmp.data[x].value]); + } } - } 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) {} - - //Get management data - var mgmtV4 = ""; - var mgmtV6 = ""; - var subnetV4 = ""; - var subnetV6 = ""; - try { - mgmtV4 = nmsData.smanagement.switches[this.sw].mgmt_v4_addr; - mgmtV6 = nmsData.smanagement.switches[this.sw].mgmt_v6_addr; - subnetV4 = nmsData.smanagement.switches[this.sw].subnet4; - subnetV6 = nmsData.smanagement.switches[this.sw].subnet6; - } catch(e) {} - - //Get ping data - var ping = undefined; - try { - nmsData.ping.switches[this.sw].latency + " ms"; - } catch (e) {} - - - content.push(["Ping latency:",ping]); - 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):",mgmtV4]); - content.push(["Management (v6):",mgmtV6]); - content.push(["Subnet (v4):",subnetV4]); - content.push(["Subnet (v6):",subnetV6]); + } var contentCleaned = []; for(var i in content) { @@ -978,7 +878,6 @@ var switchSummaryPanel = function() { content[i][1] == "No data"; contentCleaned.push(content[i]); } - var table = nmsInfoBox._makeTable(contentCleaned); this._render(table); @@ -1008,7 +907,7 @@ nmsInfoBox._makeTable = function(content, caption) { } for (var v in content) { tr = table.insertRow(-1); - tr.className = content[v][0].toLowerCase(); + tr.className = content[v][0].toLowerCase().replace(/[^a-z0-9_]/g,""); td1 = tr.insertCell(0); td2 = tr.insertCell(1); td1.innerHTML = content[v][0]; @@ -1017,123 +916,6 @@ nmsInfoBox._makeTable = function(content, caption) { return table; }; -nmsInfoBox.searchSmart = function(id, sw) { - if (id == "") - return false; - return nmsInfoBox._searchSmart(id, sw); -} - -nmsInfoBox._searchSmart = function(id, sw) { - try { - if(sw.toLowerCase().indexOf(id) > -1) { - return true; - } - 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, - * not just the infobox. - */ -nmsInfoBox._search = function() { - var el = document.getElementById("searchbox"); - var id = false; - var matches = []; - if (el) { - id = el.value.toLowerCase(); - } - if(id) { - nmsMap.enableHighlights(); - for(var sw in nmsData.switches.switches) { - if (nmsInfoBox._searchSmart(id,sw)) { - matches.push(sw); - nmsMap.setSwitchHighlight(sw,true); - } else { - nmsMap.setSwitchHighlight(sw,false); - } - } - } else { - nmsMap.disableHighlights(); - } - 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 = ''; - } -}; - -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; - } -}; - nmsInfoBox._nullBlank = function(x) { if (x == null || x == false || x == undefined) return ""; |