can event handler take argument.  I want to have a generic shell script
which take argument as to what process needs to start.  I want to restart
process via nrpe.  Can someone please verfiy if the following will work or
not?  Thanks in advance.

*

define service{
        host_name                       somehost
        service_description             HTTP
        max_check_attempts              4
        event_handler                   restart-process.sh!my_proecess
        ...other service variables...
        }

*

Once the service has been defined with an event handler, we must define that
event handler as a command. Notice the macros in the command line that I am
passing to the event handler - these are important!

define command{
command_name    restart-process.sh
command_line    /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c
restart-process -a $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMPT$
$SERVICEDESC$ 2 $ARG1$
}


my restart-process.sh

#!/bin/sh

maxattempts=$5

case "$1" in
OK)
        # The service just came back up, so don't do anything...
        ;;
WARNING)
        # We don't really care about warning states, since the service is
probably still running...
        ;;
UNKNOWN)
        # We don't know what might be causing an unknown error, so don't do 
anything...
        ;;
CRITICAL)

        case "$2" in
                

        SOFT)


                case "$3" in
                                

                $maxattempts)

                        logger -t nrpe-eventhandler "Eventhandler: (Re)starting
/etc/init.d/$4 (state=$1, type=$2, attempt=$3)"

                        output=`sudo /etc/init.d/$4 restart`

                        `which printf` "%b" "***** Nagios *****\n\nMessage:\tAn 
init script
was invoked (after $3
attempts).\nDate/Time:\t`date`\n\nHostname:\t`uname
-n`\nService:\t$4\nCommand:\t/etc/init.d/$4
restart\nOutput:\n\n$output" \
                        | `which mail` -s "** Eventhandler: Restart of '$4' on 
host '`uname
-n`'" $notifee
                        

                        sudo /etc/init.d/$6 restart
                        ;;
                        esac
                ;;
                                

        HARD)
                # Call the init script to restart the service.
                sudo /etc/init.d/$6 restart
                ;;
        esac
        ;;
esac
exit 0





-- 
Cordially,
Shadhin Rahman
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

Reply via email to