Setting downtime in nagios

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
liquidcool
Posts: 59
Joined: Tue Feb 21, 2012 6:08 am

Setting downtime in nagios

Post 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
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Setting downtime in nagios

Post 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!
Last edited by eloyd on Thu Oct 23, 2014 9:25 am, edited 1 time in total.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
liquidcool
Posts: 59
Joined: Tue Feb 21, 2012 6:08 am

Re: Setting downtime in nagios

Post 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.
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Setting downtime in nagios

Post by eloyd »

Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
liquidcool
Posts: 59
Joined: Tue Feb 21, 2012 6:08 am

Re: Setting downtime in nagios

Post by liquidcool »

Eric,

Could you please give me a quick example of a contact definition that would do this ?

Thanks
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Setting downtime in nagios

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Setting downtime in nagios

Post by sreinhardt »

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.
liquidcool
Posts: 59
Joined: Tue Feb 21, 2012 6:08 am

Re: Setting downtime in nagios

Post 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 ?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Setting downtime in nagios

Post by abrist »

Can you post the following script:
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.
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Setting downtime in nagios

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
Locked