- Nagios Core Administration Cookbook(Second Edition)
- Tom Ryder
- 605字
- 2021-07-16 12:51:50
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:
- Change to our Nagios Core configuration objects directory and edit the file called
timeperiods.cfg
:# cd /usr/local/nagios/etc/objects # vi timeperiods.cfg
- 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 }
- 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, inclusivethursday -1 00:00-24:00
: This syntax denotes the last Thursday of every monthday 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
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- Practical UX Design
- 垃圾回收的算法與實現
- Java從入門到精通(第5版)
- Apache Spark Graph Processing
- 精通網絡視頻核心開發技術
- Python機器學習:手把手教你掌握150個精彩案例(微課視頻版)
- Azure Serverless Computing Cookbook
- Serverless Web Applications with React and Firebase
- 零基礎學C語言(升級版)
- 深度學習程序設計實戰
- ROS機器人編程實戰
- 分布式系統架構與開發:技術原理與面試題解析
- Learning Puppet
- Swift iOS Programming for Kids