#!/usr/bin/env bash ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation, either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## # =============== # check_zarafaprocessed - plugin to check the number of mail processed by parsing logfiles # =============== # Based on: # * mail processor written by Cecil Westerhof & Modifications for nagios by Frank IJskes # # Modified to work with zarafa: # * Philipp Niedziela # =============== # # Info: # Dagent and Spooler need to have # log_timestamp = 1 # in config enabled (/etc/zarafa/spooler.log, /etc/zarafa/dagent.log) # # !!Logfiles should be rotaded daily to reduce load!! # # If script is called by check_nrpe set timeout to min. 20 (check_nrpe [..] -t 20) # otherwise you'll get a timeout if while getopts "hvw:c:" opt do case $opt in h) showhelp=1 break ;; w) warning="$OPTARG" ;; c) critical="$OPTARG" ;; v) verbose=1 ;; esac done declare -r TIME_RANGE=300 declare -r CURRENT_TIME=$(date +%s) declare -i i=0 dagentlog="/var/log/zarafa/dagent.log" spoolerlog="/var/log/zarafa/spooler.log" if [ ! "$dagentlog" ]; then echo "Could not find postfix log!" exit 3 fi showUsage() { echo "Usage: $0 [-h] [-v] -w -c " echo "" echo "Example: $0 -w 50 -c 100 " } showHelp() { showtUsage echo "" echo "This plugin checks the number of messages processed (send / received) by Zarafa in the last 5 minutes." echo "" echo "" exit 3 } IFS=' ' getReceived () { i=0 for dateTime in $(grep 'Delivered' ${dagentlog} | \ awk '{ print $2, $3, $4; }') ; do if [[ $((${CURRENT_TIME} - $(date --date="${dateTime}" +%s))) -lt ${TIME_RANGE} ]] ; then i+=1 fi done echo ${i} } getSend () { i=0 for dateTime in $(grep 'accepted' ${spoolerlog} | \ awk '{ print $2, $3, $4; }') ; do if [[ $((${CURRENT_TIME} - $(date --date="${dateTime}" +%s))) -lt ${TIME_RANGE} ]] ; then i+=1 fi done echo ${i} } if [ "$showhelp" = "1" ]; then showHelp exit 3 fi if [ ! "$warning" ] || [ ! "$critical" ]; then printUsage exit 3 fi if [ $warning -ge $critical ]; then echo " has to be smaller than " exit 3 fi nrmsgsreceived=`getReceived` nrmsgssend=`getSend` echo "Messages processed in the last $TIME_RANGE seconds: Send: $nrmsgssend / Received: $nrmsgsreceived | mailsend=$nrmsgssend mailreceived=$nrmsgsreceived" if [ "$nrmsgsreceived" -ge "$critical" ]; then exit 2 elif [ "$nrmsgssend" -ge "$critical" ]; then exit 2 elif [ "$nrmsgsreceived" -ge "$warning" ]; then exit 1 elif [ "$nrmsgssend" -ge "$warning" ]; then exit 1 else exit 0 fi