]> git.sesse.net Git - nms/blobdiff - web/showswitch.pl
Optomalize a bit more.
[nms] / web / showswitch.pl
index 7dd716c964248ab2123d22d6f13fd08ae181adca..72b18462b10e3e07098e19c7224be381b5f94fa2 100755 (executable)
@@ -5,6 +5,8 @@ use Time::HiRes;
 use POSIX ":sys_wait_h";
 use strict;
 use warnings;
+use lib '../include';
+use nms;
 my $cgi = CGI->new;
 my $switch = $cgi->param('id');
 my $width = $cgi->param('width');
@@ -18,8 +20,7 @@ $height = 250 unless (defined($height));
 require './mygraph.pl';
 
 my $start = [Time::HiRes::gettimeofday];
-my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", "snmpfetch", "removed")
-        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);
@@ -34,7 +35,7 @@ print <<"EOF";
     <h1>Switch $switch ($ref->{'sysname'})</h1>
 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 now() - \'1 day\'::interval and now() 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 switches natural left join portnames natural join polls where time between now() - \'1 day\'::interval and now() and switch=? order by switch,port,time;');
 $q->execute($switch);
 
 my (@totx, @toty1, @toty2) = ();