Page 1 of 2
Setting downtime in nagios
Posted: Thu Oct 23, 2014 8:58 am
by liquidcool
Hi,
Is there a way, when setting downtime, that also all the checks for that host (including its service checks) are halted during that downtime. So checks stop and start back up again according to the time you set.
We set downtime for the hosts, and though there are no notifications during this downtime, all the failing service checks still carry on and as a result clog up our dashboards.
I expect that if you set a host to go down you don't want it to do the checks also as it is not necessary.
Thanks
Re: Setting downtime in nagios
Posted: Thu Oct 23, 2014 9:10 am
by eloyd
This would be a feature request, though you can imitate the same thing via a dedicated contact as follows:
Note: This is pseudo-code, but you get the idea. You'll want to consult
http://old.nagios.org/developerinfo/ext ... ndlist.php for more specifics (especially the DISABLE_HOST_SVC_CHECKS directive).
- Create a new contact called downtime-scheduler
- Attributes of this contact will be irrelevant though you could make this process more robust and use them for something
- Create a new command called notify-downtime-scheduler
- Have it execute $USER1$/<somescript> and pass the host and notification type to the script
- In <somescript> use the code in the next block to respond to a "DOWNTIMESTART" notification to disable service checks on the host
- Also have it respond to DOWNTIMEEND and DOWNTIMECANCELLED to enable service checks on the host
- Set the host to notify downtime-scheduler for scheduled downtime events
Code for telling Nagios to STOP executing checks on a particular host passed in as the first argument:
Code: Select all
#!/bin/sh
host="$1"
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] DISABLE_HOST_SVC_CHECKS;${host}\n" $now > $commandfile
Change "DISABLE_HOST_SVC_CHECKS" to "ENABLE_HOST_SVC_CHECKS" to turn them back on.
This should do the trick!
Re: Setting downtime in nagios
Posted: Thu Oct 23, 2014 9:14 am
by liquidcool
Thanks Eric,
Will give it a go.
How do I go about putting in a feature request, because I think this is a fundamental way how a downtime should function.
Re: Setting downtime in nagios
Posted: Thu Oct 23, 2014 9:25 am
by eloyd
Re: Setting downtime in nagios
Posted: Thu Oct 23, 2014 9:26 am
by liquidcool
Eric,
Could you please give me a quick example of a contact definition that would do this ?
Thanks
Re: Setting downtime in nagios
Posted: Thu Oct 23, 2014 9:34 am
by eloyd
Let me preface this by saying I've never actually done this, but it should work.
Code: Select all
define contact{
name downtime-notifier
host_notification_options s
host_notification_commands notify-downtime-notifier
}
define command{
command_name notify-downtime-notifier
command_line $USER1$/downtime-notifier $NOTIFICATIONTYPE$ $HOSTNAME$ $HOSTSTATE$
}
Then you need to write /usr/local/nagios/libexec/downtime-notifier to do something like:
Code: Select all
#!/bin/sh
type="$1"
host="$2"
command="ENABLE_HOST_SVC_CHECKS"
[ "$1" = "DOWNTIMESTART" ] && command="DISABLE_HOST_SVC_CHECKS"
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] ${command};${host}\n" $now > $commandfile
Your mileage may vary.
Re: Setting downtime in nagios
Posted: Fri Oct 24, 2014 12:40 pm
by sreinhardt
Agreed, never tried that, but those macros look to be available, give it a shot and let us know!
Re: Setting downtime in nagios
Posted: Mon Dec 01, 2014 8:46 am
by liquidcool
So I finally got round to testing this out.
It does not seem to work. I don't see it using the contact to trigger the script.
This is what I have for the contact :
Code: Select all
define contact{
contact_name downtime-notifier
host_notification_period 24x7
service_notification_period 24x7
host_notification_options s
host_notification_commands notify-downtime-host
service_notification_commands notify-downtime-service
}
define command{
command_name notify-downtime-host
command_line $USER2$/downtime_notifier.py $NOTIFICATIONTYPE$ $HOSTNAME$ $HOSTSTATE$
}
I have checked permissions for the script and they are all in order.
At the moment all I have is the script writing to a log file, just so I can confirm that it is even using the script file. And nothing gets written to it.
The nagios logs show that there is a HOST DOWNTIME ALERT STARTED and STOPPED, but I don't see any trigger from the contact.
Any ideas ?
Re: Setting downtime in nagios
Posted: Mon Dec 01, 2014 5:30 pm
by abrist
Can you post the following script:
downtime_notifier.py
Re: Setting downtime in nagios
Posted: Tue Dec 02, 2014 9:42 am
by eloyd
As I wrote in my original post on what this technique would do, I said:
Set the host to notify downtime-scheduler for scheduled downtime events
Did you do that? You need to assign a contact called "downtime-notifier" to the host that you want to use this on.