#!/bin/sh ###### ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION # To run this script you have to set hfaxd.conf JobFormat like this # JobFmt: "%-3j %3i %1a %6.6o %-12.12e %5P %5D %7z %Y %.25s" ###### ATTENTION ATTENTION ATTENTION ATTENTION ATTENTION # # # Another Plugin for Nagios to monitor the hylafax-queue # Written by T. Bruentjen (alte-schlonte at gmx dot com) # Date: 2007/12/06 # # Usage: ./check_faxq - - # # Output: # This plugin gives a number of faxes with errors # # Exit Codes: # 0 OK The number of faxes in the queue are under the warning # or under the critical threshold # 1 Warning Number of faxes with errors in the queue above "warning" threshold # 2 Critical Number of faxes with errors in the queue above "critical" threshold # 3 Unknown One of the needed services are not running e.g. hfaxd,faxgetty,faxq # #CUSTOM VARIABLES TEMPDIR=/tmp #PARTIAL CUSTOM PART - CHECK IF HYLAFAX RUNS (depens on using Modem or CAPI) #Unset the checks for modems or customize to fit your needs #(Personally i prefer modems or cards which emulate them) modems=8 modem_count=0 daemon_count=0 spool_count=0 for i in `ps -e|grep fax` do case "$i" in "faxgetty") modem_count=$((modem_count+1));; "hfaxd") daemon_count=$((daemon_count+1));; "faxq") spool_count=$((spool_count+1));; esac done if [ $modem_count -ne $modems ] then echo $modem_count" faxgettys running instead of "$modems exit 3 #Unknown fi if [ $daemon_count -ne 1 ] then echo $daemon_count" hfaxd running instead of 1" exit 3 #Unknown fi if [ $spool_count -ne 1 ] then echo $spool_count" Queue daemons running instead of 1" exit 3 #Unknown fi #NON CUSTOM PART - check for Parameters if [ "X$1" == "X" ] || [ "X$2" == "X" ] then echo "Usage: check_faxq W C" echo " W=Warning Level - Number of failed Faxes" echo " C=Critical Level - Number of failed Faxes" exit 128 fi warn_level=$1 crit_level=$2 #NON CUSTUM NAGIOS PART OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3 #NON CUSTOM CHECK PART local_day=`date +%d` local_month=`date +%m` file=`tempfile -d $TEMPDIR` /usr/bin/faxstat -s -d > $file filelength=`wc -l $file|cut -d' ' -f1` counter=1 qcount=1 ecount=0 #Initial Setting of Queue Name queue="SENDQ" while [ $counter -le $filelength ] do sed_arg='sed -n '$counter'p '$file line=`$sed_arg` row1=`echo $line|cut -d' ' -f1` #Check what the line looks like, either System or Message case "$row1" in "HylaFAX") ;; "Modem") ;; "JID") ;; "") qcount=$((qcount+1)) if [ $qcount -gt 2 ] then #Change the Queue queue="DONEQ" fi;; *) line=`echo $line | tr -s [:space:]` jobid=`echo $line|cut -d' ' -f1` priority=`echo $line|cut -d' ' -f2` jobstat=`echo $line|cut -d' ' -f3` owner=`echo $line|cut -d' ' -f4` number=`echo $line|cut -d' ' -f5` pages=`echo $line|cut -d' ' -f6` tries=`echo $line|cut -d' ' -f7` date=`echo $line|cut -d' ' -f8` time=`echo $line|cut -d' ' -f9` error=`echo $line|cut -d' ' -f10` error=`echo $error|tr -d [:space:]` if [ "X$error" != "X" ] then old_error=$error error=${line##* $error} error_day=`echo $date|cut -d'/' -f3` error_month=`echo $date|cut -d'/' -f2` if [ $error_day -eq $local_day ] && [ $error_month -eq $local_month ] then echo -n $jobid" "$number" "$old_error$error" " #Count Errors for checking ecount=$((ecount+1)) fi fi;; esac #++ counter=$((counter+1)) done #Delete the temp file rm $file #Now get the state if [ $ecount -ge $crit_level ] then local_state=$CRITICAL else if [ $ecount -ge $warn_level ] then local_state=$WARNING else echo "Everything looks allright" local_state=$OK fi fi #Get the status back to nagios exit $local_state