event handler question with nrpe
shadih rahman
shadhin71 at gmail.com
Tue Mar 24 22:19:29 CET 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20090324/8051509b/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
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
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at 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
More information about the Users
mailing list