service dependency on host? Here's my working solution
Toussaint OTTAVI
t.ottavi at medi.fr
Wed Nov 5 10:49:14 CET 2008
Charlie Reddington wrote :
> I've seen the docs about having services dependent on services, and
> hosts dependent on hosts. But how about services, dependent on hosts.
> Do I just use hosts instead of services in the config?
Hi Charlie,
I had the same problem. I read a lot of topics, but I didn't find
anything. It seems there's no way to do what we would like to do :
services dependant on hosts, ie do not try to check all the services if
the host is down. I must say I don't really understand the actual
"logic" of nagios, but for now, this seems to be 'by design'.
Anyway, the "magic" of nagios applies : if it does not do what you want,
then you just have to do it yourself.
Here's what I did, and it seems to work fine.
- activate 'event handlers' on host. This will run a nagios command each
time a host status changes
- set up this command to run an external script (called 'disable service
checks')
- this script will send back to nagios an 'external command' to enable
or disable all the service checks for that host
- as there is only one handler for any state change (UP or DOWN), the
script has to check the actual status : if host DOWN then disable
service checks, if host UP then enable service checks
Now, let's do that :
In hosts or hosts template :
event_handler_enabled 1
event_handler disable-service-checks
In your commands file:
# event handler to disable service checks when host is down
define command {
command_name disable-service-checks
command_line $USER1$/eventhandlers/disable_service_checks
$HOSTSTATE$ $STATETYPE$ $HOSTATTEMPT$ $HOSTNAME
}
Then, put the following script in your plugins/eventhandler/
subdirectory, with name 'disable_service_checks' and execution flag :
#!/bin/sh
#
# Enable / Disable service checks after a state change of the host
# Arguments received are : $SHOSTATE$ $STATETYPE$ $HOSTATTEMPT$ $HOSTNAME
#
# by Toussaint OTTAVI, t.ottavi at medi.fr
#
CommandFile="/var/spool/nagios/nagios.cmd"
LogFile="/var/log/nagios/disable_service_checks.log"
# get the current date/time in seconds since UNIX epoch
datetime=`date +%s`
# send debug information to logfile
/usr/bin/printf "Event Handler called with Hostname:%s State:%s Type:%s
Attempts:%s\n" $4 $1 $2 $3 >> $LogFile
# Check the $HOSTSTATE$
case "$1" in
UP)
# Host is UP, re-enable service checks
/usr/bin/printf "[%i] ENABLE_HOST_SVC_CHECKS;%s \n" $datetime $4 >>
$CommandFile
;;
UNREACHABLE)
# Host is UNREACHABLE, disable service checks
/usr/bin/printf "[%i] DISABLE_HOST_SVC_CHECKS;%s \n" $datetime $4 >>
$CommandFile
;;
DOWN)
# Host is DOWN, disable service checks
/usr/bin/printf "[%i] DISABLE_HOST_SVC_CHECKS;%s \n" $datetime $4 >>
$CommandFile
;;
esac
exit 0
Notes :
- This is early beta, I did it yesyerday evening, not sure it works
100%, please feel free to provide feedback
- all paths are for installation on OpenSuse. You may have to
check/change some things.
- in case of problems, first try to run the script by hand :
'disable_service_checks DOWN HARD 1 NAME_OF_MY_HOST', then see what
happens in Nagios
- to see if the handler really triggers, have a look at the logfile :
/var/log/nagios/disable_service_checks.log
- external commands must be activated in nagios.cfg
- host names must not contain spaces. Maybe some scripting specialist
could improve it...
- the $STATETYPE$ variable should return a state 'SOFT' or 'HARD', which
would allow to improve the script (only do the action if the state
change is HARD). But for an unknown reason, Nagios does not send this
value, so we can not process it. Any idea ?
Enjoy Nagios Magic, I really love this tool, and hope this helps.
Kind regards,
--
*Toussaint OTTAVI*
*MEDI INFORMATIQUE*
*Tel :* 04 95 20 10 03
*Gsm :* 06 10 28 41 72
*Mail:* t.ottavi at medi.fr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20081105/3d0dbed6/attachment.html>
-------------- next part --------------
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
-------------- 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