Preface
Nagios Core, the open source version of the Nagios monitoring framework, is an industry standard for network monitoring hosted on Unix-like systems, such as GNU/Linux or BSD. It is very often used by network and system administrators for checking connectivity between hosts and ensuring that network services are running as expected.
Where home-grown scripts performing network checks can rapidly become unmaintainable and difficult for newer administrators to customize safely, Nagios Core provides a rigorous and configurable monitoring framework to make checks in a consistent manner and to alert appropriate people and systems of any problem it detects.
This makes Nagios Core a very general monitoring framework rather than an out-of-the-box monitoring solution, which is known to make it a little unfriendly to beginners and something of a "black box", even to otherwise experienced administrators. Busy administrators charged with setting up a Nagios Core system will often set it up to send PING requests to a set of hosts every few minutes and send them an e-mail about any problem, and otherwise never touch it. More adventurous administrators new to the system might instate a few HTTP checks to make sure that company websites respond.
Nagios Core is capable of a great deal more than that, and this book's recipes are intended to highlight all of the different means of refining and controlling checks, notifications, and reporting for Nagios Core, rather than being a list of instructions for using specific plugins, of which there are many hundreds available online at the Nagios Exchange at http://exchange.nagios.org/. The book's fundamental aim is to get administrators excited about the possibilities of Nagios Core beyond elementary default checking behavior, so that they can use much more of the framework's power, and make it into the centerpiece of their network monitoring.
This also includes installing and even writing custom plugins beyond the standard Nagios Plugins set, writing and refining one's own checks, working with the very powerful Simple Network Management Protocol (SNMP), recording and reporting of performance data, refining notification behavior to only send appropriate notifications at appropriate times to appropriate people or systems, basic visualization options, identifying breakages in network paths, clever uses of the default web interface, and even extending Nagios Core with other open source programs, all in order to check virtually any kind of host property or network service on any network.
Where possible, this book focuses on add-ons written by the Nagios team themselves, particularly NRPE and NSCA. It omits discussion of the popular NRPE replacement check_mk
, and of popular forks of Nagios Core such as Icinga. In the interest of conferring an in-depth understanding of advanced Nagios Core configuration, it also does not discuss any configuration frontends or wizards such as NConf. Finally, as a Packt open source series book focusing on the use of the freely available Nagios Core, it also does not directly discuss the use of Nagios XI, the commercial version of the software supported by the Nagios team. This is done to instill a thorough understanding of Nagios Core itself, rather than to reflect personal opinions of the author; curious administrators should definitely investigate all of these projects (particularly check_mk
).
What this book covers
Chapter 1, Understanding Hosts, Services, and Contacts, explains the basic building blocks of Nagios Core configurations and how they interrelate, and discusses using groups with each one.
Chapter 2, Working with Commands and Plugins, explains the architecture of plugins and commands, including installing new plugins, defining custom uses of existing ones, and walks us through for writing a new plugin with Perl.
Chapter 3, Working with Checks and States, explains how Nagios Core performs its checks and how to customize that behavior, including scheduling downtime for hosts and services, and managing "flapping" for hosts or services that keep going up and down.
Chapter 4, Configuring Notifications, explains the logic of how Nagios Core decides on what basis to notify, and when and to whom, including examples of implementing a custom notification method, escalating notifications that aren't fixed after a certain period of time, and scheduling contact rotation.
Chapter 5, Monitoring Methods, gives examples of usage of some of the standard Nagios Plugins set, moving from basic network connectivity checks with PING and HTTP to more complex and powerful checks involving SNMP usage.
Chapter 6, Enabling Remote Execution, shows how to use NRPE as a means of working around the problem of not being able to check system properties directly over the network, including a demonstration of the more advanced method of check_by_ssh
.
Chapter 7, Using the Web Interface, shows some less-used features of the web interface to actually control how Nagios Core is behaving and to see advanced reports, rather than simply viewing current state information. Use of the network map is not discussed here but in the next chapter.
Chapter 8, Managing Network Layout, explains how to make Nagios Core aware of the structure and function of your network, with a focus on hosts and services depending on one another to function correctly, including monitoring clusters, and using that layout information to build a network status map, optionally with icons and a background.
Chapter 9, Managing Configuration, shows how to streamline, refine, and control Nagios Core configuration at a low level without the use of frontends. It focusses on the clever use of groups, templates, and macros, and gives an example of generating configuration programmatically with the templating language m4
.
Chapter 10, Security and Performance, shows how to manage simple access control, debugging runtime problems, and keeping tabs on how Nagios Core is performing, as well as a demonstration of basic monitoring redundancy.
Chapter 11, Automating and Extending Nagios Core, explains how to submit check results from other programs (including NSCA) to provide information about external processes via the commands file, and an introduction to a few popular add-ons (NDOUtils, NagVis, and Nagiosgrapher).
What you need for this book
In an attempt to work with a "standard" installation of Nagios Core, this book's recipes assume that Nagios Core 3.0 or later and the Nagios plugins set have been installed in /usr/local/nagios
, by following the Nagios Quickstart Guides available at http://nagios.sourceforge.net/docs/3_0/quickstart.html.
If your system's package repositories include a package for Nagios Core 3.0 or later that you would prefer to use, this should still be possible, but the paths of all the files are likely to be very different. This is known to be a particular issue with the nagios3
package on Debian or Ubuntu systems. If you are familiar with the differences in the installation layout that your packaging system imposes, then you should still be able to follow the recipes with only some path changes.
For the screenshots of the web interface, the familiar Nagios Classic UI is used (with white-on-black menu), which was the default from Version 3.0 for several years before the newer "Exfoliation" style (with black-on-white menu) became the default more recently. Some of the graphical elements and styles are different, but everything has the same text and is in the same place, so it's not necessary to install the Classic UI to follow along with the recipes if you already have the Exfoliation style installed.
If you really want the Classic UI so that what you're seeing matches the screenshots exactly, you can install it by adding this as the final step of your installation process:
# make install-classicui
This book was written while the alpha of Nagios Core 4.0 was being tested. I have reviewed the change logs of the alpha release so far, and am reasonably confident that all of the recipes should work in this newer version's final release. If after Nagios Core 4.0 is released you do find some issues with using some of the recipes for it, please see the "Errata" section to let the publisher and author know.
Who this book is for
This book is aimed at system and network administrators comfortable with basic Unix-like system administration via the command line. It is best suited for GNU/Linux administrators, but should work fine for BSD administrators too. It has particular focus on the kind of administrator identified in the preface: one who is comfortable working with their Unix-like system, may well have a basic Nagios Core installation ready with some PING checks, and now wants to learn how to use much more of the framework's power and understand its configuration in more depth.
Administrators should be comfortable with installing library dependencies for the extensions, plugins, and add-ons discussed in the book. An effort is made to mention any dependencies; however, how these are best installed will depend on the system and its package repository. In almost all cases this should amount to installing some common libraries and their headers from a packaging system. Debian and Ubuntu package names are given for some more complex cases.
The easier recipes in the first five chapters involve some recap of the basics of configuring Nagios Core objects. Users completely new to Nagios Core who have just installed it will almost certainly want to start with Chapter 1, Understanding Hosts, Services, and Contacts, after completing the Nagios Quickstart Guide, as latter chapters assume a fair amount of knowledge.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "Nagios Core will only need whatever information the PING tool would need for its own check_ping
command".
A block of code is set as follows:
define service { use generic-service host_name sparta.naginet service_description HTTP check_command check_http }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
define host {
host_name sparta.naginet
alias sparta
address 10.128.0.21
max_check_attempts 3
check_period 24x7
check_command check-host-alive
contacts nagiosadmin
notification_interval 60
notification_period 24x7
}
Any command-line input or output is written as follows:
# cd /usr/local/nagios/etc/objects # vi sparta.naginet.cfg
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "If the server restarted successfully, the web interface should show a brand new host in the Hosts list, in PENDING state as it waits to run a check that the host is alive".
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>
, and mention the book title through the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com>
if you are having a problem with any aspect of the book, and we will do our best to address it.