diff options
author | Kristian Lyngstol <kly@kly.no> | 2016-03-16 23:46:27 +0000 |
---|---|---|
committer | Kristian Lyngstol <kly@kly.no> | 2016-03-16 23:46:27 +0000 |
commit | 319112d0ae89d689426441f2d6f353015d66edf9 (patch) | |
tree | 89383bd31411750e0d2178dc9853eedd1ce41c6a | |
parent | 888e40e600f4851e62d213eb0db3122e8d72c5a5 (diff) |
NMS: Ping and uplinks work now
Getting packet loss to localhost now...
-rwxr-xr-x | clients/ping.pl | 8 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/switch-state | 35 | ||||
-rw-r--r-- | web/nms.gathering.org/js/nms-map-handlers.js | 54 |
3 files changed, 41 insertions, 56 deletions
diff --git a/clients/ping.pl b/clients/ping.pl index 93d759f..78fb515 100755 --- a/clients/ping.pl +++ b/clients/ping.pl @@ -5,6 +5,7 @@ use Time::HiRes; use Net::Oping; use strict; use warnings; +use Data::Dumper; use lib '../include'; use nms; @@ -38,17 +39,22 @@ while (1) { } } my $result = $ping->ping(); + my %dropped = %{$ping->get_dropped()}; die $ping->get_error if (!defined($result)); $dbh->do('COPY ping (switch, latency_ms) FROM STDIN'); # date is implicitly now. + my $drops = 0; while (my ($ip, $latency) = each %$result) { my $switch = $ip_to_switch{$ip}; next if (!defined($switch)); + if (!defined($latency)) { + $drops += $dropped{$ip}; + } $latency //= "\\N"; - $latency*=1000; $dbh->pg_putcopydata("$switch\t$latency\n"); } + print "Dropped: $drops\n"; $dbh->pg_putcopyend(); $dbh->do('COPY ping_secondary_ip (switch, latency_ms) FROM STDIN'); # date is implicitly now. diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index cd9c0d2..38f4c57 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -17,6 +17,8 @@ while (my $ref = $q->fetchrow_hashref()) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; + my $smallport = $porti; + $smallport =~ s/[0-9-].*$//; if ($porti =~ /ge-0\/0\/4[4-7]/ or $porti eq 'eth0') { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; @@ -25,39 +27,16 @@ while (my $ref = $q->fetchrow_hashref()) { } $json{'switches'}{$sysname}{'uplinks'}{'total'} += 1; } - $json{'switches'}{$sysname}{'ifHCInOctets'} += $port{'ifHCInOctets'}; - $json{'switches'}{$sysname}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; + + $json{'switches'}{$sysname}{$smallport}{'ifHCInOctets'} += $port{'ifHCInOctets'}; + $json{'switches'}{$sysname}{$smallport}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { - $json{'switches'}{$sysname}{'live'} += 1; + $json{'switches'}{$sysname}{$smallport}{'live'} += 1; } - $json{'switches'}{$sysname}{'total'} += 1; + $json{'switches'}{$sysname}{$smallport}{'total'} += 1; } $json{'switches'}{$sysname}{'time'} = $ref->{'time'}; } - -finalize_output(); -exit; -$q->execute(); - -while (my $ref = $q->fetchrow_hashref()) { - my @fields = ('ifhcoutoctets','ifhcinoctets'); - foreach my $val (@fields) { - if ($ref->{'ifname'} =~ /ge-0\/0\/4[4-7]/) { - $nms::web::json{'switches'}{$ref->{'sysname'}}{'uplinks'}{$val} += $ref->{$val}; - } - $nms::web::json{'switches'}{$ref->{'sysname'}}{'total'}{$val} += $ref->{$val}; - } - $nms::web::json{'switches'}{$ref->{'sysname'}}{'time'} += $ref->{'time'}; -} - -my $q3 = $nms::web::dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $nms::web::when . ' order by switch,time desc'); - -$q3->execute(); -while (my $ref = $q3->fetchrow_hashref()) { - my $sysname = $ref->{'sysname'}; - $nms::web::json{'switches'}{$ref->{'sysname'}}{'temp'} = $ref->{'temp'}; -} - $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; finalize_output(); diff --git a/web/nms.gathering.org/js/nms-map-handlers.js b/web/nms.gathering.org/js/nms-map-handlers.js index e6b9103..f5bf9d5 100644 --- a/web/nms.gathering.org/js/nms-map-handlers.js +++ b/web/nms.gathering.org/js/nms-map-handlers.js @@ -73,38 +73,36 @@ var handlers = [ /* * Update function for uplink map - * Run periodically when uplink map is active. */ function uplinkUpdater() { - if (!nmsData.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); } } } @@ -114,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"); } |