Page 1 of 1

Time period inheritance

Posted: Mon May 04, 2015 9:14 am
by ashykneecaps
Im wondering if its possible to use timeperiod inheritance in nagios core 3.5.1.
Essentially all i want to do is exclude about 5-10 minutes from the 24x7 timeperiod that nagios defines.
# cat /etc/nagios3/conf.d/timeperiods_nagios2.cfg
###############################################################################
# timeperiods.cfg
###############################################################################

# This defines a timeperiod where all times are valid for checks,
# notifications, etc. The classic "24x7" support nightmare. :-)

define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-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
}

# Here is a slightly friendlier period during work hours
define timeperiod{
timeperiod_name workhours
alias Standard Work Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
}

# The complement of workhours
define timeperiod{
timeperiod_name nonworkhours
alias Non-Work Hours
sunday 00:00-24:00
monday 00:00-09:00,17:00-24:00
tuesday 00:00-09:00,17:00-24:00
wednesday 00:00-09:00,17:00-24:00
thursday 00:00-09:00,17:00-24:00
friday 00:00-09:00,17:00-24:00
saturday 00:00-24:00
}

# This one is a favorite: never :)
define timeperiod{
timeperiod_name never
alias Never
}

# end of file
The docs on timeperiods http://nagios.sourceforge.net/docs/3_0/ ... timeperiod make no mention about timeperiods being able to inherit from each other, however it is used over here http://nagios.sourceforge.net/docs/3_0/ ... ation.html

Ideally, id like to define a timeperiod like such:

Code: Select all

define timeperiod{
        timeperiod_name reboot_time
        alias           Reboot
        monday          03:00-03:10
        tuesday         03:00-03:10
        wednesday       03:00-03:10
        thursday        03:00-03:10
        friday          03:00-03:10
        }
and then exclude it from the 24x7 timeperiod like:

Code: Select all

define timeperiod{
        timeperiod_name 24x7_no_reboot
        alias           24x7_no_reboot
        use             24x7
        exclude         reboot_time
        }
The above does not seem to work, as running
nagios3 -v /etc/nagios3/nagios.cfg
fails with
Template '24x7' specified in timeperiod definition could not be not found
With all that, can timeperiods not inherit from each other or am i doing something wrong?

Re: Time period inheritance

Posted: Mon May 04, 2015 10:41 am
by jolson
Hello,

I tested this in my lab, and inheritance does not appear to work properly. As you have discovered, it looks like nagios is trying to find a 'template' to use rather than a proper time period:
Template '24x7' specified in timeperiod definition could not be not found
The solution here is to remove the following from your 24x7_no_reboot definition:

Code: Select all

        use             24x7
And add:

Code: Select all

sunday          00:00-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
Your exclusion looks proper. Let me know if you have any trouble!

Re: Time period inheritance

Posted: Tue May 05, 2015 4:07 am
by ashykneecaps
Thanks for the advice. Upon looking at things again, it seems the timeperiod requires a name field in order for this to work (Cant confirm as i have not tested this). Thing is, i wanted to use nagios defaults and not have to define my own, especially when its only got one line different to nagios' own.

I've also decided to cancel using my timeperiod that excludes the reboot time as it could possibly introduce unhappiness. Should services enter a non-ok state outside that timeperiod, no alerts will be sent. Cool. When the timeperiod comes into effect again, and the services are still in their non-ok state, no alerts will be sent. Not cool. This i have tested and it seems to be an issue with nagios for many moons now.
http://support.nagios.com/forum/viewtop ... =7&t=21818
http://support.nagios.com/forum/viewtop ... =7&t=21717

Anyway, thanks for your help.

Re: Time period inheritance

Posted: Tue May 05, 2015 2:41 pm
by tmcdonald
Are you using these timeperiods as check periods on the host/service or as notification periods on the contacts?

Re: Time period inheritance

Posted: Wed May 06, 2015 2:00 am
by ashykneecaps
Hi,

I intended using these as notification periods on services.

Code: Select all

define service{
  name                            my_service_template
  use                             generic-service
  retain_nonstatus_information    1
  contact_groups                  my_contacts
  notification_period	          24x7_no_reboot   
  register                        0
}

All services then use this template.

Code: Select all

define service {
  hostgroup_name           my_hostgroup
  service_description      HTTP
  check_command            check_http
  use                      my_service_template
}
My original intention was to not get notifications about services that are in a non-ok state, as a result of the server restarting, then about 5 minutes later receive a recovery alert once the server is up and running again.
The reason I'm ditching it is because if something bad happens that a service doesn't recover from, lets say a server fails to startup after reboot, then the notifications will not be sent and who knows how long it'll be before a dead server is noticed.That's just one example off the top of my head.

Re: Time period inheritance

Posted: Wed May 06, 2015 11:39 am
by jdalrymple
Is there a reason you're not using downtime?

I'm not going to lie, it can sometimes prove as buggy as timeperiods, but it is something to look at. Also I'd suggest it as a more appropriate way of not alerting during "downtimes"

You could schedule it with an external command even.

Re: Time period inheritance

Posted: Thu May 07, 2015 3:16 am
by ashykneecaps
Hi jdalrymple,

Thats exactly what i ended up doing. I found this http://old.nagios.org/developerinfo/ext ... and_id=119 and tweaked it a bit to my liking. It's only been a few days but so far so good.

Re: Time period inheritance

Posted: Thu May 07, 2015 9:20 am
by tmcdonald
Shall we close up this thread?

Re: Time period inheritance

Posted: Fri May 08, 2015 1:59 am
by ashykneecaps
You may indeed sir.