Table of Contents
Nagios Core Configuration - timeperiod
In the case that you have followed steps mentioned at installation of the Nagios Core document at this web page the predefined configuration file with timeperiod objects is located at:
/opt/nagios-<VERSION>/etc/objects/timeperiods.cfg
Preface
One of the main function of Nagios Core is to schedule tasks. It mean to run monitoring and notification tasks according to configured time windows.
With customization of “timeperiod” object at Nagios Core it is possible to fine tune your monitoring and this can safe lot of time for support team that can focus on really important issues.
Example:
We are running monitoring for IT infrastructure at our company or for our customer. According to Service Level Agreement (SLA) we shall provide the monitoring service only during office hours. The reason for this SLA is that during out of office hour’s part of the infrastructure is turned off.
In this case that we will run standard 24/7 * 365 monitoring during the time that is out of SLA our support team will be permanently flooded with false alarms.
According to this it is required to correct the monitoring according to SLA. In this way we can safe lot of time for support team that can be spent to solve real issues.
timeperiod
Location
Nagios Core is providing to you already predefined set of timeperiod objects.
Located at (in the case that you have followed the installation of Nagios Core described on this website): /opt/nagios-<VERSION>/etc/objects/timeperiods.cfg
# grep -e timeperiod_name -e alias /opt/nagios-4.0.7/etc/objects/timeperiods.cfg timeperiod_name 24x7 alias 24 Hours A Day, 7 Days A Week timeperiod_name workhours alias Normal Work Hours timeperiod_name none alias No Time Is A Good Time timeperiod_name us-holidays alias U.S. Holidays timeperiod_name 24x7_sans_holidays alias 24x7 Sans Holidays
Location Customization
In the case that you prefer to use your own configuration file, to store your customized configuration it is possible to define path to your configuration file.
In this case Nagios Core need to know where to search for the customized configuration file.
According to this it is required to update the main Nagios Core configuration file – “nagios.cfg”
It is possible to specify:
cfg_file=/<path>/<to>/<your>/<config>/<file> # Direct path to you customized configuration file cfg_dir=/<path>/<to>/<your>/<config>/<dir> # Path to the directory where to search for the config file.
Official documentation
In most of my documents I’m preventing to copying of the official documentation. On another hand I think at this point it is really handy as I will not reinvent the wheel.
Description:
A time period is a list of times during various days that are considered to be “valid” times for notifications and service checks. It consists of time ranges for each day of the week that “rotate” once the week has come to an end. Different types of exceptions to the normal weekly time are supported, including: specific weekdays, days of generic months, days of specific months, and calendar dates.
Definition Format:
define timeperiod{ timeperiod_name timeperiod_name # Mandatory parameter alias alias # Mandatory parameter [weekday] timeranges [exception] timeranges exclude [timeperiod1,timeperiod2,...,timeperiodn] }
Directive Descriptions:
timeperiod_name: | This directives is the short name used to identify the time period. |
alias: | This directive is a longer name or description used to identify the time period. |
[weekday]: | The weekday directives (“sunday” through “saturday”)are comma-delimited lists of time ranges that are “valid” times for a particular day of the week. Notice that there are seven different days for which you can define time ranges (Sunday through Saturday). Each time range is in the form of HH:MM-HH:MM, where hours are specified on a 24 hour clock. For example, 00:15-24:00 means 12:15am in the morning for this day until 12:00am midnight (a 23 hour, 45 minute total time range). If you wish to exclude an entire day from the timeperiod, simply do not include it in the timeperiod definition. |
[exception]: | You can specify several different types of exceptions to the standard rotating weekday schedule. Exceptions can take a number of different forms including single days of a specific or generic month, single weekdays in a month, or single calendar dates. You can also specify a range of days/dates and even specify skip intervals to obtain functionality described by “every 3 days between these dates”. Rather than list all the possible formats for exception strings, I'll let you look at the example timeperiod definitions above to see what's possible. ![]() |
exclude: | This directive is used to specify the short names of other timeperiod definitions whose time ranges should be excluded from this timeperiod. Multiple timeperiod names should be separated with a comma. |
Examples
24/7x365(+1)
In the case that you are looking for standard 24/7 monitoring, it is possible to use standard timeperiod object delivered with Nagios Core configuration:
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 }
None
In some cases it is mandatory to use timeperiode object even you are not going to schedule any time frame (for example in the case that you are testing new monitoring configuration and you will prevent of sending alarms).
In this case it's possible to use standard timeperiod object delivered with Nagios Core configuration:
define timeperiod{ timeperiod_name none alias No Time Is A Good Time }
Non-Work Hours
In this example it is possible to see how to combine time several time frames together to describe the interesting time frame for whole week.
define timeperiod{ timeperiod_name nonworkhours alias Non-Work Hours sunday 00:00-24:00 # Every Sunday of every week from 00:00 until 24:00 monday 00:00-09:00,17:00-24:00 # Every Monday of every week from 00:00 until 09:00 then from 17:00 until 24:00 tuesday 00:00-09:00,17:00-24:00 # Every Tuesday of every week from 00:00 until 09:00 then from 17:00 until 24:00 wednesday 00:00-09:00,17:00-24:00 # Every Wednesday of every week from 00:00 until 09:00 then from 17:00 until 24:00 thursday 00:00-09:00,17:00-24:00 # Every Thursday of every week from 00:00 until 09:00 then from 17:00 until 24:00 friday 00:00-09:00,17:00-24:00 # Every Friday of every week from 00:00 until 09:00 then from 17:00 until 24:00 saturday 00:00-24:00 # Every Saturday of every week from 00:00 until 24:00 }
Single day
In some cases it is needed to specify exact day. The nice example where it can be used is list of public holidays in your country.
define timeperiod{ timeperiod_name list_of_single_days alias List of single days 1999-01-28 00:00-24:00 # January 28th, 1999 (Exact one day) monday 3 00:00-24:00 # 3rd Monday of every Month day 2 00:00-24:00 # 2nd Day of every Month friday -2 00:00-24:00 # 2nd to last Friday of every Month february 10 00:00-24:00 # February 10th of every Year february -1 00:00-24:00 # Last of February of every Year thursday -1 november 00:00-24:00 # Last Thursday in November of every year }
Time Range
In some causes it is interesting to specify time range including more days. This can be used for example during longer company closure for example at X-mas.
define timeperiod{ timeperiod_name time-range alias Time Range 2007-01-01 - 2008-02-01 00:00-24:00 # January 1st, 2007 to February 1st, 2008 monday 3 - thursday 4 00:00-24:00 # 3rd Monday to 4th Thursday of every month day 1 - 15 00:00-24:00 # 1st to 15th day of every month day 20 - -1 00:00-24:00 # 20th to the last day of every month july 10 - 15 00:00-24:00 # July 10th to July 15th of every year april 10 - may 15 00:00-24:00 # April 10th to May 15th of every year tuesday 1 april - friday 2 may 00:00-24:00 # 1st Tuesday in April to 2nd Friday in May of every year }
X-th day during Time Range
In this case we are going to specify our interesting time frame at every X-th day during time Range.
define timeperiod{ timeperiod_name X-th_day alias X-th Day 2007-01-01 - 2008-02-01 / 3 00:00-24:00 # Every 3 days from January 1st, 2007 to February 1st, 2008 2008-04-01 / 7 00:00-24:00 # Every 7 days from April 1st, 2008 (continuing forever) monday 3 - thursday 4 / 2 00:00-24:00 # Every other day from 3rd Monday to 4th Thursday of every month day 1 - 15 / 5 00:00-24:00 # Every 5 days from the 1st to the 15th day of every month july 10 - 15 / 2 00:00-24:00 # Every other day from July 10th to July 15th of every year tuesday 1 april - friday 2 may / 6 00:00-24:00 # Every 6 days from the 1st Tuesday in April to the 2nd Friday in May of every year }
How to benefit from “timeperiod”
Until this point it was described common usage of configuration possibilities. It is important to understand all described options to benefit from the provided possibilities.
Working hours without public holidays
At this example I would like to describe hot to configure ”timeperiod” object at Nagios Core that can be used to define the time interesting time frame for monitoring our infrastructure.
define timeperiod{ timeperiod_name our_public_holidays # Create a list of your Public Holidays alias Our Public Holidays january 1 00:00-00:00 # New Years december 25 00:00-00:00 # Christmas december 26 00:00-00:00 # Christmas } define timeperiod{ timeperiod_name working_hours_without_public_holidays # This time period will be used at for service/host/... object definition alias Working hours without public holidays exclude our_public_holidays # Exclude the list of Public holidays monday 00:90-16:00 # Standard office hours tuesday 00:90-16:00 # Standard office hours wednesday 00:90-16:00 # Standard office hours thursday 00:90-16:00 # Standard office hours friday 00:90-16:00 # Standard office hours }
URL's
Nagios Core 3 “timeperiof” documentation: http://nagios.sourceforge.net/docs/nagioscore/3/en/timeperiods.html
Nagios Core 4 “timeperiof” documentation: http://nagios.sourceforge.net/docs/nagioscore/4/en/timeperiods.html