Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Nagios Core Administration Cookbook Second Edition - Second Edition

You're reading from  Nagios Core Administration Cookbook Second Edition - Second Edition

Product type Book
Published in Feb 2016
Publisher
ISBN-13 9781785889332
Pages 386 pages
Edition 2nd Edition
Languages
Author (1):
Tom Ryder Tom Ryder
Profile icon Tom Ryder

Table of Contents (18) Chapters

Nagios Core Administration Cookbook Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Understanding Hosts, Services, and Contacts 2. Working with Commands and Plugins 3. Working with Checks and States 4. Configuring Notifications 5. Monitoring Methods 6. Enabling Remote Execution 7. Using the Web Interface 8. Managing Network Layout 9. Managing Configuration 10. Security and Performance 11. Automating and Extending Nagios Core Index

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 individual 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

You have been reading a chapter from
Nagios Core Administration Cookbook Second Edition - Second Edition
Published in: Feb 2016 Publisher: ISBN-13: 9781785889332
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}