Bacula + nagios + nrpe + freebsd

Key to success can be a proper script for execution, I found https://github.com/janoszen/nagios-check-bacula-jobs/blob/master/check_bacula_jobs.sh, that, did not work, so I started to search why

 

First of all, my bacula database contains of backup sets that do not exist (I have no idea why, its deleted servers), so I got 35 and not 25 jobs on:

JOBTYPES=$(echo "list jobtotals" | bconsole | grep -e '^|' | sed -e 's/|/\t/g' | sed 1d | awk ' { print $4 } ' | grep -v -e '^$')

 

 

You might want to check if you get the same output, check on a commandline on your bacula server:

echo “status director” | bconsole | grep ‘Backup’ | grep ‘^Differential\|^Incremental\|^Full’ | awk ‘ { print $6 } ‘

it should give a list of your ACTIVE server job names.

 

I did also note that the following line on FreeBSD did not work:

	LASTRUN_UNIX=$(date --date="${LASTRUN}" "+%s")

 

It might be linux related, I have no idea..

 

Lastly, this did not output the date and time of last run, but something else:

	LASTRUN=$(echo 'list jobs' | bconsole | grep -e '^|' | sed 1d | grep '| T ' | sed -e 's/|/\t/g' |grep $job | tail -n 1 | awk ' { print $3" "$4 } ')

you might want to test it on the bacula server by hand, just take this line:

echo ‘list jobs’ | bconsole | grep -e ‘^|’ | sed 1d | grep ‘| T ‘ | sed -e ‘s/|/\t/g’ |grep $job | tail -n 1 | awk ‘ { print $6″ “$7 } ‘

 

edit $job with a jobname, eg: “BackupCatalog”:

echo ‘list jobs’ | bconsole | grep -e ‘^|’ | sed 1d | grep ‘| T ‘ | sed -e ‘s/|/\t/g’ |grep BackupCatalog | tail -n 1 | awk ‘ { print $6″ “$7 } ‘

 

and it should output something like this: 2014-12-15 04:28:50

The corrected script is below, ready for inclusion on your nrpe setup, enjoy..

 

#!/usr/local/bin/bash

# we want a list of job named from this
#JOBTYPES=$(echo "status director" | bconsole | grep 'Backup' | grep 'unknown' | awk ' { print $6 } ')
JOBTYPES=$(echo "status director" | bconsole | grep 'Backup' | grep '^Differential\|^Incremental\|^Full' | awk ' { print $6 } ')
#JOBTYPES=$(echo "list jobtotals" | bconsole | grep -e '^|' | sed -e 's/|/\t/g' | sed 1d | awk ' { print $8 } ' | grep -v -e '^$')
                                                                                   
NOW=$(date +%s)                                                                    
WARN=$((2*86400))                                                                  
CRIT=$((7*86400))                                                                  
LEVEL=0                                                                            
for job in $JOBTYPES; do                                                           
        LASTRUN=$(echo 'list jobs' | bconsole | grep -e '^|' | sed 1d | grep '| T ' | sed -e 's/|/\t/g' |grep $job | tail -n 1 | awk ' { print $6" "$7 } ')
        LASTRUN_UNIX=$(date -j -f '%Y-%m-%d %H:%M:%S' "${LASTRUN}" "+%s")          
        if [ "$(($NOW - $LASTRUN_UNIX))" -gt "$WARN" ]; then                       
                if [ "$((${NOW}-${LASTRUN_UNIX}))" -gt "$CRIT" ]; then             
                        echo "Critical: job ${job} last ran successfully $((${NOW}-${LASTRUN_UNIX})) seconds ago"
                        LEVEL=2                                                    
                else                                                               
                        echo "Warning: job ${job} last ran successfully $((${NOW}-${LASTRUN_UNIX})) seconds ago"
                        if [ $LEVEL -eq 0 ]; then
                                LEVEL=1
                        fi
                fi
        fi
done

if [ $LEVEL -eq 0 ]; then
        echo "All jobs ran successfully within $WARN seconds."
fi

exit $LEVEL

 

 

 

Leave a Reply