≡ Menu

How to Define Nagios Timeperiod Exclude for Maintenance Window

Q: I have setup nagios to monitor my servers. However, I perform some regular daily maintenance on this server. I don’t want Nagios to send me any notification during this this daily regular downtime window. How can I achieve this?

A: You can use any one of the method shown here to handle this situation. By default, you’ll see the following 24×7 timeperiod in the timeperiod.cfg file.

This 24×7 timeperiod can be used in your service definition for check_period and notification_period. By default, if you don’t define check_period and notification_period, it inherits this 24×7 timeperiod from the default service template.

$ vi /usr/local/nagios/etc/objects/timeperiod.cfg
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
        }

Method 1: Define new Timeperiod with a Specific Time Range

The first option would be to define a new timeperiod with the specific timeslots that you want Nagios to monitor the services every day.

In the following example, it includes 2 a.m until midnight for every day. So, this excludes midnight until 1:59 a.m.

$ vi /usr/local/nagios/etc/objects/timeperiod.cfg
define timeperiod{
        timeperiod_name 24x7-except-night-12-2
        alias           24x7 Except 00:00 - 02:00
        sunday          02:00-23:59
        monday          02:00-23:59
        tuesday         02:00-23:59
        wednesday       02:00-23:59
        thursday        02:00-23:59
        friday          02:00-23:59
        saturday        02:00-23:59
}

For example, if you are bringing down your HTTP server everyday sometime between midnight and 1:59 a.m, you can specify the above “24×7-except-night-12-2” timeperiod in your service definition for the check_period and notification_period as shown below for your particular service definition.

$ vi /usr/local/nagios/etc/servers/devserver.cfg
define service{
        use                             generic-service
        host_name                       devserver
        service_description             HTTP
        contacts                        ramesh
        check_command                   check_http
        check_period                    24x7-except-night-12-2
        notification_period             24x7-except-night-12-2
        }

Method 2: Using Exclude Directive

First define a timeperiod for the time that you like to exclude. This is defined just like any other timeperiod. In this example, this timeperiod covers from 23:01 p.m until 2:00 a.m only for Friday.

$ vi /usr/local/nagios/etc/objects/timeperiod.cfg
define timeperiod{
        timeperiod_name weekly-maintenance
        alias           Weekly Maintenance Windows
        friday          23:01-02:00
}

Next, define another time period where you want the above time period to be excluded. In the following example, I’ve created “24x7_except_maintenance” time period, which is similar to the 24×7 time period. Except this one also has the “exclude” directive, which excluded the above “weekly-maintenance” time period.

define timeperiod{
        timeperiod_name 24x7_except_maintenance
        alias           24x7 Except Weekly Maintenance
        exclude         weekly-maintenance
        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
}

The idea here is that if you use “24x7_except_maintenance” timeperiod in your service definition for check_period and notification_period, it will not check or send any notification during the “weeekly-maintenance” timeslot for that particular service.

$ vi /usr/local/nagios/etc/servers/devserver.cfg
define service{
        use                             generic-service
        host_name                       devserver
        service_description             HTTP
        contacts                        ramesh
        check_command                   check_http
        check_period                    24x7-except_maintenance
        notification_period             24x7-except_maintenance
        }

Warning: For some reason I couldn’t get this method to work consistently. For some scenarios I got it working, and for some scenarios it doesn’t work. Upon further research, I found out that this is known bug.

Method 3: Define new Timeperiod with Multiple Time Ranges

You can also specify multiple timeranges for every day using comma delimited values. In the following example, I’ve specified different time ranges for few days.

$ vi /usr/local/nagios/etc/objects/timeperiod.cfg
define timeperiod{
        timeperiod_name multiple-time-slots
        alias           Multiple Time Slots
        sunday          00:00-18:00,20:00-24:00
        monday          00:00-18:00,20:00-21:00,23:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-20:00,22:00-24:00
        saturday        00:00-23:00
}

For example, if you are bringing down your HTTP server at different time everyday as defined in the above multiple-time-slots. i.e If you are bringing it down during the timeslots that are not mentioned in the above “multiple-time-slots” value, you can specify those in the check_period and the notification_period of your HTTP service definition as shown below.

$ vi /usr/local/nagios/etc/servers/devserver.cfg
define service{
        use                             generic-service
        host_name                       devserver
        service_description             HTTP
        contacts                        ramesh
        check_command                   check_http
        check_period                    multiple-time-slots
        notification_period             multiple-time-slots
        }

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 2 comments… add one }

  • dilip varma September 27, 2013, 12:28 am

    Hi,
    very useful.

    Could you please tell me how to configure nagios on rehdat linux 64bit?

    Thanks in advance
    Dilip

  • pree December 10, 2015, 11:53 am

    Hi there, this is great but I am a GUI person, I need to schedule one service to be down each night for few hours, can I do that via GUI?

Leave a Comment