官术网_书友最值得收藏!

Creating a new time period

In this recipe, we'll add a new time period definition to the Nagios Core configuration so that it allows us to set up monitoring for hosts and services only during weekdays. There's a default configuration defined as workhours that would almost suit us, except it doesn't include evenings, so we'll make a new one from scratch. We'll make another one to cover the weekends, too.

Getting ready

You should have a working Nagios Core 4.0 or better server running. You should also have a clear idea about when the boundaries for the time period you want to define are.

How to do it...

We can set up our new time period, which we'll call weekdays, as follows:

  1. Change to our Nagios Core configuration objects directory and edit the file called timeperiods.cfg:
    # cd /usr/local/nagios/etc/objects
    # vi timeperiods.cfg
    
  2. Add the following definitions to the end of the file:
    define timeperiod {
        timeperiod_name  weekdays
        alias            Weekdays
        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
    }
    define timeperiod {
        timeperiod_name  weekends
        alias            Weekends
        saturday         00:00-24:00
        sunday           00:00-24:00
    }
  3. Reload the configuration:
    # /etc/init.d/nagios reload
    

How it works...

In our host and service definitions, there are two directives, check_period and notification_period, which are used to define the times during which a host or service should be checked and the times when notifications about it should be sent. The two examples normally defined in the stock Nagios Core configuration are the 24x7 period and the workhours period, which are defined in the timeperiods.cfg file that we just edited and used in several of the examples and templates.

We've just added two more of these time periods that we can now use in our definitions for hosts and services. The first is called weekdays, which corresponds to any time during a weekday; the second is called weekends, which corresponds to any time that's not a weekday. Note that, in both cases, we specified the dates and times by naming each inpidual day and the times to which it corresponded.

There's more...

The definitions for dates are flexible, and can be defined a variety of ways. The following are all valid syntaxes to define days and time periods:

  • june 1 – july 15 00:00-24:00: This syntax denotes June 1 to July 15, inclusive
  • thursday -1 00:00-24:00: This syntax denotes the last Thursday of every month
  • day 1 – 10 13:00-21:00: This syntax denotes the time from 1 p.m. to 9 p.m. on any day from the 1st day of any month to the 10th day of the same month

In a typical practice, it's likely that the standard 24x7 and workhours definitions will be fine for day-to-day monitoring, maybe with a weekdays and weekends definition added. However, there may come a time when we need a specific host or service monitored on an unusual schedule, particularly if we're debugging a specific problem that only manifests around a certain time, or have a lot of contacts to manage, or a complex on-call roster.

Note that Nagios Core can behave in unusual ways, particularly with uptime reporting, if the time periods for our monitoring of hosts and services don't add up to 24 hours. Ideally, we should check and notify all our hosts and services in some way around the clock, but by dealing with the notifications in different ways depending on the schedule, for example paging the systems administrators about a noncritical system during work hours but just e-mailing them when they're asleep!

See also

  • Automating contact rotation, Chapter 4, Configuring Notifications
  • Configuring notification periods, Chapter 4, Configuring Notifications
  • Configuring notification groups, Chapter 4, Configuring Notifications
主站蜘蛛池模板: 鄂伦春自治旗| 潞西市| 盐源县| 青田县| 古田县| 平阴县| 东乌珠穆沁旗| 湘乡市| 田阳县| 平顶山市| 新余市| 辉南县| 屏山县| 尼勒克县| 平原县| 鄂尔多斯市| 昌江| 炎陵县| 托里县| 淳安县| 东源县| 冀州市| 威海市| 工布江达县| 兖州市| 石景山区| 连城县| 松原市| 昌宁县| 深州市| 根河市| 交口县| 二连浩特市| 磐安县| 漠河县| 吉林市| 曲阳县| 巴林左旗| 涞水县| 澄城县| 神农架林区|