Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me
Don't miss your chance to attend the 2014 Nagios World conference!

Don't miss your chance to attend the 2014 Nagios World Conference, Oct 13-16th. Informative Sessions, Networking, Food and Cocktails! Visit go.nagios.com/conference/ for more information or to register.


check_bacula.pl

Bookmark and Share

Rating
5 votes
Favoured:
1
Current Version
0.3.1
Last Release Date
2013-10-10
Compatible With
  • Nagios 1.x
  • Nagios 2.x
  • Nagios 3.x
Owner
License
GPL
Hits
78873
Files:
FileDescription
check_bacula.plcheck_bacula.pl
The script queries Bacula database for number of successful or still running backups of a given job. It's also possible to query number of errors of the job's instances and check errors of BeforeJob and AfterJob scripts.
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
Reviews (4)
bybockfot2000, March 17, 2014
1 of 1 people found this review helpful
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];
+ }
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
bysvarco, January 7, 2014
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];
--------------------------------------------------
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
Owner's reply

Sorry, I've not used it with Postgres, so I can't advise you on that.