Wednesday, April 11, 2012

How to make Nagios monitor its service at particular Time Period

I am considering that you already know how to add custom services. If not, please have a look at my previous post:  http://codebyte.blogspot.com/2012/03/adding-custom-services-for-windows-host.html

Suppose you want to monitor your service at 16:00 to 16:15 and 18:00 to 18:15 hours everyday.

First of all, you need to open your timeperiod.cfg file in your nagios server installation directory.
Add the following lines,
define timeperiod{
         timeperiod_name               24X7custom
         alias                                   24X7custom
         sunday                               16:00-16:15,18:00-18:15
         monday                             16:00-16:15,18:00-18:15
         tuesday                             16:00-16:15,18:00-18:15
         wednesday                        16:00-16:15,18:00-18:15
         thursday                           16:00-16:15,18:00-18:15
         friday                                16:00-16:15,18:00-18:15
         saturday                           16:00-16:15,18:00-18:15
}

Here, timeperiod_name and alias are any names you give for this specific time period.
16:00-16:15 means monitoring of your service starts from 16:00 hour and then end at 16:15. The monitoring interval depends on the service used. Under normal condition, service will be checked every 10 minutes for generic service. Again, your service will be checked from 18:00 to 18:15 hours as defined. Note that, separate time periods are kept as comma separated values.

After this, in windows.cfg file inside your nagios server installation directory, add one line in the service you have defined:

check_period                    24X7custom

So the whole service definition looks like:
define service{
                   use                                     generic_service
                   check_period                    24X7custom
                   host_name                        your-host-name
                   service_description          your-service-description
                  check_command               your-service-command 
}

Finally, restart nagios server: /etc/init.d/nagios restart

3 comments:

  1. Shouldn't define timestamp be define timeperiod?

    ReplyDelete
    Replies
    1. Thanks for pointing it out. I made the correction.

      Delete
  2. thank you very much . i'm just looking for this.

    ReplyDelete