diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-03-17 19:51:46 +0000 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-03-17 19:51:46 +0000 |
commit | 5c9d6d10dc7e53a8d06fbd056ded591a6b583167 (patch) | |
tree | 6f6290fb1b8bcc859278a2c68573a35547173931 /web/nms.gathering.org/js/nms-map-handlers.js | |
parent | 76a3aad5090d304ec0f76f28e50afe1f53b7b96c (diff) | |
parent | 025f01e7e8c5bfea21b559fbac650f90c2774a29 (diff) |
Merge branch 'master' of https://github.com/tech-server/tgmanage
Diffstat (limited to 'web/nms.gathering.org/js/nms-map-handlers.js')
-rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 177 |
1 files changed, 92 insertions, 85 deletions
diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index eaa62fd..fa33bad 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -2,8 +2,7 @@ * Map handlers/updaters for NMS. * * These are functions used to determine how the map should look in NMS. - * They represent vastly different information, but in a uniform way. I - * suppose this is the c++-type of object orientation... + * They represent vastly different information, but in a uniform way. * * The idea is that these updaters only parse information that's fetched by * NMS - they do not request additional information. E.g., ping data is @@ -11,57 +10,52 @@ * displayed. This might seem redundant, but it means any handler can * utilize information from any aspect of NMS, and thus opens NMS up to the * world of intelligent maps base don multiple data sources. + * + * Warning: This paradigm will change. Handlers will be expected to + * register their own callbacks for nmsData. Work in progress. + * */ /* - * Handlers. "updater" is run periodically when the handler is active, and - * "init" is run once when it's activated. */ var handler_uplinks = { - updater:uplinkUpdater, init:uplinkInit, tag:"uplink", name:"Uplink map" }; var handler_temp = { - updater:tempUpdater, init:tempInit, tag:"temp", name:"Temperature map" }; var handler_ping = { - updater:pingUpdater, init:pingInit, tag:"ping", name:"IPv4 Ping map" }; var handler_traffic = { - updater:trafficUpdater, init:trafficInit, tag:"traffic", name:"Uplink traffic map" }; var handler_traffic_tot = { - updater:trafficTotUpdater, init:trafficTotInit, tag:"traffictot", name:"Switch traffic map" }; var handler_disco = { - updater:randomizeColors, init:discoInit, tag:"disco", name:"Disco fever" }; var handler_comment = { - updater:commentUpdater, init:commentInit, tag:"comment", name:"Fresh comment spotter" @@ -79,38 +73,36 @@ var handlers = [ /* * Update function for uplink map - * Run periodically when uplink map is active. */ function uplinkUpdater() { - if (!nms.switches_now["switches"]) + if (!nmsData.switches) return; - for (sw in nms.switches_now["switches"]) { + if (!nmsData.switches.switches) + return; + if (!nmsData.switchstate) + return; + if (!nmsData.switchstate.switches) + return; + for (sw in nmsData.switches.switches) { var uplinks=0; - for (port in nms.switches_now["switches"][sw]["ports"]) { - if (!nms.switches_then["switches"][sw]["ports"] || - !nms.switches_now["switches"][sw]["ports"]) - continue; - if (/ge-0\/0\/44$/.exec(port) || - /ge-0\/0\/45$/.exec(port) || - /ge-0\/0\/46$/.exec(port) || - /ge-0\/0\/47$/.exec(port)) - { - if (parseInt(nms.switches_then["switches"][sw]["ports"][port]["ifhcoutoctets"]) != parseInt(nms.switches_now["switches"][sw]["ports"][port]["ifhcoutoctets"])) { - uplinks += 1; - } - } + if (nmsData.switchstate.switches[sw] == undefined || nmsData.switchstate.switches[sw].uplinks == undefined) { + uplinks=0; + } else { + uplinks = nmsData.switchstate.switches[sw].uplinks.live; + nuplinks = nmsData.switchstate.switches[sw].uplinks.total; } + if (uplinks == 0) { - setSwitchColor(sw,"white"); - } else if (uplinks == 1) { - setSwitchColor(sw,red); - } else if (uplinks == 2) { - setSwitchColor(sw, orange); - } else if (uplinks == 3) { - setSwitchColor(sw, green); + 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) { + nmsMap. setSwitchColor(sw, red); } else if (uplinks > 3) { - setSwitchColor(sw, blue); + nmsMap.setSwitchColor(sw, blue); } } } @@ -120,10 +112,12 @@ function uplinkUpdater() */ function uplinkInit() { + nmsData.addHandler("switches","mapHandler",uplinkUpdater); + nmsData.addHandler("switchstate","mapHandler",uplinkUpdater); setLegend(1,"white","0 uplinks"); - setLegend(2,red,"1 uplink"); - setLegend(3,orange,"2 uplinks"); - setLegend(4,green,"3 uplinks"); + setLegend(2,red,"2 missing"); + setLegend(3,orange,"1 missing"); + setLegend(4,green,"0 missing"); setLegend(5,blue,"4 uplinks"); } @@ -168,9 +162,6 @@ function trafficUpdater() } } -/* - * Init-function for uplink map - */ function trafficTotInit() { var m = 1024 * 1024 / 8; @@ -256,24 +247,20 @@ function tempInit() function pingUpdater() { - if (!nms.ping_data || !nms.ping_data["switches"]) { - resetColors(); + if (nmsData.switches == undefined || nmsData.switches.switches == undefined) { return; } - for (var sw in nms.switches_now["switches"]) { - var c = blue; - if (nms.ping_data['switches'] && nms.ping_data['switches'][sw]) - c = gradient_from_latency(nms.ping_data["switches"][sw]["latency"]); - setSwitchColor(sw, c); - } - for (var ln in nms.switches_now["linknets"]) { - var c1 = blue; - var c2 = c1; - if (nms.ping_data['linknets'] && nms.ping_data['linknets'][ln]) { - c1 = gradient_from_latency(nms.ping_data["linknets"][ln][0]); - c2 = gradient_from_latency(nms.ping_data["linknets"][ln][1]); + for (var sw in nmsData.switches.switches) { + try { + if (nmsData.ping.switches[sw].age > 0) { + c = red; + } else { + c = gradient_from_latency(nmsData.ping.switches[sw].latency); + } + nmsMap.setSwitchColor(sw, c); + } catch (e) { + nmsMap.setSwitchColor(sw, blue); } - setLinknetColors(ln, c1, c2); } } @@ -285,68 +272,88 @@ function pingInit() setLegend(3,gradient_from_latency(60),"60ms"); setLegend(4,gradient_from_latency(100),"100ms"); setLegend(5,gradient_from_latency(undefined) ,"No response"); + nmsData.addHandler("ping","mapHandler",pingUpdater); + nmsData.addHandler("switches","mapHandler",pingUpdater); + nmsData.addHandler("ticker", "mapHandler", pingUpdater); } function commentUpdater() { var realnow = Date.now(); var now = Math.floor(realnow / 1000); - for (var sw in nms.switches_now["switches"]) { + if (nmsData.comments == undefined || nmsData.comments.comments == undefined) { + return + } + for (var sw in nmsData.switches.switches) { var c = "white"; - var s = nms.switches_now["switches"][sw]; - if (s["comments"] && s["comments"].length > 0) { - var then = 0; - var active = 0; - var persist = 0; - c = "yellow"; - for (var v in s["comments"]) { - var then_test = parseInt(s["comments"][v]["time"]); - if (then_test > then && s["comments"][v]["state"] != "inactive") - then = then_test; - if (s["comments"][v]["state"] == "active") { - active++; - } - if (s["comments"][v]["state"] == "persist") - persist++; - } - if (then > (now - (60*15))) { - c = red; - } else if (active > 0) { - c = orange; - } else if (persist > 0) { - c = blue; - } else { - c = green; + if (nmsData.comments.comments[sw] == undefined) { + nmsMap.setSwitchColor(sw,c); + continue; + } + var s = nmsData.comments.comments[sw]; + var then = 0; + var active = 0; + var persist = 0; + c = "yellow"; + for (var v in s["comments"]) { + var then_test = parseInt(s["comments"][v]["time"]); + if (then_test > then && s["comments"][v]["state"] != "inactive") + then = then_test; + if (s["comments"][v]["state"] == "active") { + active++; } + if (s["comments"][v]["state"] == "persist") + persist++; + } + if (then > (now - (60*15))) { + c = red; + } else if (active > 0) { + c = orange; + } else if (persist > 0) { + c = blue; + } else { + c = green; } - setSwitchColor(sw, c); + nmsMap.setSwitchColor(sw, c); } } function commentInit() { + nmsData.addHandler("comments","mapHandler",commentUpdater); setLegend(1,"white","0 comments"); setLegend(2,blue,"Persistent"); setLegend(3,red, "New"); setLegend(4,orange,"Active"); setLegend(5,green ,"Old/inactive only"); } + /* * Testing-function to randomize colors of linknets and switches */ function randomizeColors() { - for (var i in nms.switches_now.linknets) { +/* for (var i in nms.switches_now.linknets) { setLinknetColors(i, getRandomColor(), getRandomColor()); } - for (var sw in nms.switches_now.switches) { - setSwitchColor(sw, getRandomColor()); +*/ + if (nmsData.switches == undefined || nmsData.switches.switches == undefined) { + return; + } + for (var sw in nmsData.switches.switches) { + nmsMap.setSwitchColor(sw, getRandomColor()); } } +function discoDo() { + randomizeColors(); + setTimeout(randomizeColors,500); +} function discoInit() { + nmsData.addHandler("ticker", "mapHandler", discoDo); + setNightMode(true); setLegend(1,blue,"Y"); setLegend(2,red, "M"); |