1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

die commands if no DB connection can be made

graceful die script if DB connection cannot be created. Also for
prepare & execute command
This commit is contained in:
Clemens Schwaighofer 2012-03-14 17:26:15 +09:00
parent 647632f7af
commit 6facd3c331

View file

@ -157,13 +157,16 @@ if (defined($ARGV[0]))
} }
# connect to data # connect to data
my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass); my $dbh = DBI->connect("DBI:Pg:dbname=$db_name;host=$db_host;port=$db_port", $db_user, $db_pass)
or die ("Cannot connect to database");
# go trough each set and get the data # go trough each set and get the data
foreach my $get ('pools', 'stats') foreach my $get ('pools', 'stats')
{ {
# prep and execute the show query # prep and execute the show query
my $pre = $dbh->prepare("SHOW $get"); my $pre = $dbh->prepare("SHOW $get")
$pre->execute(); or die ("Cannot prepare query");
$pre->execute()
or die ("Cannot execute statement")
while (@data = $pre->fetchrow) while (@data = $pre->fetchrow)
{ {
# first defines the pool # first defines the pool