Setting downtime in nagios
-
- Posts: 59
- Joined: Tue Feb 21, 2012 6:08 am
Setting downtime in nagios
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
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
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).
Change "DISABLE_HOST_SVC_CHECKS" to "ENABLE_HOST_SVC_CHECKS" to turn them back on.
This should do the trick!
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: 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
This should do the trick!
Last edited by eloyd on Thu Oct 23, 2014 9:25 am, edited 1 time in total.
-
- Posts: 59
- Joined: Tue Feb 21, 2012 6:08 am
Re: Setting downtime in nagios
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.
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.
-
- Posts: 59
- Joined: Tue Feb 21, 2012 6:08 am
Re: Setting downtime in nagios
Eric,
Could you please give me a quick example of a contact definition that would do this ?
Thanks
Could you please give me a quick example of a contact definition that would do this ?
Thanks
Re: Setting downtime in nagios
Let me preface this by saying I've never actually done this, but it should work.
Then you need to write /usr/local/nagios/libexec/downtime-notifier to do something like:
Your mileage may vary.
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$
}
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
-
- -fno-stack-protector
- Posts: 4366
- Joined: Mon Nov 19, 2012 12:10 pm
Re: Setting downtime in nagios
Agreed, never tried that, but those macros look to be available, give it a shot and let us know!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
-
- Posts: 59
- Joined: Tue Feb 21, 2012 6:08 am
Re: Setting downtime in nagios
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 :
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 ?
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$
}
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
Can you post the following script:
downtime_notifier.py
downtime_notifier.py
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Re: Setting downtime in nagios
As I wrote in my original post on what this technique would do, I said:
Did you do that? You need to assign a contact called "downtime-notifier" to the host that you want to use this on.Set the host to notify downtime-scheduler for scheduled downtime events