diff options
author | Kristian Lyngstol <kly@kly@.no> | 2016-03-22 19:54:00 +0100 |
---|---|---|
committer | Kristian Lyngstol <kly@kly@.no> | 2016-03-22 19:54:00 +0100 |
commit | 8e2fb5f3c7fbfbb13224f0cb8a610837bfef364a (patch) | |
tree | e4a2d43eb86e912f44b8d397e8f86450a1d0469a /web/nms-public.gathering.org/js/nms-map-handlers.js | |
parent | 05fedaa7461c6fd67c402671f0e129b3d1772fbf (diff) |
Update nms-public code
Diffstat (limited to 'web/nms-public.gathering.org/js/nms-map-handlers.js')
-rw-r--r-- | web/nms-public.gathering.org/js/nms-map-handlers.js | 95 |
1 files changed, 77 insertions, 18 deletions
diff --git a/web/nms-public.gathering.org/js/nms-map-handlers.js b/web/nms-public.gathering.org/js/nms-map-handlers.js index a6dc942..0bec084 100644 --- a/web/nms-public.gathering.org/js/nms-map-handlers.js +++ b/web/nms-public.gathering.org/js/nms-map-handlers.js @@ -49,6 +49,12 @@ var handler_traffic_tot = { name:"Switch traffic map" }; +var handler_dhcp = { + init:dhcpInit, + tag:"dhcp", + name:"DHCP map" +}; + var handler_disco = { init:discoInit, tag:"disco", @@ -68,7 +74,8 @@ var handlers = [ handler_traffic, handler_disco, handler_comment, - handler_traffic_tot + handler_traffic_tot, + handler_dhcp ]; /* @@ -84,7 +91,7 @@ function uplinkUpdater() return; if (!nmsData.switchstate.switches) return; - for (sw in nmsData.switches.switches) { + for (var sw in nmsData.switches.switches) { var uplinks=0; if (nmsData.switchstate.switches[sw] == undefined || nmsData.switchstate.switches[sw].uplinks == undefined) { uplinks=0; @@ -95,12 +102,12 @@ function uplinkUpdater() if (uplinks == 0) { nmsMap.setSwitchColor(sw,"white"); - } else if (nuplinks == uplinks) { - nmsMap.setSwitchColor(sw,green); - } else if (nuplinks - uplinks == 1) { - nmsMap.setSwitchColor(sw, orange); - } else if (nuplinks - uplinks == 2) { + } else if (uplinks == 1) { nmsMap. setSwitchColor(sw, red); + } else if (uplinks == 2) { + nmsMap.setSwitchColor(sw, orange); + } else if (uplinks == 3) { + nmsMap.setSwitchColor(sw,green); } else if (uplinks > 3) { nmsMap.setSwitchColor(sw, blue); } @@ -115,9 +122,9 @@ function uplinkInit() nmsData.addHandler("switches","mapHandler",uplinkUpdater); nmsData.addHandler("switchstate","mapHandler",uplinkUpdater); setLegend(1,"white","0 uplinks"); - setLegend(2,red,"2 missing"); - setLegend(3,orange,"1 missing"); - setLegend(4,green,"0 missing"); + setLegend(2,red,"1 uplink"); + setLegend(3,orange,"2 uplinks"); + setLegend(4,green,"3 uplinks"); setLegend(5,blue,"4 uplinks"); } @@ -139,9 +146,9 @@ function trafficUpdater() { if (!nms.switches_now["switches"]) return; - for (sw in nms.switches_now["switches"]) { + for (var sw in nms.switches_now["switches"]) { var speed = 0; - for (port in nms.switches_now["switches"][sw]["ports"]) { + for (var port in nms.switches_now["switches"][sw]["ports"]) { if (/ge-0\/0\/44$/.exec(port) || /ge-0\/0\/45$/.exec(port) || /ge-0\/0\/46$/.exec(port) || @@ -177,9 +184,9 @@ function trafficTotUpdater() { if (!nms.switches_now["switches"]) return; - for (sw in nms.switches_now["switches"]) { + for (var sw in nms.switches_now["switches"]) { var speed = 0; - for (port in nms.switches_now["switches"][sw]["ports"]) { + for (var port in nms.switches_now["switches"][sw]["ports"]) { if (!nms.switches_then["switches"][sw] || !nms.switches_then["switches"][sw]["ports"] || !nms.switches_then["switches"][sw]["ports"][port]) @@ -220,14 +227,14 @@ function tempUpdater() if(!nmsData.switches) return; - for (sw in nmsData.switches["switches"]) { + for ( var sw in nmsData.switches["switches"]) { var t = "white"; var temp = ""; - - if(!nmsData.snmp || !nmsData.snmp.snmp[sw] || !nmsData.snmp.snmp[sw]["misc"] || !nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]) + + if(!nmsData.snmp || !nmsData.snmp.snmp || ! nmsData.snmp.snmp[sw] || !nmsData.snmp.snmp[sw]["misc"] || !nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]) continue; - tempObj = nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]; + var tempObj = nmsData.snmp.snmp[sw]["misc"]["enterprises.2636.3.1.13.1.7.7.1.0.0"]; Object.keys(tempObj).forEach(function (key) { if(key == "") { temp = tempObj[key] + "°C"; @@ -259,6 +266,7 @@ function pingUpdater() } for (var sw in nmsData.switches.switches) { try { + var c; if (nmsData.ping.switches[sw].age > 0) { c = red; } else { @@ -291,6 +299,8 @@ function commentUpdater() if (nmsData.comments == undefined || nmsData.comments.comments == undefined) { return } + if(!nmsData.switches) + return; for (var sw in nmsData.switches.switches) { var c = "white"; if (nmsData.comments.comments[sw] == undefined) { @@ -336,6 +346,55 @@ function commentInit() setLegend(5,green ,"Old/inactive only"); } +function getDhcpColor(stop) +{ + stop = parseInt(stop); + stop = stop * 0.85; + if (stop < 0) + stop = 1000; + if (stop > 1000) + stop = 1000; + return getColorStop(stop); +} + +function dhcpUpdater() +{ + var realnow = Date.now(); + var now = Math.floor(realnow / 1000); + if (nmsData.dhcp == undefined || nmsData.dhcp.dhcp == undefined) { + return + } + if (nmsData.switches == undefined || nmsData.switches.switches == undefined) { + return; + } + try { + for (var sw in nmsData.switches.switches) { + var c = "white"; + if (nmsData.dhcp.dhcp[sw] == undefined) { + nmsMap.setSwitchColor(sw,c); + continue; + } + var s = nmsData.dhcp.dhcp[sw]; + var then = parseInt(s); + c = getDhcpColor(now - then); + nmsMap.setSwitchColor(sw, c); + } + } catch(e) { + console.log(e); + } +} + +function dhcpInit() +{ + drawGradient([green,lightgreen,orange,red]); + nmsData.addHandler("dhcp","mapHandler",dhcpUpdater); + setLegend(1,"white","Undefined"); + setLegend(2,getDhcpColor(1),"1 Second old"); + setLegend(3,getDhcpColor(300),"300 Seconds old"); + setLegend(4,getDhcpColor(900),"900 Seconds old"); + setLegend(5,getDhcpColor(1200),"1200 Seconds old"); +} + /* * Testing-function to randomize colors of linknets and switches */ |