<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Arial"><small>Charlie Reddington wrote :</small></font><font
 size="-1"><font face="Arial">
<blockquote type="cite">I've seen the docs about having services
dependent on services, and <br>
hosts dependent on hosts. But how about services, dependent on hosts. <br>
Do I just use hosts instead of services in the config?<br>
</blockquote>
<br>
Hi Charlie,<br>
<br>
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'.<br>
<br>
Anyway, the "magic" of nagios applies : if it does not do what you
want, then you just have to do it yourself. <br>
<br>
Here's what I did, and it seems to work fine.<br>
- activate 'event handlers' on host. This will run a nagios command
each time a host status changes<br>
- set up this command to run an external script (called 'disable
service checks')<br>
- this script will send back to nagios an 'external command' to enable
or disable all the service checks for that host<br>
- 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<br>
<br>
Now, let's do that :<br>
<br>
In hosts or hosts template :<br>
</font></font><font face="Courier New, Courier, monospace" size="-1">   
event_handler_enabled  1   <br>
</font><font size="-1"><font face="Arial"><font
 face="Courier New, Courier, monospace">    event_handler
disable-service-checks</font><br>
<br>
In your commands file:<br>
<font face="Courier New, Courier, monospace">  # event handler to
disable service checks when host is down<br>
  define command {<br>
    command_name disable-service-checks<br>
    command_line $USER1$/eventhandlers/disable_service_checks
$HOSTSTATE$ $STATETYPE$ $HOSTATTEMPT$ $HOSTNAME        <br>
    }</font><br>
<br>
Then, put the following script in your plugins/eventhandler/
subdirectory, with name 'disable_service_checks' and execution flag :<br>
<br>
<font face="Courier New, Courier, monospace">#!/bin/sh<br>
#<br>
# Enable / Disable service checks after a state change of the host<br>
# Arguments received are : $SHOSTATE$ $STATETYPE$ $HOSTATTEMPT$
$HOSTNAME<br>
#<br>
# by Toussaint OTTAVI, <a class="moz-txt-link-abbreviated" href="mailto:t.ottavi@medi.fr">t.ottavi@medi.fr</a><br>
#<br>
<br>
CommandFile="/var/spool/nagios/nagios.cmd"<br>
LogFile="/var/log/nagios/disable_service_checks.log"<br>
<br>
# get the current date/time in seconds since UNIX epoch<br>
datetime=`date +%s`<br>
<br>
# send debug information to logfile<br>
/usr/bin/printf "Event Handler called with Hostname:%s State:%s Type:%s
Attempts:%s\n" $4 $1 $2 $3 >> $LogFile<br>
<br>
# Check the $HOSTSTATE$ <br>
case "$1" in<br>
UP)<br>
    # Host is UP, re-enable service checks<br>
  /usr/bin/printf "[%i] ENABLE_HOST_SVC_CHECKS;%s \n" $datetime $4
>> $CommandFile<br>
    ;;<br>
UNREACHABLE)<br>
    # Host is UNREACHABLE, disable service checks<br>
    /usr/bin/printf "[%i] DISABLE_HOST_SVC_CHECKS;%s \n" $datetime $4
>> $CommandFile<br>
    ;;    <br>
DOWN)<br>
    # Host is DOWN, disable service checks<br>
  /usr/bin/printf "[%i] DISABLE_HOST_SVC_CHECKS;%s \n" $datetime $4
>> $CommandFile<br>
  ;;<br>
esac<br>
exit 0</font><br>
<br>
<br>
Notes :<br>
- This is early beta, I did it yesyerday evening, not sure it works
100%, please feel free to provide feedback<br>
</font></font><font size="-1"><font face="Arial"><font
 face="Courier New, Courier, monospace"><font face="Arial">- all paths
are for installation on OpenSuse. You may have to check/change some
things.<br>
</font></font></font></font><font size="-1"><font face="Arial">- 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<br>
- to see if the handler really triggers, have a look at the logfile : </font></font><font
 size="-1"><font face="Arial"><font
 face="Courier New, Courier, monospace">/var/log/nagios/disable_service_checks.log<br>
<font face="Arial">- external commands must be activated in nagios.cfg</font><br>
<font face="Arial">- host names must not contain spaces. Maybe some
scripting specialist could improve it...<br>
- 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 ?<br>
<br>
<br>
Enjoy Nagios Magic, I really love this tool, and hope this helps.<br>
<br>
Kind regards,</font></font></font></font><font size="-1"><font
 face="Arial"><br>
</font></font>
<div class="moz-signature">-- <br>
<title>Signature</title>
<meta http-equiv="Content-Type" content="text/html; ">
<style type="text/css">
<!--
.stylesig {
        font-family: Arial, Helvetica, sans-serif; 
        font-size: 12px;
        color: #000066;
}
-->
</style>
<p class="stylesig"><strong>Toussaint OTTAVI</strong><br>
<br>
<strong>MEDI INFORMATIQUE</strong><br>
<strong>Tel :</strong> 04 95 20 10 03<br>
<strong>Gsm :</strong> 06 10 28 41 72<br>
<strong>Mail:</strong> <a class="moz-txt-link-abbreviated" href="mailto:t.ottavi@medi.fr">t.ottavi@medi.fr</a></p>
</div>
</body>
</html>