#!/bin/bash # $Header: $ # vim:nu:ai:sw=4:ts=4: # # Nagios check script for the number of mails in AntiVir MailGate queues # Created by Wolfram Schlich # Distributed under the terms of the GNU General Public License v3 # # External dependencies: # - find # - wc # ## ## nagios state specific exit codes ## declare -i state_ok=0 declare -i state_warning=1 declare -i state_critical=2 declare -i state_unknown=3 declare -i state_dependent=4 ## ## functions ## function usage() { echo echo "Usage: ${0##*/} WARN_VALUE CRIT_VALUE " echo echo " WARN when the amount of mails in the queue is > WARN_VALUE," echo " CRIT when it is > CRIT_VALUE" echo } function checkargs() { if [[ -z "${qname}" || -z "${warn_value}" || -z "${crit_value}" ]]; then usage exit ${state_unknown} fi } ## ## main() ## if [[ ! -x "$(type -p find 2>/dev/null)" ]]; then echo "ERROR - 'find' not executable" exit ${state_unknown} fi if [[ ! -x "$(type -p wc 2>/dev/null)" ]]; then echo "ERROR - 'wc' not executable" exit ${state_unknown} fi qname="${1}"; shift warn_value="${1}"; shift crit_value="${1}"; shift checkargs qdir=/var/spool/avmailgate/${qname} if [[ ! -d "${qdir}" ]]; then echo "UNKNOWN - queue directory '${qdir}' does not exist" exit ${state_unknown} else declare -i qmails=$(find "${qdir}" -type f -name "df-*" | wc -l) if [[ ${qmails} -ge ${crit_value} ]]; then echo "CRITICAL - queue '${qname}' has ${qmails} mails" exit ${state_critical} elif [[ ${qmails} -ge ${warn_value} ]]; then echo "WARNING - queue '${qname}' has ${qmails} mails" exit ${state_warning} else echo "OK" exit ${state_ok} fi fi ## should never reach this echo "ERROR - there's an error in the matrix!" exit ${state_unknown}