aboutsummaryrefslogtreecommitdiffstats
path: root/web/api
diff options
context:
space:
mode:
Diffstat (limited to 'web/api')
-rwxr-xr-xweb/api/public/dhcp5
-rwxr-xr-xweb/api/public/switch-state10
-rwxr-xr-xweb/api/public/switches4
-rwxr-xr-xweb/api/write/switch-update7
4 files changed, 18 insertions, 8 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');
diff --git a/web/api/write/switch-update b/web/api/write/switch-update
index 15b85ae..797a14b 100755
--- a/web/api/write/switch-update
+++ b/web/api/write/switch-update
@@ -23,7 +23,7 @@ my @dups;
my $sth = $nms::web::dbh->prepare("SELECT sysname FROM switches WHERE sysname=?");
-my @fields = ( 'community', 'current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan');
+my @fields = ( 'community', 'tags','current_mac', 'distro_name', 'distro_phy_port', 'lldp_chassis_id', 'mgmt_v4_addr', 'mgmt_v4_gw', 'mgmt_v4_netsize', 'mgmt_v6_addr', 'mgmt_v6_gw', 'mgmt_v6_netsize', 'mgmt_vlan', 'placement', 'poll_frequency', 'subnet4', 'subnet6', 'switchtype', 'sysname', 'traffic_vlan');
sub convertplace
{
@@ -82,7 +82,7 @@ foreach my $tmp2 (@tmp) {
} keys %switch;
- $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});");
+ $nms::web::dbh->do("INSERT INTO SWITCHES (ip, sysname, last_updated, locked, poll_frequency, tags, community, lldp_chassis_id, secondary_ip, placement,subnet4,subnet6,distro) VALUES ($template{'ip'}, $template{'sysname'}, $template{'last_updated'}, $template{'locked'}, $template{'poll_frequency'}, $template{'tags'}, $template{'community'}, $template{'lldp_chassis_id'}, $template{'secondary_ip'}, $template{'placement'},$template{'subnet4'},$template{'subnet6'},$template{'distro'});");
push @added, $switch{'sysname'};
} else {
if (defined($switch{'placement'})) {
@@ -100,6 +100,9 @@ foreach my $tmp2 (@tmp) {
$switch{'placement'} = "(($x1,$y1),($x2,$y2))";
push @dups, "not really, but: " . $switch{'placement'};
}
+ if (defined($switch{'tags'})) {
+ $switch{'tags'} =~ s/'/"/g;
+ }
if (not defined($switch{'ip'}) and defined($switch{'mgtmt4'})) {
$switch{'ip'} = $switch{'mgtmt4'};
}