X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=web%2Fext%2Fshowswitch.pl;h=f2851c149f2998ab05a0ad2d3186e0b346f0f199;hb=7659e82b3be35279be5c85ac83af19982ebabaa9;hp=c0150054e271d89c605af1c110cc7e50868996fe;hpb=caf1d1f41eb593fb8beec11684186fb6919a9436;p=nms
diff --git a/web/ext/showswitch.pl b/web/ext/showswitch.pl
index c015005..f2851c1 100755
--- a/web/ext/showswitch.pl
+++ b/web/ext/showswitch.pl
@@ -6,6 +6,9 @@ use POSIX ":sys_wait_h";
use strict;
use warnings;
+use lib '../../include';
+
+use nms;
use mygraph;
require 'glue.pl';
@@ -22,8 +25,7 @@ $height = 250 unless (defined($height));
my $graph = mygraph::mygraph_new($width, $height);
my $start = [Time::HiRes::gettimeofday];
-my $dbh = DBI->connect("dbi:Pg:dbname=tg", "tg", "tg06")
- or die "Couldn't connect to database";
+my $dbh = nms::db_connect();
# Fetch the name
my $ref = $dbh->selectrow_hashref('SELECT sysname FROM switches WHERE switch=?', undef, $switch);
@@ -38,7 +40,7 @@ print <<"EOF";
Switch $switch ($ref->{'sysname'})
EOF
-my $q = $dbh->prepare('select port,coalesce(description, \'Port \' || port) as description,extract(epoch from time) as time,bytes_in,bytes_out from polls natural join switches natural left join portnames where time between \'2005-03-23 05:17:36+01\' and \'2005-03-24 05:17:36+01\' and switch=? order by switch,port,time;');
+my $q = $dbh->prepare('select port,coalesce(description, \'Port \' || port) as description,extract(epoch from time) as time,bytes_in,bytes_out from polls natural join switches natural left join portnames where time between now() - \'1 day\'::interval and now() and switch=? order by switch,port,time;');
$q->execute($switch);
my (@totx, @toty1, @toty2) = ();
@@ -60,7 +62,7 @@ while (my $ref = $q->fetchrow_hashref()) {
my $in = $ref->{'bytes_in'};
my $out = $ref->{'bytes_out'};
next if ($time == $prev_time);
-
+
if ($ref->{'port'} != $last_port) {
if ($last_port != -1) {
my $filename = "$switch-$last_port-$width-$height.png";