Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
check_bacula.pl
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
The plugin takes 2 arguments for both warning (-w) and critical (-c) limits and returns the according code if any of the limits is not met. The check is done within past n-hours period (-H). Every backup-job (-j) needs a separate check. Plugin has also possibilities to check the required minimal number of errors (-e), BeforeJob (-b) and AfterJob (-a) scripts statuses.
In case critical limit is 1, the script can query number of running jobs and return warning in case there are any.
Script is configured to use MySQL database by default, but can be adjusted to something else - $dsn needs to be changed accordingly.
It's also necessary to put correct parameters of SQL-access into the script, so it's critical to restrict permissions of the script too!
The script uses other perl modules to access database, so according module has to be installed too, eg. p5-DBD-mysql (with all its dependencies).
Sample usage: ./check_bacula.pl -H 24 -w 2 -c 1 -e 0 -a -b -r -j my-backupjob
In case critical limit is 1, the script can query number of running jobs and return warning in case there are any.
Script is configured to use MySQL database by default, but can be adjusted to something else - $dsn needs to be changed accordingly.
It's also necessary to put correct parameters of SQL-access into the script, so it's critical to restrict permissions of the script too!
The script uses other perl modules to access database, so according module has to be installed too, eg. p5-DBD-mysql (with all its dependencies).
Sample usage: ./check_bacula.pl -H 24 -w 2 -c 1 -e 0 -a -b -r -j my-backupjob
Reviews (5)
byadalle, July 15, 2015
I have this working well with Postgres. A couple minor changes from the previous suggested changes:
$sql_query = "SELECT SUM(JobErrors) AS errors, COUNT(*) AS count, Job.JobId, Job.JobStatus, Log.LogText FROM Job LEFT JOIN Log on Job.JobId = Log.JobId WHERE (Name='$opt_job') AND (JobStatus='T') AND (EndTime IS NOT NULL) AND ((EndTime >= '$date_stop')) GROUP BY Job.JobId, Job.JobStatus, Log.LogText;";
(EndTime >= as opposed to =)
When there isn't a match, you don't get an array of 0's or nulls, but just an empty array.
So I check for that:
if ($#job_stats == -1)
{
@job_stats = (0,0,0,0)
}
This is the easiest fix; the rest of the code expects that array to exist, so I just set it to zeroes.
$sql_query = "SELECT SUM(JobErrors) AS errors, COUNT(*) AS count, Job.JobId, Job.JobStatus, Log.LogText FROM Job LEFT JOIN Log on Job.JobId = Log.JobId WHERE (Name='$opt_job') AND (JobStatus='T') AND (EndTime IS NOT NULL) AND ((EndTime >= '$date_stop')) GROUP BY Job.JobId, Job.JobStatus, Log.LogText;";
(EndTime >= as opposed to =)
When there isn't a match, you don't get an array of 0's or nulls, but just an empty array.
So I check for that:
if ($#job_stats == -1)
{
@job_stats = (0,0,0,0)
}
This is the easiest fix; the rest of the code expects that array to exist, so I just set it to zeroes.
byah6003, June 3, 2014
Hello bockfot2000, in my case: The Log Tables are empty. I tried bacula 5.2.6 and 7.0.3 on Debian Wheezy.
i applied you changes, but i get this:
Use of uninitialized value $count in numeric lt (oncatenation (.) or string at /usr/lib/nagios/plugins/check_bacula.pl line 229.
Bacula CRITICAL: Found successful jobs
i applied you changes, but i get this:
Use of uninitialized value $count in numeric lt (oncatenation (.) or string at /usr/lib/nagios/plugins/check_bacula.pl line 229.
Bacula CRITICAL: Found successful jobs
Below is a patch to make the script working with a PostgreSQL backend, and a quick-fix for instances where query returns 0E0:
+ my $dsn = "DBI:Pg:database=$sqlDB;host=localhost";
+ $sql_query = "SELECT SUM(JobErrors) AS errors, COUNT(*) AS count, Job.JobId, Job.JobStatus, Log.LogText
+ FROM Job LEFT JOIN Log on Job.JobId = Log.JobId
+ WHERE (Name='$opt_job') AND (JobStatus='T') AND (EndTime IS NOT NULL)
+ AND ((EndTime = '$date_stop'))
+ GROUP BY Job.JobId, Job.JobStatus, Log.LogText;";
- my @job_stats = sql_exec();
+ my $sth = $dbh->prepare($sql_query);
+ my $rv = $sth->execute() or die "Error executing query: '$sql_query': $DBI::errstr\n";
+ if ($rv fetchrow_array();
+ $errors = $job_stats[0];
+ $count = $job_stats[1];
+ $jobid = $job_stats[2];
+ $joblog = $job_stats[3];
+ }
+ my $dsn = "DBI:Pg:database=$sqlDB;host=localhost";
+ $sql_query = "SELECT SUM(JobErrors) AS errors, COUNT(*) AS count, Job.JobId, Job.JobStatus, Log.LogText
+ FROM Job LEFT JOIN Log on Job.JobId = Log.JobId
+ WHERE (Name='$opt_job') AND (JobStatus='T') AND (EndTime IS NOT NULL)
+ AND ((EndTime = '$date_stop'))
+ GROUP BY Job.JobId, Job.JobStatus, Log.LogText;";
- my @job_stats = sql_exec();
+ my $sth = $dbh->prepare($sql_query);
+ my $rv = $sth->execute() or die "Error executing query: '$sql_query': $DBI::errstr\n";
+ if ($rv fetchrow_array();
+ $errors = $job_stats[0];
+ $count = $job_stats[1];
+ $jobid = $job_stats[2];
+ $joblog = $job_stats[3];
+ }
On our bacula Version
Version: 5.0.0 (26 January 2010)
in the mysql Database each line of the log messages is stored in a new row. This leads to confusion with the sql_query in check_bacula.pl, as it is joined with the Log table of the bacula database, resulting in returning a wrong number of successful jobs.
Here is the patch file we created:
check_bacula.patch
--------------------------------------------------
***************
*** 181,187 ****
}
$date_start = get_now();
! $sql_query = "SELECT SUM(JobErrors) AS 'errors', COUNT(*) AS 'count', Job.JobId, Job.JobStatus, Log.LogText FROM Job LEFT JOIN Log on Job.JobId = Log.JobId WHERE (Name='$opt_job') AND (JobStatus='T') AND (EndTime '') AND ((EndTime = '$date_stop'));";
my @job_stats = sql_exec();
$errors = $job_stats[0];
$count = $job_stats[1];
--- 181,205 ----
}
$date_start = get_now();
! $sql_query = "
! SELECT
! SUM(JobErrors) AS 'errors',
! COUNT(*) AS 'count',
! j.JobId,
! j.JobStatus,
! l.LogText
! FROM
! Job j LEFT JOIN Log l on j.JobId = l.JobId and l.LogId = (
! select max(logid)
! from bacula.Log l2
! where l2.jobid = j.jobid
! )
! WHERE
! (Name='$opt_job')
! AND (JobStatus='T')
! AND (EndTime '')
! AND (EndTime = '$date_stop'); ";
my @job_stats = sql_exec();
$errors = $job_stats[0];
$count = $job_stats[1];
--------------------------------------------------
Version: 5.0.0 (26 January 2010)
in the mysql Database each line of the log messages is stored in a new row. This leads to confusion with the sql_query in check_bacula.pl, as it is joined with the Log table of the bacula database, resulting in returning a wrong number of successful jobs.
Here is the patch file we created:
check_bacula.patch
--------------------------------------------------
***************
*** 181,187 ****
}
$date_start = get_now();
! $sql_query = "SELECT SUM(JobErrors) AS 'errors', COUNT(*) AS 'count', Job.JobId, Job.JobStatus, Log.LogText FROM Job LEFT JOIN Log on Job.JobId = Log.JobId WHERE (Name='$opt_job') AND (JobStatus='T') AND (EndTime '') AND ((EndTime = '$date_stop'));";
my @job_stats = sql_exec();
$errors = $job_stats[0];
$count = $job_stats[1];
--- 181,205 ----
}
$date_start = get_now();
! $sql_query = "
! SELECT
! SUM(JobErrors) AS 'errors',
! COUNT(*) AS 'count',
! j.JobId,
! j.JobStatus,
! l.LogText
! FROM
! Job j LEFT JOIN Log l on j.JobId = l.JobId and l.LogId = (
! select max(logid)
! from bacula.Log l2
! where l2.jobid = j.jobid
! )
! WHERE
! (Name='$opt_job')
! AND (JobStatus='T')
! AND (EndTime '')
! AND (EndTime = '$date_stop'); ";
my @job_stats = sql_exec();
$errors = $job_stats[0];
$count = $job_stats[1];
--------------------------------------------------
byshockwavecs, March 19, 2013
Hey,
thanks for the plugin. I'm tryingto use this with postgres. I installed perl-DBD-Pg.x86_64 package and changed the dsn to be Pg. It complains about bad password. There is currently no password as configured by bacula itself. Any idea how to circumvent this? the postgres -w command is used for no password. I'm just unsure how this translates to being fired off from the perl script.
Any help would be excellent!
justinedmands@gmail.com
thanks for the plugin. I'm tryingto use this with postgres. I installed perl-DBD-Pg.x86_64 package and changed the dsn to be Pg. It complains about bad password. There is currently no password as configured by bacula itself. Any idea how to circumvent this? the postgres -w command is used for no password. I'm just unsure how this translates to being fired off from the perl script.
Any help would be excellent!
justinedmands@gmail.com
Owner's reply
Sorry, I've not used it with Postgres, so I can't advise you on that.