2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01: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
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
foreach my $get ('pools', 'stats')
{
# prep and execute the show query
my $pre = $dbh->prepare("SHOW $get");
$pre->execute();
my $pre = $dbh->prepare("SHOW $get")
or die ("Cannot prepare query");
$pre->execute()
or die ("Cannot execute statement")
while (@data = $pre->fetchrow)
{
# first defines the pool