From 2679e59589f8338def31c4b7b5c35a365df00d05 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 29 Mar 2006 12:44:13 +0000 Subject: [PATCH] Use nms::db_connect() everywhere. --- clients/dhcptail.pl | 5 +++-- clients/smanagrun.pl | 6 +++--- clients/switchfix.pl | 8 ++++---- web/dhcpkart.pl | 5 +++-- web/nettkart-telnet.pl | 5 +++-- web/nettkart-text.pl | 5 +++-- web/nettkart-web.pl | 5 +++-- web/nettkart.pl | 5 +++-- web/overlay.pl | 5 +++-- web/portkart.pl | 5 +++-- web/showswitch.pl | 5 +++-- web/smanagement.pl | 6 +++--- web/sshow.pl | 6 +++--- web/stempmap-ptn.pl | 5 +++-- web/stempmap.pl | 5 +++-- web/tempfetch.pl | 5 +++-- 16 files changed, 49 insertions(+), 37 deletions(-) diff --git a/clients/dhcptail.pl b/clients/dhcptail.pl index 50a51b9..a1e1c62 100755 --- a/clients/dhcptail.pl +++ b/clients/dhcptail.pl @@ -1,6 +1,8 @@ #! /usr/bin/perl use DBI; use POSIX; +use lib '../include'; +use nms; use strict; use warnings; @@ -28,8 +30,7 @@ while (<>) { my $date = $year . "-" . $months{$1} . "-" . $2 . " " . $3; if (!defined($dbh) || !$dbh->ping) { - $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", "snmpfetch", "removed") - or die "Couldn't connect to database"; + $dbh = nms::db_connect(); $q = $dbh->prepare("UPDATE dhcp SET last_ack=? WHERE inet ? << network AND ( last_ack < ? OR last_ack IS NULL )") or die "Couldn't prepare query"; } diff --git a/clients/smanagrun.pl b/clients/smanagrun.pl index e66cfd2..d02d731 100755 --- a/clients/smanagrun.pl +++ b/clients/smanagrun.pl @@ -7,6 +7,8 @@ use strict; use Net::Telnet; use DBI; use POSIX; +use lib '../include'; +use nms; # Tweak and check my $password = 'removed'; @@ -14,9 +16,7 @@ my $timeout = 15; my $delaytime = 30; my $poll_frequency = 60; -my $dbh = DBI->connect("dbi:Pg:dbname=snmpfetch;host=violet.tg05.gathering.org", - "snmpfetch", "removed") - or die "Couldn't connect to database"; +my $dbh = db_connect(); $dbh->{AutoCommit} = 0; my $spoll = $dbh->prepare(" diff --git a/clients/switchfix.pl b/clients/switchfix.pl index 536e868..4329f04 100755 --- a/clients/switchfix.pl +++ b/clients/switchfix.pl @@ -4,6 +4,9 @@ use warnings; use DBI; use Getopt::Long; use LWP::UserAgent; +use lib '../include'; +use nms; + { package RequestAgent; our @ISA = qw(LWP::UserAgent); @@ -25,10 +28,7 @@ my $target_mask = $ARGV[0] ? $ARGV[0] : 'e%-%sw'; # ACTION -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(); my $sth = $dbh->prepare("SELECT sysname,ip FROM switches WHERE sysname LIKE ? ORDER BY ip"); $sth->execute($target_mask); diff --git a/web/dhcpkart.pl b/web/dhcpkart.pl index 2558fb9..e428eca 100755 --- a/web/dhcpkart.pl +++ b/web/dhcpkart.pl @@ -2,13 +2,14 @@ use CGI; use GD; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; my $greentimeout = 900; my $maxtimeout = $greentimeout*9; -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(); GD::Image->trueColor(1); $img = GD::Image->new('snmp-bg.png'); diff --git a/web/nettkart-telnet.pl b/web/nettkart-telnet.pl index fd32044..3a83539 100755 --- a/web/nettkart-telnet.pl +++ b/web/nettkart-telnet.pl @@ -1,10 +1,11 @@ #! /usr/bin/perl use CGI; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; -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(); print $cgi->header(-type=>'text/html', -refresh=>'45; http://nms.tg05.gathering.org/nettkart-telnet.pl'); print <<"EOF"; diff --git a/web/nettkart-text.pl b/web/nettkart-text.pl index 6ac1d9f..7255e58 100755 --- a/web/nettkart-text.pl +++ b/web/nettkart-text.pl @@ -1,10 +1,11 @@ #! /usr/bin/perl use CGI; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; -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(); print $cgi->header(-type=>'text/html', -refresh=>'10; http://nms.tg05.gathering.org/nettkart-text.pl'); print <<"EOF"; diff --git a/web/nettkart-web.pl b/web/nettkart-web.pl index 3da5fe5..154181f 100755 --- a/web/nettkart-web.pl +++ b/web/nettkart-web.pl @@ -1,10 +1,11 @@ #! /usr/bin/perl use CGI; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; -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(); print $cgi->header(-type=>'text/html', -refresh=>'45; http://nms.tg05.gathering.org/nettkart-web.pl'); print <<"EOF"; diff --git a/web/nettkart.pl b/web/nettkart.pl index ac88162..29499fb 100755 --- a/web/nettkart.pl +++ b/web/nettkart.pl @@ -2,10 +2,11 @@ use CGI; use GD; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; -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(); GD::Image->trueColor(1); $img = GD::Image->new('snmp-bg.png'); diff --git a/web/overlay.pl b/web/overlay.pl index 21eff19..95e9198 100755 --- a/web/overlay.pl +++ b/web/overlay.pl @@ -3,10 +3,11 @@ use GD; use LWP::Simple; use CGI; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; -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(); my $cam = $cgi->param('cam'); if (!defined($cam) || ($cam ne "1" && $cam ne "2")) { diff --git a/web/portkart.pl b/web/portkart.pl index 24a26ec..9150cef 100755 --- a/web/portkart.pl +++ b/web/portkart.pl @@ -2,10 +2,11 @@ use CGI; use GD; use DBI; +use lib '../include'; +use nms; my $cgi = CGI->new; -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(); GD::Image->trueColor(1); $img = GD::Image->new('snmp-bg.png'); diff --git a/web/showswitch.pl b/web/showswitch.pl index 7dd716c..3be8769 100755 --- a/web/showswitch.pl +++ b/web/showswitch.pl @@ -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); diff --git a/web/smanagement.pl b/web/smanagement.pl index ce270c3..e647458 100755 --- a/web/smanagement.pl +++ b/web/smanagement.pl @@ -1,4 +1,6 @@ #!/usr/bin/perl +use lib '../include'; +use nms; # # @@ -20,9 +22,7 @@ use Data::Dumper; # Grab from .htaccess-authentication my $user = $ENV{'REMOTE_USER'}; -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(); $dbh->{AutoCommit} = 0; # Ugly casting, found not other way diff --git a/web/sshow.pl b/web/sshow.pl index 32a8306..a16da77 100755 --- a/web/sshow.pl +++ b/web/sshow.pl @@ -1,4 +1,6 @@ #!/usr/bin/perl +use lib '../include'; +use nms; # # @@ -18,9 +20,7 @@ use DBI; # Grab from .htaccess-authentication my $user = $ENV{'REMOTE_USER'}; -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(); $dbh->{AutoCommit} = 0; my $sgetdone = $dbh->prepare( diff --git a/web/stempmap-ptn.pl b/web/stempmap-ptn.pl index 3522b51..a1fc55a 100755 --- a/web/stempmap-ptn.pl +++ b/web/stempmap-ptn.pl @@ -1,4 +1,6 @@ #!/usr/bin/perl +use lib '../include'; +use nms; # # @@ -11,8 +13,7 @@ use warnings; my $img = GD::Image->new('stemp-bg5.png'); my $cgi = CGI->new; -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(); my $black = $img->colorAllocate(0,0,0); my $white = $img->colorAllocate(255,255,255); diff --git a/web/stempmap.pl b/web/stempmap.pl index b2df70b..fcfd32c 100755 --- a/web/stempmap.pl +++ b/web/stempmap.pl @@ -5,6 +5,8 @@ use CGI; use GD; use DBI; +use lib '../include'; +use nms; use strict; use warnings; @@ -14,8 +16,7 @@ my $img = GD::Image->new('snmp-bg.png'); #my $img = GD::Image->new(100,100); my $cgi = CGI->new; -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(); my $sgetpoll = $dbh->prepare('select switch,(select temp from temppoll where switches.switch=temppoll.switch AND temp != 0 order by id desc limit 1) AS temp,placement from switches natural join placements'); diff --git a/web/tempfetch.pl b/web/tempfetch.pl index eed5417..3a5c84d 100644 --- a/web/tempfetch.pl +++ b/web/tempfetch.pl @@ -5,6 +5,8 @@ use DBI; use Net::Telnet; use POSIX; use Time::HiRes; +use lib '../include'; +use nms; use strict; use warnings; #require 'SNMP_Session.pm'; @@ -14,8 +16,7 @@ my $password = 'removed'; my $timeout = 25; my $location = 'skipet'; -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(); $dbh->{AutoCommit} = 0; my $qswitch = $dbh->prepare(<<"EOF") -- 2.39.2