diff options
Diffstat (limited to 'web/api/public')
-rwxr-xr-x | web/api/public/dhcp | 5 | ||||
-rwxr-xr-x | web/api/public/switch-state | 10 | ||||
-rwxr-xr-x | web/api/public/switches | 4 |
3 files changed, 13 insertions, 6 deletions
diff --git a/web/api/public/dhcp b/web/api/public/dhcp index ea42b8f..88f1eb5 100755 --- a/web/api/public/dhcp +++ b/web/api/public/dhcp @@ -14,6 +14,11 @@ while ( my $ref = $q->fetchrow_hashref() ) { my $sysname = $ref->{'sysname'}; $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; } +my $q2 = $nms::web::dbh->prepare("select sysname,count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp natural join switches where $nms::web::when group by switches.sysname;"); +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $nms::web::json{'switches'}{$ref->{sysname}} = $ref; +} $nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "30"; diff --git a/web/api/public/switch-state b/web/api/public/switch-state index 2e82836..47de6d5 100755 --- a/web/api/public/switch-state +++ b/web/api/public/switch-state @@ -22,13 +22,13 @@ while ( my $ref = $q->fetchrow_hashref() ) { if ($porti =~ m/\.0$/) { next; } - if ($data{'ports'}{$porti}{'ifAlias'} =~ m/client/) { + if ($data{'ports'}{$porti}{'ifAlias'} =~ m/client/i) { $smallport =~ s/[0-9-].*$//; } else { $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } - if ($porti =~ /Gi1\/0\/4[78]$/ || - $data{'ports'}{$porti}{'ifAlias'} =~ m/uplink/) { + if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and + $data{'ports'}{$porti}{'ifAlias'} =~ m/trunk/i) { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { @@ -71,8 +71,8 @@ while ( my $ref = $q2->fetchrow_hashref() ) { } else { $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } - if ($porti =~ /Gi1\/0\/4[78]$/ || - $data{'ports'}{$porti}{'ifAlias'} =~ m/uplink/) { + if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and + $data{'ports'}{$porti}{'ifAlias'} =~ m/trunk/i) { $json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; if ($port{'ifOperStatus'} eq "up") { diff --git a/web/api/public/switches b/web/api/public/switches index e6a37f8..ce95e5f 100755 --- a/web/api/public/switches +++ b/web/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_v6_gw,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,tags,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()) { @@ -24,6 +24,8 @@ while (my $ref = $q2->fetchrow_hashref()) { $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'width'} = $x1 - $x2; $nms::web::json{'switches'}{$ref->{'sysname'}}{'placement'}{'height'} = $y1 - $y2; $nms::web::json{'switches'}{$ref->{'sysname'}}{'distro_name'} = $ref->{'distro_name'}; + my $data = JSON::XS::decode_json($ref->{'tags'}); + $nms::web::json{'switches'}{$ref->{'sysname'}}{'tags'} = $data; } my $q4 = $nms::web::dbh->prepare('select linknet, (select sysname from switches where switch = switch1) as sysname1, (select sysname from switches where switch = switch2) as sysname2 from linknets'); |