aboutsummaryrefslogtreecommitdiffstats
path: root/web/nms.gathering.org/port-state.pl
diff options
context:
space:
mode:
Diffstat (limited to 'web/nms.gathering.org/port-state.pl')
-rwxr-xr-xweb/nms.gathering.org/port-state.pl31
1 files changed, 11 insertions, 20 deletions
diff --git a/web/nms.gathering.org/port-state.pl b/web/nms.gathering.org/port-state.pl
index a7b2f05..76dd7d8 100755
--- a/web/nms.gathering.org/port-state.pl
+++ b/web/nms.gathering.org/port-state.pl
@@ -11,30 +11,20 @@ my $cgi = CGI->new;
my $dbh = nms::db_connect();
-my $switch = $cgi->param('switch');
-my @ports = split(",",$cgi->param('ports'));
my $cin = $cgi->param('time');
-my $when =" time > now() - '5m'::interval";
+my $now = "now()";
+if ($cgi->param('now') != undef) {
+ $now = "'" . $cgi->param('now') . "'::timestamp ";
+}
+
+my $when =" time > " . $now . " - '5m'::interval and time < " . $now . " ";
my %json = ();
if (defined($cin)) {
- $when = " time < now() - '$cin'::interval and time > now() - ('$cin'::interval + '15m'::interval) ";
+ $when = " time < " . $now . " - '$cin'::interval and time > ". $now . " - ('$cin'::interval + '15m'::interval) ";
}
-my $query = 'select distinct on (switch,ifname,ifhighspeed,ifhcoutoctets,ifhcinoctets) extract(epoch from date_trunc(\'second\',time)) as time,switch,ifname,max(ifhighspeed) as ifhighspeed,max(ifhcinoctets) as ifhcinoctets,max(ifhcoutoctets) as ifhcoutoctets,switch,sysname from polls natural join switches where ' . $when . ' ';
-
-my $or = "and (";
-my $last = "";
-foreach my $port (@ports) {
- $query .= "$or ifname = '$port' ";
- $or = " OR ";
- $last = ")";
-}
-$query .= "$last";
-if (defined($switch)) {
- $query .= "and sysname = '$switch'";
-}
-$query .= 'group by time,switch,ifname,ifhighspeed,ifhcinoctets,ifhcoutoctets,sysname order by switch,ifname,ifhighspeed,ifhcoutoctets,ifhcinoctets,time desc';
+my $query = 'select sysname,extract(epoch from date_trunc(\'second\',time)) as time, ifname,ifhighspeed,ifhcinoctets,ifhcoutoctets from polls natural join switches where time in (select max(time) from polls where ' . $when . ' group by switch,ifname);';
my $q = $dbh->prepare($query);
$q->execute();
@@ -48,7 +38,7 @@ while (my $ref = $q->fetchrow_hashref()) {
#print Dumper(%json);
my $q2 = $dbh->prepare('select switch,sysname,placement,zorder,ip,switchtype,poll_frequency,community,last_updated from switches natural join placements');
-my $q3 = $dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches order by switch,time desc');
+my $q3 = $dbh->prepare('select distinct on (switch) switch,temp,time,sysname from switch_temp natural join switches where ' . $when . ' order by switch,time desc');
$q2->execute();
while (my $ref = $q2->fetchrow_hashref()) {
@@ -76,7 +66,8 @@ while (my $ref = $q3->fetchrow_hashref()) {
my $q4 = $dbh->prepare(' select linknet, (select sysname from switches where switch = switch1) as sysname1, addr1, (select sysname from switches where switch = switch2) as sysname2,addr2 from linknets');
$q4->execute();
while (my $ref = $q4->fetchrow_hashref()) {
- push @{$json{'linknets'}}, $ref;
+ $json{'linknets'}{$ref->{'linknet'}} = $ref;
+# push @{$json{'linknets'}}, $ref;
}
print $cgi->header(-type=>'text/json; charset=utf-8');