ICINGA EXIM mailq script for icinga part 2

========================================================================
check mailq EXIM
 ========================================================================
At client side:-
#rpm -qf utils.pm                                  //tofind the package name of file
#yum install nagios-plugins-perl
do this if you face the"utils.sh not found error". make dir's as needed
#ln -s /usr/lib64/nagios/plugins/utils.sh  /usr/local/nagios/libexec/utils.sh
#visudo
   Comment out    

#Defaults    requiretty             <<<= = =

#add nrpe user like below line
root    ALL=(ALL)       ALL
nrpe ALL=NOPASSWD:/usr/sbin/exim                             
Save/exit
 ***************************************
copybelow script in file name  "check_eximmailqueue"
#ls -l  /usr/lib64/nagios/plugins/check_eximmailqueue
-rwxr-xr-x 1 root root   3285 Jul 27 06:25 check_eximmailqueue*
-rwxr-xr-x 1 root root 172880 Oct 17  2013 check_http*
-rwxr-xr-x 1 root root  40944 Oct 17  2013 check_load*
-rwxr-xr-x 1 root root  22256 Apr 30 21:28 check_nrpe*
-rwxr-xr-x 1 root root  36080 Oct 17  2013 check_users*
-rwxr-xr-x 1 root root  38696 Oct 17  2013 negate*
-rwxr-xr-x 1 root root  36104 Oct 17  2013 urlize*
-rw-r--r-- 1 root root   2091 Oct 17  2013 utils.pm
-rwxr-xr-x 1 root root   2728 Oct 17  2013 utils.sh*
cat /usr/lib64/nagios/plugins/check_eximmailqueue
#!/bin/sh
###############################################
#
# Nagios script to check Exim mail queue status
#
# Copyright 2007, 2008 Ian Yates
#
# NOTE: Depending on your config, the nagios user will probably be
#       needed to be added to the exim group for this script to function correctly
#
# See usage for command line switches
#

. /usr/local/nagios/libexec/utils.sh


VERSION="1.3"

EXIM=$(which exim)
SUDO=/usr/bin/sudo

FLAG_VERBOSE=FALSE
LEVEL_WARN=""
LEVEL_CRIT=""
RESULT=""
EXIT_STATUS=$STATE_OK


###############################################
#
## FUNCTIONS
#

## Print usage
usage() {
    echo " check_eximailqueue $VERSION - Nagios Exim mail queue check script"
    echo ""
    echo " Usage: check_eximailqueue -w <warning queue size> -c <critical queue size> [ -v ] [ -h ]"
    echo ""
    echo "         -w  Queue size at which a warning is triggered"
    echo "         -c  Queue size at which a critical is triggered"
    echo "         -v  Verbose output (ignored for now)"
    echo "         -h  Show this page"
    echo ""
}

## Process command line options
doopts() {
    if ( `test 0 -lt $#` )
    then
        while getopts w:c:vh myarg "$@"
        do
            case $myarg in
                h|\?)
                    usage
                    exit;;
                w)
                    LEVEL_WARN=$OPTARG;;
                c)
                    LEVEL_CRIT=$OPTARG;;
                v)
                    FLAG_VERBOSE=TRUE;;
                *)    # Default
                    usage
                    exit;;
            esac
        done
    else
        usage
        exit
    fi
}


# Write output and return result
theend() {
    echo $RESULT
    exit $EXIT_STATUS
}


#
## END FUNCTIONS
#

#############################################
#
## MAIN
#


# Handle command line options
doopts $@

# Do the do
OUTPUT=`$SUDO -u root $EXIM -bpc`
if test -z "$OUTPUT" ; then
    RESULT="Mailqueue WARNING - query returned no output!"
    EXIT_STATUS=$STATE_WARNING
else
    if test "$OUTPUT" -lt "$LEVEL_WARN" ; then
        RESULT="Mailqueue OK - $OUTPUT messages on queue"
        EXIT_STATUS=$STATE_OK
    else
        if test "$OUTPUT" -ge "$LEVEL_CRIT" ; then
            RESULT="Mailqueue CRITICAL - $OUTPUT messages on queue"
            EXIT_STATUS=$STATE_CRITICAL
        else
            if test "$OUTPUT" -ge "$LEVEL_WARN" ; then
                RESULT="Mailqueue WARNING - $OUTPUT messages on queue"
                EXIT_STATUS=$STATE_WARNING
            fi
        fi
    fi
fi

# Quit and return information and exit status
theend

No comments:

Post a Comment