D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
lib64
/
nagios
/
plugins
/
nccustom
/
Filename :
check_postfix_queue.sh
back
Copy
#!/bin/bash # Auteur : Belgotux # Site : www.monlinux.net # Licence : CC-BY-NC-SA # Version : 1.0 # Date : 21/08/18 # changelog # v1.0 check different postfix queue # example : command[check_mailqueue]=/usr/lib/nagios/plugins/check_postfix_queue.sh --wa 100 --ca 500 --wd 500 --cd 1000 --wo 1 --co 100 # # Updated by Bogdan Kukharskiy (added queue_req warning and critical options, removed queue_size kB from output, ignored corrupted and bounced in final step) # #possibles states STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 #default options postfix_dir=/var/spool/postfix warning_queue_req=1500 critical_queue_req=2000 warning_active=500 critical_active=1000 warning_deferred=1000 critical_deferred=1500 warning_other=1000 critical_other=1500 function usage { echo "$0 [--dir|-d postfix_dir] [--wq|-w warning_queue_req] [--cq|-c critical_queue_req] [--wa warning_active] [--ca critical_active] [--wd warning_deferred] [--cd critical_deferred] [--wo warning_other] [--co critical_other] [--dc docker_container]" 1>&2 } if [ -z $# ]; then echo "Error : need argument!" 1>&2 usage exit $STATE_UNKNOWN fi while test -n "$1"; do case "$1" in --dir|-d ) postfix_dir=$2 shift;; --wq|-w ) warning_queue_req=$2 shift;; --cq|-c ) critical_queue_req=$2 shift;; --wa ) warning_active=$2 shift;; --ca ) critical_active=$2 shift;; --wd ) warning_deferred=$2 shift;; --cd ) critical_deferred=$2 shift;; --wo ) warning_other=$2 shift;; --co ) warning_other=$2 shift;; --dc ) docker_container=$2 shift;; *) echo "Wrong arguments!" 1>&2 usage exit $STATE_UNKNOWN ;; esac shift done # pre-command definition if container name is specified if [ "$docker_container" ]; then docker_command="/usr/bin/docker container exec -i $docker_container" queue=$($docker_command /usr/bin/mailq | tail -n 1) else docker_command="" queue=$(/usr/bin/mailq | tail -n 1) fi # queue empty = ok if [ "$queue" == "Mail queue is empty" ] ; then perfdata="'req'=0;$warning_queue_req;$critical_queue_req; 'size'=0KB;;; 'active'=0;$warning_active;$critical_active; 'bounce'=0;$warning_other;$warning_other; 'corrupt'=0;$warning_other;$warning_other; 'deferred'=0;$warning_deferred;$critical_deferred; 'maildrop'=0;$warning_other;$warning_other; " output="$queue" echo "OK - ${output} | ${perfdata}" exit $STATE_OK else queue_req=$(echo $queue | cut -d ' ' -f 5) queue_size=$(echo $queue | cut -d ' ' -f 2) # in KB queue_active=$($docker_command find $postfix_dir/active -type f | wc -l) queue_bounce=$($docker_command find $postfix_dir/bounce -type f | wc -l) queue_corrupt=$($docker_command find $postfix_dir/corrupt -type f | wc -l) queue_deferred=$($docker_command find $postfix_dir/deferred -type f | wc -l) queue_maildrop=$($docker_command find $postfix_dir/maildrop -type f | wc -l) perfdata="'req'=$queue_req;$warning_queue_req;$critical_queue_req; 'size'=${queue_size}KB;;; 'active'=$queue_active;$warning_active;$critical_active; 'bounce'=$queue_bounce;$warning_other;$warning_other; 'corrupt'=$queue_corrupt;$warning_other;$warning_other; 'deferred'=$queue_deferred;$warning_deferred;$critical_deferred; 'maildrop'=$queue_maildrop;$warning_other;$warning_other; " fi #echo $perfdata #echo "postfix_dir $postfix_dir - warning_active $warning_active - critical_active $critical_active - warning_deferred $warning_deferred - critical_deferred $critical_deferred - warning_other $warning_other - critical_other $critical_other" returnCrit=0 returnWarn=0 errorString="" #Check critical and warning state for each queue if [ $queue_req -ge $critical_queue_req ]; then returnCrit=1 errorString="$errorString - CRIT total queue > $critical_queue_req ($queue_req)" elif [ $queue_req -ge $warning_queue_req ]; then returnWarn=1 errorString="$errorString - WARN total queue > $warning_queue_req ($queue_req)" fi if [ $queue_active -ge $critical_active ]; then returnCrit=1 errorString="$errorString - CRIT $queue_active > $critical_active actives" elif [ $queue_active -ge $warning_active ]; then returnWarn=1 errorString="$errorString - WARN $queue_active > $warning_active actives" fi if [ $queue_bounce -ge $critical_other ]; then returnCrit=1 errorString="$errorString - CRIT $queue_bounce > $critical_other bounce" elif [ $queue_bounce -ge $warning_other ]; then returnWarn=1 errorString="$errorString - CRIT $queue_bounce > $warning_other bounce" fi #if [ $queue_corrupt -ge $critical_other ]; then # returnCrit=1 # errorString="$errorString - CRIT $queue_corrupt > $critical_other corrupt" #elif [ $queue_corrupt -ge $warning_other ]; then # returnWarn=1 # errorString="$errorString - WARN $queue_corrupt > $warning_other corrupt" #fi if [ $queue_deferred -ge $critical_deferred ]; then returnCrit=1 errorString="$errorString - CRIT $queue_deferred > $critical_deferred deferred" elif [ $queue_deferred -ge $warning_deferred ]; then returnWarn=1 errorString="$errorString - WARN $queue_deferred > $warning_deferred deferred" fi #if [ $queue_maildrop -ge $critical_other ]; then # returnCrit=1 # errorString="$errorString - CRIT $queue_maildrop > $critical_other maildrop" #elif [ $queue_maildrop -ge $warning_other ]; then # returnWarn=1 # errorString="$errorString - WARN $queue_maildrop > $warning_other maildrop" #fi #output="$queue_req request(s) ($queue_size kB)" output="$queue_req request(s)" if [ $returnCrit == 0 ] && [ $returnWarn == 0 ] ; then echo "OK - ${output} | ${perfdata}" returnCode=$STATE_OK elif [ $returnCrit == 0 ] && [ $returnWarn == 1 ] ; then echo "WARNING - ${output}${errorString} | ${perfdata}" returnCode=$STATE_WARNING else echo "CRITICAL - ${output}${errorString} | ${perfdata}" returnCode=$STATE_CRITICAL fi exit $returnCode