6

I have Nagios Core up and running, and cannot find any way to schedule a regular period of downtime for hosts. For example, let's say I have a host that is scheduled to reboot itself every Sunday at 1 am. I'd like to be able to schedule that known downtime of "every Sunday from 1:00am to 1:10am" into Nagios, but the only way I see to do so is one event at a time.

Alan M
  • 279
  • 1
  • 3
  • 11
  • 2
    Just curious why you would be rebooting a server that's unattended on a schedule like that? It seems like not such a good idea. – MDMarra Aug 03 '11 at 14:36
  • 2
    There is no option like this because it's generaly seen as bad practice to periodicly reboot a server. If your server requires a reboot every week you should try and find out why it does and resolve the issue rather than rebooting it every week. – Bart De Vos Aug 03 '11 at 14:47
  • 1
    It's generally seen as a good practice to periodically reboot your server to make sure it still boots (e.g., the startup scripts did not get broken). The worst time to find that your server doesn't boot successfully is during an emergency unscheduled reboot. – Mark Wagner Aug 03 '11 at 16:45
  • @embobo But every week... That's a bit harsh. Just do it whenever you apply a patch or make some major change. There is no need for a weekly reboot. – Bart De Vos Aug 04 '11 at 13:14

2 Answers2

11

Without using the cron solution mentioned by JakePaulus the typical method for handling "downtime" with Nagios is to define and use a timeperiod that does not include the time during which the host will be down. E.g., in your case

define timeperiod {
  timeperiod_name foo
  sunday 00:00-1:00,1:10-24:00
  monday 00:00-24:00
  tuesday 00:00-24:00
  wednesday 00:00-24:00
  thursday 00:00-24:00
  friday 00:00-24:00
  saturday 00:00-24:00
}

A simpler method is to take your pre-existing 24x7 timeperiod and define and exclusion:

define timeperiod {
  name reboot
  timeperiod_name reboot
  sunday 1:00-1:10
}

define timeperiod {
  timeperiod_name foo
  use 24x7
  exclude reboot
}
Mark Wagner
  • 18,019
  • 2
  • 32
  • 47
  • The only problem with scheduling checks to only occur outside of scheduled downtime is it doesn't allow you to keep track of how much actual downtime has occurred including scheduled maintenance. This might be important for some people to track. – JakePaulus Aug 05 '11 at 03:16
  • 1
    @JakePaulus This timeperiod could be applied to notifications only; thus the downtime during this period would be tracked. I purposely didn't say where in the nagios config to use the timeperiod because it depends on your needs. – Mark Wagner Aug 05 '11 at 17:43
  • if one were to apply this time period to the notifications, then availability reports would not have a way to differentiate scheduled vs. unscheduled downtime. – JakePaulus Aug 05 '11 at 22:42
  • note: for version 3.5, i had to change 'name' => 'alias' – Greg Jan 08 '15 at 15:53
  • Note: Inheritance of a time period does not appear to work! (Nor is such behavior documented) – Sebazzz Dec 23 '16 at 08:24
  • In version 4, inheritance is working, see https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/objectinheritance.html and https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/timeperiods.html – MDT Oct 17 '18 at 07:21
6

You can do this using a shell script that submits an external command (outputs a command to the named pipe nagios.cmd file) on a schedule dictated by cron. Here's a link to what we use.

http://exchange.nagios.org/directory/Addons/Scheduled-Downtime/Schedule-Downtime-via-cron/details

JakePaulus
  • 2,347
  • 16
  • 17