2

I have a event handler configured and running in nagios which is triggered every time a given service is in a CRITICAL state.

The problem is that we decided that in regular working hours there's no need to run the event handler as we can fix the problem by hand and in a more efficient way.

The question is, is there any way I can setup this event handler to run just in a given periot of time and yet be normally notified of the CRITICAL state? Let's say in non-working hours?

Thanks in advance for your help.

1
  • How is fixing a problem by hand, where there is an acceptable fix that can be automated, ever more efficient?
    – dunxd
    Aug 4, 2011 at 15:32

3 Answers 3

2

Take a look at the Nagios macro ISVALIDTIME.

This is a special on-demand macro that returns a 1 or 0 depending on whether or not a particular time is valid within a specified timeperiod. There are two ways of using this macro:

$ISVALIDTIME:24x7$ will be set to "1" if the current time is valid within the "24x7" timeperiod. If not, it will be set to "0".
$ISVALIDTIME:24x7:timestamp$ will be set to "1" if the time specified by the "timestamp" argument (which must be in time_t format) is valid within the "24x7" timeperiod. If not, it will be set to "0".

Don't know whether this is present in the service context, but you can test it. Define a timeperiod "non-working hours" and take ISVALIDTIME as a parameter to your eventhandler script. When the script is called during working hours, let it do nothing and exit.

When this doesn't work, you could just verify the time of day in the eventhandler script.

0

Before I launch into the actual answer, a gotcha to watch out for: when I set up our call routing system to intelligently, rather than manually, handle 'working hours', I completely forgot to allow for public holidays, leaving urgent customer calls ringing in an empty office for half of the following bank holiday Monday.

I'm sure you'll be more careful than that :-)

That caveat aside, it looks from the docs like want to define some timeperiod objects in your Nagios config, e.g:

define timeperiod{
    timeperiod_name workhours
    alias           "Normal" Working Hours
    monday          08:00-17:00
    tuesday         08:00-17:00
    wednesday       08:00-17:00
    thursday        08:00-17:00
    friday          08:00-17:00
}

And then invoke them with check_period in your service config:

define service{
    use                             some-service
    name                            service-name
    ...
    check_period                    24x7
    ...
}
2
  • No no. It make the service will not be check in non-specific time period.
    – quanta
    Aug 4, 2011 at 14:55
  • If I'm parsing the above comment correctly, then if there is a problem with the above you can just invert the time period definitions, surely. Aug 4, 2011 at 15:17
0

If you really want to do that, I have an idea (this is the first thing comes to my mind):

  1. put the service definition in a seperate file to make it easier
  2. write a script to check the current time
  3. at the start time of working hours you will comment the event_handler line in config file and at the end time you will comment out. (you can do it with sed)

Try this and let me know if it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .