diff options
author | Kristian Lyngstol <kly@kly@.no> | 2016-03-23 00:38:49 +0100 |
---|---|---|
committer | Kristian Lyngstol <kly@kly@.no> | 2016-03-23 00:38:49 +0100 |
commit | 7b5eee1f23bb66a6de8484c4ff5ad5b2021915ea (patch) | |
tree | 68a402f3bb16aaac57595e0ccf1c980ffc2f379f | |
parent | 348d197899f37e535feefd5055ae8ef553a71bdf (diff) |
NMS: Remove netsize and add traffic
Not perfect, but getting closer
-rwxr-xr-x | web/nms.gathering.org/api/public/switches | 2 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/read/switches-management | 2 | ||||
-rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 60 |
3 files changed, 31 insertions, 33 deletions
diff --git a/web/nms.gathering.org/api/public/switches b/web/nms.gathering.org/api/public/switches index 72c77be..890b7d7 100755 --- a/web/nms.gathering.org/api/public/switches +++ b/web/nms.gathering.org/api/public/switches @@ -12,7 +12,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; -my $q2 = $nms::web::dbh->prepare('select switch,sysname,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,distro_name,placement,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,community,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/api/read/switches-management b/web/nms.gathering.org/api/read/switches-management index 1bb4c4c..7697671 100755 --- a/web/nms.gathering.org/api/read/switches-management +++ b/web/nms.gathering.org/api/read/switches-management @@ -13,7 +13,7 @@ use Data::Dumper; $nms::web::cc{'max-age'} = "60"; #my $q2 = $nms::web::dbh->prepare('select sysname,ip,poll_frequency,subnet4,subnet6,distro,last_updated from switches '); -my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v4_netsize,mgmt_v6_gw,mgmt_v6_netsize,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); +my $q2 = $nms::web::dbh->prepare('select switch,sysname,mgmt_v4_addr,mgmt_v6_addr,mgmt_v4_gw,mgmt_v6_gw,mgmt_vlan,traffic_vlan,last_config_fetch,current_mac,poll_frequency,last_updated,switchtype from switches where placement is not null'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index dac630a..82d0c4a 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -133,6 +133,8 @@ function uplinkInit() */ function trafficInit() { + nmsData.addHandler("switches","mapHandler",trafficUpdater); + nmsData.addHandler("switchstate","mapHandler",trafficUpdater); var m = 1024 * 1024 / 8; drawGradient([lightgreen,green,orange,red]); setLegend(1,colorFromSpeed(0),"0 (N/A)"); @@ -144,33 +146,28 @@ function trafficInit() function trafficUpdater() { - if (!nms.switches_now["switches"]) + if (!nmsData.switchstate.switches || !nmsData.switchstate.then) return; - for (var sw in nms.switches_now["switches"]) { + for (var sw in nmsData.switchstate.switches) { var speed = 0; - 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) || - /ge-0\/0\/47$/.exec(port)) - { - if (!nms.switches_then["switches"][sw] || - !nms.switches_then["switches"][sw]["ports"] || - !nms.switches_then["switches"][sw]["ports"][port]) - continue; - var t = nms.switches_then["switches"][sw]["ports"][port]; - var n = nms.switches_now["switches"][sw]["ports"][port]; - speed += (parseInt(t["ifhcoutoctets"]) -parseInt(n["ifhcoutoctets"])) / (parseInt(t["time"] - n["time"])); - speed += (parseInt(t["ifhcinoctets"]) -parseInt(n["ifhcinoctets"])) / (parseInt(t["time"] - n["time"])); - } - } + try { + var t = parseInt(nmsData.switchstate.then[sw].uplinks.ifHCOutOctets); + var n = parseInt(nmsData.switchstate.switches[sw].uplinks.ifHCOutOctets); + var tt = parseInt(nmsData.switchstate.then[sw].time); + var nt = parseInt(nmsData.switchstate.switches[sw].time); + } catch (e) { continue;}; + var tdiff = nt - tt; + var diff = n - t; + speed = diff / tdiff; if(!isNaN(speed)) - setSwitchColor(sw,colorFromSpeed(speed)); + nmsMap.setSwitchColor(sw,colorFromSpeed(speed)); } } function trafficTotInit() { + nmsData.addHandler("switches","mapHandler",trafficTotUpdater); + nmsData.addHandler("switchstate","mapHandler",trafficTotUpdater); var m = 1024 * 1024 / 8; drawGradient([lightgreen,green,orange,red]); setLegend(1,colorFromSpeed(0),"0 (N/A)"); @@ -182,20 +179,21 @@ function trafficTotInit() function trafficTotUpdater() { - if (!nms.switches_now["switches"]) + if (!nmsData.switchstate.switches || !nmsData.switchstate.then) return; - for (var sw in nms.switches_now["switches"]) { + for (var sw in nmsData.switchstate.switches) { var speed = 0; - 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]) - continue; - var t = nms.switches_then["switches"][sw]["ports"][port]; - var n = nms.switches_now["switches"][sw]["ports"][port]; - speed += (parseInt(t["ifhcoutoctets"]) -parseInt(n["ifhcoutoctets"])) / (parseInt(t["time"] - n["time"])); - } - setSwitchColor(sw,colorFromSpeed(speed,5)); + try { + var t = parseInt(nmsData.switchstate.then[sw].totals.ifHCOutOctets); + var n = parseInt(nmsData.switchstate.switches[sw].totals.ifHCOutOctets); + var tt = parseInt(nmsData.switchstate.then[sw].time); + var nt = parseInt(nmsData.switchstate.switches[sw].time); + } catch (e) { continue;}; + var tdiff = nt - tt; + var diff = n - t; + speed = diff / tdiff; + if(!isNaN(speed)) + nmsMap.setSwitchColor(sw,colorFromSpeed(speed)); } } |