diff options
Diffstat (limited to 'web/api/public/switch-state')
-rwxr-xr-x | web/api/public/switch-state | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/web/api/public/switch-state b/web/api/public/switch-state index 965e881..528bf7d 100755 --- a/web/api/public/switch-state +++ b/web/api/public/switch-state @@ -7,17 +7,19 @@ use strict; use warnings; use Data::Dumper; -my $target = $ENV{REQUEST_URI}; -$target =~ s/$ENV{SCRIPT_NAME}//; -$target =~ s/^\///; -my ($switch, $port) = split(/\//,$target,2); +#my $target = $ENV{REQUEST_URI}; +#$target =~ s/$ENV{SCRIPT_NAME}//; +#$target =~ s/^\///; +#my ($switch, $port) = split(/\//,$target,2); +my $port; +my $switch; my $q; -if (!defined($switch)) { - $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . ' and switches.deleted = false group by switch);'); -} else { - $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch) and sysname = ' . $nms::web::dbh->quote($switch) . ' and switches.deleted = false;'); -} +#if (!defined($switch)) { + $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . ' group by switch) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];'); +#} else { +# $q = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch) and sysname = ' . $nms::web::dbh->quote($switch) . ';'); +#} $q->execute(); while ( my $ref = $q->fetchrow_hashref() ) { @@ -42,7 +44,7 @@ while ( my $ref = $q->fetchrow_hashref() ) { $json{'switches'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and - $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) { + $data{'ports'}{$porti}{'ifAlias'} =~ m/Fysisk/i) { if ($port{'ifAdminStatus'} eq "up") { $json{'switches'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'switches'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; @@ -83,9 +85,9 @@ while ( my $ref = $q->fetchrow_hashref() ) { nms::web::setwhen('15m','10m'); my $q2; if (!defined($switch)) { - $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch);'); + $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . ' group by switch) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'];'); } else { - $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch) and sysname = ' . $nms::web::dbh->quote($switch) . ';'); + $q2 = $nms::web::dbh->prepare('select sysname,extract(epoch from date_trunc(\'second\',time)) as time,data from snmp natural join switches where id in (select max(id) from snmp where ' . $nms::web::when . 'group by switch) and switches.deleted = \'f\' and not switches.tags \?& array[\'ignoreswitchstate\'] and sysname = ' . $nms::web::dbh->quote($switch) . ';'); } $q2->execute(); @@ -109,7 +111,7 @@ while ( my $ref = $q2->fetchrow_hashref() ) { $json{'then'}{$sysname}{ifs}{$smallport}{'ifAlias'} = $port{'ifAlias'}; } if ($data{'ports'}{$porti}{'ifType'} ne "propVirtual" and - $data{'ports'}{$porti}{'ifAlias'} =~ m/LAG member/i) { + $data{'ports'}{$porti}{'ifAlias'} =~ m/Fysisk/i) { if ($port{'ifAdminStatus'} eq "up") { $json{'then'}{$sysname}{'uplinks'}{'ifHCInOctets'} += $port{'ifHCInOctets'}; $json{'then'}{$sysname}{'uplinks'}{'ifHCOutOctets'} += $port{'ifHCOutOctets'}; |