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 /web/nms.gathering.org/api/public/switch-state | |
parent | 888e40e600f4851e62d213eb0db3122e8d72c5a5 (diff) |
NMS: Ping and uplinks work now
Getting packet loss to localhost now...
Diffstat (limited to 'web/nms.gathering.org/api/public/switch-state')
-rwxr-xr-x | web/nms.gathering.org/api/public/switch-state | 35 |
1 files changed, 7 insertions, 28 deletions
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(); |