Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Nagios Core Administration Cookbook

You're reading from   Nagios Core Administration Cookbook The ideal book for System Administrators who want to move their network monitoring to an advanced level. This book covers the powerful features and flexibility of Nagios Core, and its recipes can be applied to virtually any network.

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849515566
Length 366 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Tom Ryder Tom Ryder
Author Profile Icon Tom Ryder
Tom Ryder
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Nagios Core Administration Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Understanding Hosts, Services, and Contacts 2. Working with Commands and Plugins FREE CHAPTER 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 to allow 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 that it doesn't include the evenings. We'll make a new one from scratch, and we'll make another one to cover the weekends too.

Getting ready

You should have a working Nagios Core 3.0 or better server running.

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. Restart the Nagios Core server:

    # /etc/init.d/nagios restart
    

How it works...

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

We've just added two more of these time periods, which we can now use in our definitions for hosts and services. The first is called weekdays, and corresponds to any time during a weekday; the second is called weekends, and 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 they corresponded.

There's more...

The definitions for dates are quite clever, and can be defined in a variety of ways. The following are all valid definitions for days and time periods:

  • june 1 - july 15 00:00-24:00: Any time from June 1st to July 15th, inclusive

  • thursday -1 00:00-24:00: Any time on the last Thursday of every month

  • day 1 - 10 13:00-21:00: From 1 PM to 9 PM on any day from the 1st of any month to the 10th of any month, inclusive

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 well 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 at least some way around the clock, but dealing with the notifications in different ways depending on schedule; for example, we could page the systems administrators about a non-critical system during work hours, but just e-mail them when they're asleep!

See also

  • The Automating contact rotation, Configuring notification periods, and Configuring notification groups recipes in Chapter 4, Configuring Notifications

lock icon The rest of the chapter is locked
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 $19.99/month. Cancel anytime
Banner background image