Nagios, 2nd Edition: System and Network Monitoring
4/5
()
About this ebook
Nagios, which runs on Linux and most *nix variants, can be configured to continuously monitor network services such as SMTP, POP3, HTTP, NNTP, SSH, and FTP. It can also supervise host resources (processor load, disk and memory usage, running processes, log files, and so on) and environmental factors, such as temperature and humidity. This book is your guide to getting the most out of this versatile and powerful monitoring tool.
Inside Nagios, you’ll learn how to:
–Install and configure the Nagios core, all standard plugins, and selected third-party plugins
–Configure the notification system to alert you of ongoing problems—and to alarm others in case of a serious crisis
–Program event handlers to take automatic action when trouble occurs
–Write Perl plugins to customize Nagios for your unique needs
–Quickly understand your Nagios data using graphing and visualization tools
–Monitor Windows servers, SAP systems, and Oracle databases
The book also includes a chapter that highlights the differences between Nagios versions 2 and 3 and gives practical migration and compatibility tips. Nagios: System and Network Monitoring, 2nd Edition is a great starting point for configuring and using Nagios in your own environment.
Related to Nagios, 2nd Edition
Related ebooks
CentOS Stream 9 Essentials: Learn to Install, Administer, and Deploy CentOS Stream 9 Systems Rating: 0 out of 5 stars0 ratingsFedora 31 Essentials: Learn how to install, administer, and deploy Fedora 31 systems Rating: 0 out of 5 stars0 ratingsRocky Linux 9 Essentials: Learn to Install, Administer, and Deploy Rocky Linux 9 Systems Rating: 0 out of 5 stars0 ratings978-1-951442-67-5: Learn to Install, Administer, and Deploy Rocky Linux 9 Systems Rating: 0 out of 5 stars0 ratingsAlmaLinux 9 Essentials: Learn to Install, Administer, and Deploy Rocky Linux 9 Systems Rating: 0 out of 5 stars0 ratingsCybersecurity Blue Team Toolkit Rating: 2 out of 5 stars2/5Snow Leopard Server Rating: 0 out of 5 stars0 ratingsKali Linux Penetration Testing Bible Rating: 0 out of 5 stars0 ratingsCentOS 8 Essentials: Learn to Install, Administer and Deploy CentOS 8 Systems Rating: 0 out of 5 stars0 ratingsCentOS 8 Essentials: Get ready to use this free, widely-used enterprise level operating system Rating: 0 out of 5 stars0 ratingsSecuring DevOps: Security in the Cloud Rating: 0 out of 5 stars0 ratingsPython Real-World Projects: Craft your Python portfolio with deployable applications Rating: 0 out of 5 stars0 ratingsMastering Windows Server 2016 Rating: 0 out of 5 stars0 ratingsUnderstanding TCP/IP Rating: 4 out of 5 stars4/5MCSA Windows Server 2012 R2 Administration Study Guide: Exam 70-411 Rating: 5 out of 5 stars5/5Ubuntu 20.04 Essentials: A Guide to Ubuntu 20.04 Desktop and Server Editions Rating: 0 out of 5 stars0 ratingsCompTIA CySA+ Study Guide: Exam CS0-003 Rating: 2 out of 5 stars2/5CompTIA Cloud+ Study Guide: Exam CV0-003 Rating: 0 out of 5 stars0 ratingsSet Up Your Own IPsec VPN, OpenVPN and WireGuard Server: Build Your Own VPN Rating: 5 out of 5 stars5/5CompTIA PenTest+ Study Guide: Exam PT0-002 Rating: 0 out of 5 stars0 ratingsLearn System Center Configuration Manager in a Month of Lunches: Covers SCCM 1511 and Windows 10 Rating: 0 out of 5 stars0 ratingsBuilding Web APIs with ASP.NET Core Rating: 0 out of 5 stars0 ratingsRed Hat Enterprise Linux 9 Essentials: Learn to Install, Administer and Deploy RHEL 9 Systems Rating: 0 out of 5 stars0 ratingsLearning Nagios - Third Edition Rating: 0 out of 5 stars0 ratingsMastering Windows Server 2022 with Azure Cloud Services: IaaS, PaaS, and SaaS Rating: 0 out of 5 stars0 ratingsHallo Nginx: Deploying and Optimizing Modern Web Applications Rating: 0 out of 5 stars0 ratingsLogs and Telemetry: Using Fluent Bit, Kubernetes, streaming and more Rating: 0 out of 5 stars0 ratings.NET Core in Action Rating: 0 out of 5 stars0 ratingsUbuntu 18.04 Essentials: Learn to Install, Administer and Use Ubuntu 18.04 Systems Rating: 0 out of 5 stars0 ratings
Security For You
Social Engineering: The Science of Human Hacking Rating: 3 out of 5 stars3/5CompTIA Security+ Study Guide: Exam SY0-601 Rating: 5 out of 5 stars5/5Make Your Smartphone 007 Smart Rating: 4 out of 5 stars4/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5How to Become Anonymous, Secure and Free Online Rating: 5 out of 5 stars5/5Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5Wireless Hacking 101 Rating: 5 out of 5 stars5/5Hacking For Dummies Rating: 4 out of 5 stars4/5Cybersecurity All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsIAPP CIPP / US Certified Information Privacy Professional Study Guide Rating: 0 out of 5 stars0 ratingsDark Territory: The Secret History of Cyber War Rating: 4 out of 5 stars4/5CompTIA Network+ Practice Tests: Exam N10-008 Rating: 0 out of 5 stars0 ratingsCompTIA Network+ Review Guide: Exam N10-008 Rating: 0 out of 5 stars0 ratingsMike Meyers CompTIA Security+ Certification Passport, Sixth Edition (Exam SY0-601) Rating: 5 out of 5 stars5/5Cybersecurity For Dummies Rating: 5 out of 5 stars5/5Hacking Point of Sale: Payment Application Secrets, Threats, and Solutions Rating: 5 out of 5 stars5/5CompTIA Security+ Study Guide with over 500 Practice Test Questions: Exam SY0-701 Rating: 5 out of 5 stars5/5How to Hack Like a Pornstar Rating: 5 out of 5 stars5/5Blockchain Basics: A Non-Technical Introduction in 25 Steps Rating: 4 out of 5 stars4/5The Cyber Attack Survival Manual: Tools for Surviving Everything from Identity Theft to the Digital Apocalypse Rating: 0 out of 5 stars0 ratingsThe Art of Intrusion: The Real Stories Behind the Exploits of Hackers, Intruders and Deceivers Rating: 4 out of 5 stars4/5Codes and Ciphers - A History of Cryptography Rating: 4 out of 5 stars4/5CompTIA Network+ Certification Guide (Exam N10-008): Unleash your full potential as a Network Administrator (English Edition) Rating: 0 out of 5 stars0 ratingsCybersecurity: The Beginner's Guide: A comprehensive guide to getting started in cybersecurity Rating: 5 out of 5 stars5/5Apple Card and Apple Pay: A Ridiculously Simple Guide to Mobile Payments Rating: 0 out of 5 stars0 ratingsCodes and Ciphers Rating: 5 out of 5 stars5/5IAPP CIPM Certified Information Privacy Manager Study Guide Rating: 0 out of 5 stars0 ratingsHow to Hack Like a GOD: Master the secrets of hacking through real-life hacking scenarios Rating: 4 out of 5 stars4/5
Reviews for Nagios, 2nd Edition
7 ratings0 reviews
Book preview
Nagios, 2nd Edition - Wolfgang Barth
Nagios: System and Network Monitoring, 2nd Edition
Table of Contents
Foreword to the second edition What's New in the Second Edition? Information Sources on the Internet Introduction The tests The suppliers of information Keeping admins up-to-date Taking in information from outside Other tools for network monitoring About This Book Further notes on the book Note of Thanks I. From Source Code to a Running Installation 1. Installation 1.1 Preparations 1.1.1 Determining and setting up the required users 1.2 Compiling Source Code 1.3 Starting Nagios Automatically 1.4 Installing and Testing Plugins 1.4.1 Installation 1.4.2 Plugin test 1.5 Configuration of the Web Interface 1.5.1 Setting up Apache 1.5.2 SELinux 1.5.3 User authentication 2. Nagios Configuration 2.1 The Main Configuration File nagios.cfg Simple structure 2.2 Objects—an Overview Notes on the object examples below 2.3 Defining the Machines to Be Monitored, with host 2.4 Grouping Computers Together with hostgroup 2.5 Defining Services to Be Monitored with service 2.6 Grouping Services Together with servicegroup 2.7 Defining Addressees for Error Messages: contact 2.8 The Message Recipient: contactgroup 2.9 When Nagios Needs to Do Something: The command Object 2.10 Defining a Time Period with timeperiod 2.11 Templates 2.12 Configuration Aids for Those Too Lazy to Type 2.12.1 Defining services for several computers 2.12.2 One host group for all computers 2.12.3 Other configuration aids 2.13 CGI Configuration in cgi.cfg 2.14 The Resources File resource.cfg 3. Startup 3.1 Checking the Configuration 3.2 Getting Monitoring Started 3.2.1 Manual start 3.2.2 Making configuration changes come into effect 3.3 Overview of the Web Interface II. In More Detail... 4. Nagios Basics 4.1 Taking into Account the Network Topology 4.2 On-Demand Host Checks vs. Periodic Reachability Tests 4.3 States of Hosts and Services 5. Service Checks and How They Are Performed 5.1 Testing Network Services Directly 5.2 Running Plugins via Secure Shell on the Remote Computer 5.3 The Nagios Remote Plugin Executor 5.4 Monitoring via SNMP 5.5 The Nagios Service Check Acceptor 6. Plugins for Network Services 6.1 Standard Options 6.2 Reachability Test with Ping 6.2.1 check_icmp as a Service Check 6.2.2 check_icmp as a Host Check 6.3 Monitoring Mail Servers 6.3.1 Monitoring SMTP with check_smtp 6.3.2 POP and IMAP 6.4 Monitoring FTP and Web Servers 6.4.1 FTP services 6.4.2 Web server control via HTTP 6.4.3 Monitoring Web proxies 6.5 Domain Name Server Under Control 6.5.1 DNS check with nslookup 6.5.2 Monitoring the name server with dig 6.6 Querying the Secure Shell Server 6.7 Generic Network Plugins 6.7.1 Testing TCP ports 6.7.2 Monitoring UDP ports 6.8 Monitoring Databases 6.8.1 PostgreSQL 6.8.2 MySQL 6.9 Monitoring LDAP Directory Services 6.10 Checking a DHCP Server Granting the plugin root permissions 6.11 Monitoring UPS with the Network UPS Tools The Network UPS Tools 6.12 Health Check of an NTP Server with check_ntp_peer 7. Testing Local Resources 7.1 Free Hard Drive Capacity 7.2 Utilization of the Swap Space 7.3 Testing the System Load 7.4 Monitoring Processes 7.5 Checking Log Files 7.5.1 The standard plugin check.log 7.5.2 The modern variation: check_logs.pl 7.5.3 The Swiss Army knife: check_logfiles 7.6 Keeping Tabs on the Number of Logged-In Users 7.7 Checking the System Time 7.7.1 Checking the system time via NTP 7.7.2 Checking system time with the time protocol 7.8 Regularly Checking the Status of the Mail Queue 7.9 Keeping an Eye on the Modification Date of a File 7.10 Monitoring UPSs with apcupsd 7.11 Nagios Monitors Itself 7.11.1 Running the plugin manually with a script 7.12 Hardware Checks with LM Sensors 8. Plugins for Special Tasks 8.1 The Dummy Plugin for Tests 8.2 Negating Plugin Results 8.3 Inserting Hyperlinks with urlize 8.4 Checking Host or Service Clusters as an Entity 8.5 Summarizing Checks with check_multi 8.5.1 Multiple-line plugin output 8.5.2 Installation requirements 8.5.3 Installation and testing 8.5.4 Configuration file 8.5.5 Command-line parameters 8.5.6 Performance data and PNP 8.5.7 Simple business process monitoring 9. Executing Plugins via SSH 9.1 The check_by_ssh Plugin 9.2 Configuring SSH 9.2.1 Generating SSH key pairs on the Nagios server 9.2.2 Setting up the user nagios on the target host 9.2.3 Checking the SSH connection and check_by_ssh 9.3 Nagios Configuration 10. The Nagios Remote Plugin Executor (NRPE) 10.1 Installation 10.1.1 Distribution-specific packages 10.1.2 Installation from the source code 10.2 Starting via the inet Daemon 10.2.1 xinetd configuration 10.2.2 inetd configurationt 10.2.3 Is the Inet daemon watching on the NRPE port? 10.3 NRPE Configuration on the Computer to Be Monitored 10.3.1 Passing parameters on to local plugins 10.4 NRPE Function Test 10.5 Nagios Configuration 10.5.1 NRPE without passing parameters on 10.5.2 Passing parameters on in NRPE 10.5.3 Optimizing the configuration 10.6 Indirect Checks 11. Collecting Information Relevant for Monitoring with SNMP 11.1 Introduction to SNMP 11.1.1 The Management Information Base 11.1.2 SNMP protocol versions 11.2 NET-SNMP 11.2.1 Tools for SNMP requests 11.2.2 The NET-SNMP daemon 11.3 Nagios's Own SNMP Plugins 11.3.1 The generic SNMP plugin check_snmp 11.3.2 Checking several interfaces simultaneously 11.3.3 Testing the operating status of individual interfaces 11.4 Other SNMP-based Plugins 11.4.1 Monitoring hard drive space and processes with nagios-snmp-plugins 11.4.2 Observing the load on network interfaces with check-iftraffic 11.4.3 The manubulon.com plugins for special application purposes 12. The Nagios Notification System 12.1 Who Should be Informed of What, When? 12.2 When Does a Message Occur? 12.3 The Message Filter 12.3.1 Switching messages on and off systemwide 12.3.2 Enabling and suppressing computer and service-related messages 12.3.3 Person-related filter options 12.3.4 Case examples 12.4 External Notification Programs 12.4.1 Notification via e-mail 12.4.2 Notification via SMS 12.5 Escalation Management 12.6 Accounting for Dependencies between Hosts and Services 12.6.1 The standard case: service dependencies 12.6.2 Only in exceptional cases: host dependencies 13. Passive Tests with the External Command File 13.1 The Interface for External Commands 13.2 Passive Service Checks 13.3 Passive Host Checks 13.4 Reacting to Out-of-Date Information of Passive Checks 14. The Nagios Service Check Acceptor (NSCA) 14.1 Installation 14.2 Configuring the Nagios Server 14.2.1 The configuration file nsca.cfg 14.2.2 Configuring the inet daemon 14.3 Client-side Configuration 14.4 Sending Test Results to the Server 14.5 Application Example I: Integrating syslog and Nagios 14.5.1 Preparing syslog-ng for use with Nagios 14.5.2 Nagios configuration: volatile services 14.5.3 Resetting error states manually 14.6 Application Example II: Processing SNMP Traps 14.6.1 Receiving traps with snmptrapd 14.6.2 Passing on traps to NSCA 14.6.3 The matching service definition 15. Distributed Monitoring 15.1 Switching On the OCSP/OCHP Mechanism 15.2 Defining OCSP/OCHP Commands 15.3 Practical Scenarios 15.3.1 Avoiding redundancy in configuration files 15.3.2 Defining templates III. The Web Interface and Other Ways to Visualize Nagios Data 16. The Classical Web Interface 16.1 Recognizing and Acting On Problems 16.1.1 Comments on problematic hosts 16.1.2 Taking responsibility for problems 16.2 An Overview of the Individual CGI Programs 16.2.1 Variations in status display: status.cgi 16.2.2 Additional information and control center: extinfo.cgi 16.2.3 Interface for external commands: cmd.cgi 16.2.4 The most important things at a glance: tac.cgi 16.2.5 The topological map of the network: statusmap.cgi 16.2.6 Navigation in 3D: statuswrl.cgi 16.2.7 Querying the status with a cell phone: statuswml.cgi 16.2.8 Analyzing disrupted partial networks: outages.cgi 16.2.9 Querying the object definition with config.cgi 16.2.10 Availability statistics: avail.cgi 16.2.11 What events occur, how often?—histogram.Cgi 16.2.12 Filtering log entries after specific states: history.cgi 16.2.13 Who was told what, when?— notifications.Cgi 16.2.14 Showing all log file entries: showlog.cgi 16.2.15 Evaluating whatever you want: summary.cgi 16.2.16 Following states graphically over time: trends.Cgi 16.3 Planning Downtimes 16.3.1 Maintenance periods for hosts 16.3.2 Downtime for services 16.4 Additional Information on Hosts and Services 16.4.1 Extended host information 16.4.2 Extended service information 16.5 Configuration Changes through the Web Interfaces: the Restart Problem 16.6 Modern Layout with the Nuvola Style 17. Flexible Web Interface with the NDOUtils 17.1 The Event Broker 17.2 The Database Interface 17.3 The Installation 17.3.1 Compiling the source code 17.3.2 Preparing the MySQL database 17.3.3 Upgrading the database design 17.4 Configuration 17.4.1 Adjusting the Event Broker configuration 17.4.2 Configuring database access 17.4.3 Starting the ndo2db daemon 17.4.4 Loading the Event Broker module in Nagios 18. NagVis 18.1 Installation 18.1.1 Installing the source code 18.1.2 Initial configuration 18.1.3 User authentication 18.2 Creating NagVis Maps 18.2.1 Editing the configuration in text form 18.2.2 Adding NagVis maps to the Nagios Web interface 19. Graphic Display of Performance Data 19.1 Processing Plugin Performance Data with Nagios 19.1.1 The template mechanism 19.1.2 Using external commands to process performance data 19.2 Graphs for the Web with Nagiosgraph 19.2.1 Basic installation 19.2.2 Configuration 19.3 Preparing Performance Data for Evaluation with Perf2rrd 19.3.1 Installation 19.3.2 Nagios configuration 19.3.3 Perf2rrd in practice 19.4 The Graphics Specialist drraw 19.4.1 Installation 19.4.2 Configuration 19.4.3 Practical application 19.5 Automated to a Large Extent: NagiosGrapher 19.5.1 Installation 19.5.2 Configuration 19.6 Smooth Plotting with PNP 19.6.1 Installation 19.6.2 The standard configuration 19.6.3 The PNP Web interface 19.6.4 Bulk processing of performance data 19.6.5 How should the graphic appear? 19.7 Other Tools and the Limits of Graphic Evaluation IV. Part IV Special Applications 20. Monitoring Windows Servers 20.1 Agent-less Checks via WMI 20.2 Installing and Configuring the Additional Services 20.2.1 NSClient 20.2.2 NC_Net 20.2.3 NSClient++ 20.2.4 OpMon Agent 20.2.5 Rectifying problems with port 1248 20.3 The check_nt Plugin 20.3.1 Generally supported commands 20.3.2 Advanced functions of NC_Net 20.3.3 Installing the check_ncnet plugin 20.4 NRPE for Windows 20.4.1 NRPE_NT, the classic tool 20.4.2 Plugins for NRPE in Windows 20.4.3 NRPE with NSClient++ 20.4.4 Internal NSClient++ functions 21. Monitoring Room Temperature and Humidity 21.1 Sensors and Software 21.1.1 The PCMeasure software for Linux 21.1.2 The query protocol 21.2 The Nagios Plugin check_pcmeasure2.pl 22. Monitoring SAP Systems 22.1 Checking without a Login: sapinfo 22.1.1 Installation 22.1.2 First test 22.1.3 The plugin check_sap.sh 22.1.4 More up to date and written in Perl: check_sap.pl 22.2 Monitoring with SAP's Own Monitoring System CCMS 22.2.1 A short overview over the alert monitor 22.2.2 Obtaining the necessary SAP usage permissions for Nagios 22.2.3 Monitors and templates 22.2.4 The CCMS plugins 22.2.5 Performance optimization 23. Processing Events with the EventDB 23.1 How the EventDB Works 23.2 Installation 23.2.1 Installation requirements 23.2.2 Preparing the MySQL database 23.2.3 Sending events to the database with syslog-ng 23.3 Using the Web Interface 23.3.1 Preselection of the filter with URL parameters 23.4 The Nagios Plugin for the EventDB 23.5 Maintenance 23.6 Sending Windows Events to Syslog 23.7 Making the Incomprehensible Legible with SNMPTT 23.7.1 The configuration file snmptt.ini 23.7.2 Converting MIBs V. Part V Development 24. Writing Your Own Plugins 24.1 Programming Guidelines for Plugins 24.1.1 Return values 24.1.2 Information for the administrator on the standard output 24.1.3 Onboard online help? 24.1.4 Reserved options 24.1.5 Specifying thresholds 24.1.6 Timeout 24.1.7 Performance data 24.1.8 Copyright 24.2 The Perl Module Nagios::Plugin 24.2.1 Installation 25. Determining File and Directory Sizes 25.1 Splitting up the Command Line With Getopt::Long 25.2 The Perl Online Documentation 25.2.1 The module Pod::Usage 25.3 Determining Thresholds 25.4 Implementing Timeouts 25.5 Displaying Performance Data 25.6 Configuration Files for Plugins 26. Monitoring Oracle with the Instant Client 26.1 Installing the Oracle Instant Client 26.2 Establishing a Connection to the Oracle Database 26.3 A Wrapper Plugin for sqlplus 26.3.1 How the wrapper works 26.3.2 The Perl plugin in detail VI. Part VI Appendixes A. An Overview of the Nagios Configuration Parameters A.1 The Main Configuration File nagios.cfg A.2 CGI Configuration in cgi.cfg A.2.1 Authentication parameters A.2.2 Other Parameters B. Rapidly Alternating States: Flapping B.1 Flap Detection with Services B.1.1 Nagios configuration B.1.2 The history memory and the chronological progression of the changes in state B.1.3 Representation in the Web interface B.2 Flap Detection for Hosts C. Event Handlers C.1 Execution Times for the Event Handler C.2 Defining the Event Handler in the Service Definition C.3 The Handler Script C.4 Things to Note When Using Event Handlers D. Macros D.1 Standard Macros D.1.1 Host macros D.1.2 Service macros D.1.3 Group macros D.1.4 Contact macros D.1.5 Notification macros D.1.6 Macros to specify time and date D.1.7 Statistics macros D.1.8 Using standard macros about the environment D.2 On-Demand Macros D.3 Macros for User-defined Variables D.4 Macro Contents: Not Everything Is Allowed E. Single Sign-On for the Nagios Web Interface E.1 HTTP Authentication for Single Sign-On E.2 Kerberos Authentication with mod_auth_kerb E.2.1 Installation E.2.2 Creating a service ticket for Apache E.2.3 Kerberos configuration E.2.4 Apache configuration E.2.5 Definition of a Nagios contact E.3 Single Sign-On with mod_auth_ntlm_winbind E.3.1 Installation E.3.2 Preparing Samba E.3.3 Apache configuration E.3.4 Defining a Nagios contact E.4 Mozilla Firefox as a Web Client E.4.1 Firefox and NTLM E.5 Microsoft Internet Explorer as a Web Client F. Tips on Optimizing Performance F.1 Internal Statistics of Nagios F.1.1 The command-line tool nagiostats F.1.2 Showing Nagios performance graphically F.1.3 A plugin to monitor latency F.2 Measures for Improving Performance F.2.1 Service checks: as often as necessary, as few as possible F.2.2 Processing performance data intelligently F.2.3 Avoiding plugins in interpreted languages F.2.4 Optimizing host checks F.2.5 The matter of the Reaper F.2.6 Preferring passive checks F.2.7 Optimizing large Nagios environments F.2.8 Optimizing the NDOUtils database G. The Embedded Perl Interpreter G.1 Requirements of an ePN-capable Plugin G.2 Using ePN G.2.1 Compiling ePN G.2.2 Interpreter-specific parameters in nagios.cfg G.2.3 Disabling ePN on a per-plugin basis G.3 The Testing Tool new_mini_epn H. What's New in Nagios 3.0? H.1 Changes in Object Definitions H.1.1 The host object H.1.2 The service object H.1.3 Group objects H.1.4 The contact object H.1.5 Time definitions H.1.6 Dependency descriptions H.1.7 Escalation objects H.1.8 Inheritance H.2 Variable and Macros H.3 Downtime, Comments, and Acknowledgments H.4 Rapidly Changing States H.5 External Commands H.6 Embedded Perl H.7 A New Logic for Host Checks H.8 Restart H.9 Performance Optimization H.10 Extended Plugin Output H.11 CGI H.12 Miscellaneous H.13 Upgrade from Nagios 2.x to 3.0
Nagios: System and Network Monitoring, 2nd Edition
Wolfgang Barth
Copyright © 2008
1 2 3 4 5 6 7 8 9 10—09 08 07 06
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is
basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor Open Source Press GmbH nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
No Starch Press
Foreword to the second edition
As soon as the stable Nagios version 3.0 appeared, as can be expected after going to press, the question was raised: Nagios 2 or Nagios 3? For those just starting out with Nagios, Nagios 3.0 is a safe bet. Even the release candidate 3.0rc1 was sufficiently stable for production environments, and you can benefit directly from the new features, rather than having to get used to them later on.
If you are already using Nagios 2 in a sizable environment, then you'll surely be thinking, Never touch a running system. Why change if your existing system is running smoothly? But there has been further development on Nagios 2 since the first edition of this book appeared, and various bugs have been fixed.[¹] So it is perhaps advisable to change to the current Nagios 2 version, and then wait and see how things develop.
On the other hand, Nagios 3.0 does contain a number of improvements. In particular where there are performance problems in large environments, this major version provides some adjusting screws that can help the system to achieve a higher performance through its greatly improved hostcheck logic, thanks to the caching of check results and a series of optimization parameters. Otherwise, it is smaller changes, ones that are not so obvious, that distinguish Nagios 3.0 from Nagios 2. Many things, often hardly noti-cable, combine to make your work with Nagios 3.0 easier, and sometimes more pleasant as well. You can get to know and appreciate all these small details best if, as a Nagios 2 administrator, you just try out Nagios 3. Newcomers will probably take all these small improvements for granted, and not even notice them.
Fortunately, converting from Nagios 2 to Nagios 3.0, as described in H.13 Upgrade from Nagios 2.x to 3.0 from page 693, is relatively simple, and you can continue using your existing configuration unchanged in most cases.
What's New in the Second Edition?
The second edition deals with Nagios in both version 2.x and version 3.0, since there is no difference in the basic principles. At first glance the structure of the book looks the same, as do the contents of many chapters. Nevertheless, much has changed, even in the chapters that existed in the first edition. Nearly all the chapters were revised and updated to do justice to the current state of development of the tools introduced, but also to take into account the differences between Nagios 2.x and Nagios 3.0.
The Monitoring Servers chapter was completely revised and expanded, in particular where the NSClient++ tool is concerned. The chapter on the processing of performance data was also extended. A new tool was added, in the shape of PNP, and the description of the NagiosGrapher was brought right up to date. Of the newly introduced plugins, check_logfiles by Gerhard Laußer and check_multi by Matthias Flacke in particular deserve special mention, and the author considers these to have great potential. But caution is advised: both are for the advanced user.
There is a new chapter on NagVis, with which you can define a Web interface based on your own images or graphics, with complete freedom in its design. NagVis requires the database interface NDOUtils, to which a separate chapter is devoted.
The EventDB reveals a database-supported approach to processing events as an alternative to the classic log file check. A separate chapter is also devoted to this. The chapters Writing Your Own Plugins and Determining File and Directory Sizes are also new, and describe step by step how to write your own Perl plugin, introducing the Perl module Nagios::Plugin in so doing. To optimize the performance of Perl scripts, Nagios provides its own interpreter, which is also given its own chapter.
A chapter called What's New in Nagios 3.0? can't be missing, of course, which compactly summarizes all the changes made compared to Nagios 2.x. For the sake of completeness, there is a new chapter on macros in the Appendix. This compares the various macro types and explains their intended use.
A chapter on performance optimization was also included. It certainly doesn't contain any patent remedies, since this is just not possible, given the wide range of monitored environments and scenarios for use. But it does take a look at the problem zones of Nagios, and provides some tips on where to look for support.
The fact that authentification on the Nagios Web interface does not have to be restricted to the simple basis authentification described in the installation chapter is demonstrated by another new chapter about Single-Sign-On in Microsoft Active Directory environments.
[¹] Nagios 2.10 was the current version at the time of going to press.
Information Sources on the Internet
Despite an increase of over 200 pages, the book cannot describe all the existing tools and possibilities for use. The Internet provides a wealth of information that is useful while, or after, studying this book. The most important sources are listed here.
The Nagios homepage at http://www.nagios.org/
The homepage of Nagios plugins at http://www.nagiosplugins.org/
The Nagios community at http://www.nagioscommunity.org/
http://www.nagiosexchange.org/ as an exchange platform for plug-ins
The original mailing lists at http://www.nagios.org/support/mailinglists.php
Introduction
It's ten o'clock on Monday morning. The boss of the branch office is in a rage. He's been waiting for hours for an important e-mail, and it still hasn't arrived. It can only be the fault of the mail server; it's probably misbehaving yet again. But a quick check of the computer shows that no mails have got stuck in the queue there, and there's no mention either in the log file that a mail from the sender in question has arrived. So where's the problem?
The central mail server of the company doesn't respond to a ping. That's probably the root of the problem. But the IT department at the company head office absolutely insists that it is not to blame. It also cannot ping the mail node of the branch office, but it maintains that the network at the head office is running smoothly, so the problem must lie with the network at the branch office. The search for the error continues...
The humiliating result: the VPN connection to head office was down, and although the ISDN backup connection was working, no route to the head office (and thus to the central mail server) was defined in the backup router. A globally operating IT service provider was responsible for the network connections (VPN and ISDN) between branch and head office, for whom something like this just doesn't happen.
The end result: many hours spent searching for the error, an irritated boss (the meeting for which the e-mail was urgently required has long since finished), and a sweating admin.
With a properly configured Nagios system, the adminstrator would already have noticed the problem at eight in the morning and been able to isolate its cause within a few minutes. Instead of losing valuable time, the IT service provider would have been informed directly. The time then required to eliminate the error (in this case, half an hour) would have been sufficient to deliver the e-mail in time.
A second example: somewhere in Germany, the hard drive on which the central Oracle database for a hospital stores its log files reaches full capacity Although this does not cause the lights to go out
in the operating room, the database stops working and there is considerable disruption to work procedures: patients cannot be admitted, examination results cannot be saved, and reports cannot be documented until the problem has been fixed.
If the critical hard drive had been monitored with Nagios, the IT department would have been warned at an early stage. The problem would not even have occurred.
With personnel resources becoming more and more scarce, no IT department can really afford to regularly check all systems manually. Networks that are growing more and more complex especially demand the need to be informed early on of disruptions that have occurred or of problems that are about to happen. Nagios, the Open Source tool for system and network monitoring, helps the administrator to detect problems before the phone rings off the hook.
The aim of the software is to inform administrators quickly about questionable (WARNING) or critical conditions (CRITICAL). What is regarded as questionable
or critical
is defined by the administrator in the configuration. A Web page summary then informs the administrator of normally working systems and services, which Nagios displays in green, of questionable conditions (yellow), and of critical situations (red). There is also the possibility of informing the administrators in charge—depending on specific services or systems—selectively by e-mail but also by paging services such as SMS.
By concentrating on stop light states (green, yellow, red), Nagios is distinct from network tools that display elapsed time graphically (for example in the load of a WAN interface or a CPU throughout an entire day) or that record and measure network traffic (how high was the proportion of HTTP on a particular interface?). Nagios is involved plainly and simply with the issue of whether everything is on a green light. The software does an excellent job in looking after this, not just in terms of the current status but also over long periods of time.
The tests
When checking critical hosts and services, Nagios distinguishes between host and service checks. A host check tests a computer, called a host in Nagios slang, for reachability—as a rule, a simple ping is used. A service check selectively tests individual network services such as HTTP, SMTP, DNS, etc., but also running processes, CPU load, or log files. Host checks are performed by Nagios irregularly and only where required, for example if none of the services to be monitored can be reached on the host being monitored. As long as one service can be addressed there, then this is basically valid for the entire computer, so this test can be dropped.
The simplest test for network services consists of looking to see whether the relevant target port is open, and whether a service is listening there. But this does not necessarily mean that, for example, the SSH daemon really is running on TCP port 22. Nagios therefore uses tests for many services that go several steps further. With SMTP, for example, the software also tests whether the mail server announces itself with a 220
output, the so-called SMTP greeting; and for a PostgreSQL database, it checks whether this will accept an SQL query.
Nagios becomes especially interesting through the fact that it takes into account dependencies in the network topology (if it is configured to do so). If the target system can only be reached through a particular router that has just gone down, then Nagios reports that the target system is unreachable
and does not bother to bombard it with further host and service checks. The software puts administrators in a position where they can more quickly detect the actual cause and rectify the situation.
The suppliers of information
The great strength of Nagios—even in comparison with other network monitoring tools—lies in its modular structure. The Nagios core does not contain one single test. Instead it uses external programs for service and host checks, which are known as plugins. The basic equipment already contains a number of standard plugins for the most important application cases. Special requests that go beyond these are answered—provided that you have basic programming knowledge—by plugins that you can write yourself. Before investing time in developing these, however, it is first worth taking a look on the Internet and browsing through the relevant mailing lists,[²] as there is lively activity in this area. Ready-to-use plugins are available, especially in The Nagios Exchange platform, http://www.nagiosexchange.org/.
A plugin is a simple program—often just a shell script (Bash, Perl, etc.)—that gives out one of the four possible conditions: OK, WARNING, CRITICAL, or (with operating errors, for example) UNKNOWN.
This means that in principle Nagios can test everything that can be measured or counted electronically: the temperature and humidity in the server room, the amount of rainfall, the presence of persons in a certain room at a time when nobody should enter it. There are no limits to this, provided that you can find a way of providing measurement data or events as information that can be evaluated by computer (for example, with a temperature and humidity sensor, an infrared sensor, etc.). Apart from the standard plugins, this book accordingly introduces further freely available plugins, such as the use of a plugin to query a temperature and humidity sensor in Chapter 21 from page 505.
[²] http://www.nagios.org/support/mailinglists.php
Keeping admins up-to-date
Nagios possesses a sophisticated notification system. On the sender side (that is, with the host or service check) you can configure when each group of persons—the so-called contact groups—are informed about which conditions or events (failure, recovery, warnings, etc.). On the receiver side you can also define on multiple levels what is to be done with a corresponding message—for example whether the system should forward it, depending on the time of day, or discard the message.
If a specific service is to be monitored seven days a week round the clock, this does not mean that the administrator in charge will never be able to take a break. For example, you can instruct Nagios to notify the person only from Monday to Friday between 8am and 5pm, every two hours at the most. If the administrator in charge is not able to solve the problem within a specified period of time, eight hours for example, then the head of department responsible should receive a message. This process is known as escalation management. The corresponding configuration is explained in Chapter 12 from page 282.
Nagios can also make use of freely configurable, external programs for notifications, so that you can integrate any system you like, from e-mail to SMS, to a voice server that the administrator calls up and receives a voice message concerning the error.
With its Web interface (Chapter 16 from page 327, Nagios provides the administrator with a wide range of information, clearly arranged according to the issues involved. Whether the admin needs a summary of the overall situation, a display of problematic services and hosts and the causes of network outages, or the status of entire groups of hosts or services, Nagios provides an individually structured information page for nearly every purpose.
Through the Web front end, an administrator can inform colleagues upon accepting a particular problem so that they can concentrate on other issues that have not yet been addressed. Information already obtained can be stored as comments on hosts and services.
By reviewing past events, the Web interface can reveal problems that occurred in a selected time interval, who was informed of the problems, and which hosts and/or services were affected. Nagios can be configured to recognize scheduled downtimes and to prevent false alarms from going off during these periods.
Taking in information from outside
For tests, notifications, and so on, Nagios makes use of external programs, but the reverse is also possible: through a separate interface (see 13.1 The Interface for External Commands from page 292), independent programs can send status information and commands to Nagios. The Web interface makes widespread use of this possibility, which allows the administrator to send interactive commands to Nagios. But a backup program unknown to Nagios can also transmit a success or failure to Nagios, as well as to a syslog daemon. The possibilities are limitless. Thanks to this interface, Nagios allows distributed monitoring. This involves several decentralized Nagios installations sending their test results to a central instance, which then helps to maintain an overview of the situation from a central location.
Other tools for network monitoring
Nagios is not the only tool for monitoring systems and networks. The most well-known competitor,
perhaps on an equal footing, is Big Brother (BB). Despite a number of differences, its Web interface serves the same purpose as that of Nagios: displaying to the administrator what is in the green area
and what is not.
The reason why the author uses Nagios instead of Big Brother lies in the license for Big Brother, on the BB homepage[³] called Better Than Free License: the product continues to be commercially developed and distributed. If you use BB and earn money with it, you must buy the software. The fact that the software, including the source code, may not be passed on or modified, except with the explicit permission of the vendor, means that it cannot be reconciled with the criteria for Open Source licenses. This means that Linux distributors have their hands tied.
For the graphical display of certain measured values over a period of time, such as the load on a network interface, CPU load, or the number of mails per minute, there are other tools that perform this task better than Nagios. The original tool is certainly the Multi Router Traffic Grapher MRTG,[⁴] which, despite growing competition, still enjoys great popularity. A relatively young, but very powerful alternative is called Cacti[⁵]: this has a larger range of applications, can be configured via Web interface, and avoids the restrictions in MRTG, which can only display two measured values at the same time and cannot display any negative values. Another interesting new alternative is Munin.[⁶]
Nagios itself can also display performance data graphically, using extensions (Chapter 19 from page 403). In many cases this is sufficient, but for very dedicated requirements, the use of Nagios in tandem with a graphic representation tool such as MRTG or Cacti is recommended.
[³] http://www.bb4.org/
[⁴] http://www.mrtg.org/
[⁵] http://www.cacti.net/
[⁶] http://munin.projects.linpro.no/
About This Book
This book is directed at network administrators who want to find out about the condition of their systems and networks using an Open Source tool. It describes the Nagios versions 2.x and 3.0. The plugins, on the other hand, lead their own lives, are to a great extent independent of Nagios, and are therefore not restricted to a particular version.
Even though this book is based upon using Linux as the operating system for the Nagios computer, this is not a requirement. Most descriptions also apply to other Unix systems,[⁷] only system-specific details such as start scripts need to be adjusted accordingly. Nagios currently does not officially work under Windows, however.[⁸]
The first part of this book deals with getting Nagios up and running with a simple configuration, albeit one that is sufficient for many uses, as quickly as possible. This is why Chapter 1 through Chapter 3 do not have detailed descriptions and treatments of all options and features. These are examined in the second part of the book.
Chapter 4 looks at the details of service and host checks, and in particular introduces their dependency on network topologies.
The options available to Nagios for implementing service checks and obtaining their results is described in Chapter 5.
This is followed by the presentation of individual standard plugins and a number of additional, freely obtainable plugins. Chapter 6 takes a look at the plugins that inspect the services of a network protocol directly from the Nagios host, while Chapter 7 summarizes plugins that need to be installed on the machine that is being monitored, and for which Nagios needs additional utilities to get them running. Several auxiliary plugins, which do not perform any tests themselves, but manipulate already established results, are introduced in Chapter 8.
Two utilities that Nagios requires to run local plugins on remote hosts are introduced in the two subsequent chapters. Chapter 9 describes SSH, while Chapter 10 introduces a daemon developed specifically for Nagios.
Wherever networks are being monitored, SNMP also needs to be implemented. Chapter 11 not only describes SNMP-capable plugins but also examines the protocol and the SNMP world itself in detail, providing the background knowledge needed for this.
The Nagios notification system is introduced Chapter 12, which also deals with notification using SMS, escalation management, and taking account of dependencies.
The interface for external commands is discussed in Chapter 13. This forms the basis of other Nagios mechanisms, such as the Nagios Service Check Acceptor (NSCA), a client-server mechanism for transmitting passive test results, covered in Chapter 14. The use of this is shown in two concrete examples—integrating syslog-ng and processing SNMP traps. NSCA is also a requirement for distributed monitoring, discussed in Chapter 15.
The third part of the book is devoted to how the extracted information can be represented graphically. Chapter 16 explains how this works and how it is set up in detail, supported by some useful screenshots. It also explains a series of parameters, for which there are otherwise no documentation at all, except in the source code.
Nagios can be expanded by adding external applications. The NDOUtils enable database-driven storage of all Nagios objects and are described in Chapter 17. Connection to a database, using the addon described in Chapter 18, enables you to build a Web interface that can be configured far beyond the basic range of Nagios.
Although in its operation, Nagios concentrates primarily on stoplight signals (red-yellow-green), there are ways of evaluating and representing the performance data provided by plugins, which are described in detail in Chapter 19.
The fourth part of this book is dedicated to special applications. Networks are rarely homogeneous—that is, equipped only with Linux and other Unix-based operating systems. For this reason, Chapter 20 demonstrates what utilities can be used to integrate and monitor Windows systems.
Chapter 21 uses the example of a low-cost hardware sensor to show how room temperature and humidity can be monitored simply, yet effectively.
Nagios can also monitor proprietary commercial software, as long as mechanisms are available which can query states of the system integrated into a plugin. In Chapter 22, this is described using an SAP-R/3 system.
Whereas event processing is only briefly outlined in Chapter 14, Chapter 23 presents a database-supported approach that provides more options for selecting and processing events, including interlinking with Nagios.
Building your own plugins is the subject of the fifth part of this book. Chapter 24 looks at the general requirements for a standard plugin, while Chapter 25 uses a step-by-step example of how to write your own plugins that are fit for publishing. Chapter 26 takes an example of the Instant Client of Oracle to demonstrate how to build your own plugins based on programs not really intended for this purpose.
Appendix A introduces all the parameters of the two central configuration files nagios.cfg and cgi.cfg, while Appendix B and Appendix C are devoted to some useful but somewhat exotic features.
A separate appendix (Appendix D) is devoted to macros, which allow flexibility in configuration.
Appendix E wanders slightly away from the core topic of Nagios and demonstrates how single sign-on scenarios can also be used for authentication in the Nagios Web interface.
The larger the environment, the more important it is to have a powerful and quick-reacting Nagios system. Appendix F offers a series suggestions on this, while Appendix G is dedicated to a specific tool, the Perl interpreter integrated into Nagios.
Finally, Appendix H briefly summarizes all the changes made since Nagios 2.x
[⁷] For example, *BSD, HP-UX, AIX, and Solaris; the author does not know of any Nagios versions running under MacOS X.
[⁸] There are, however, rumors about Nagios running in Cygwin environments.
Further notes on the book
At the time of going to press, Nagios 3.0 is close to completion. By the time this book reaches the market, there could well be some modifications. Relevant notes, as well as corrections, in case some errors have slipped into the book, can be found at http://linux.swobspace.net/books/nagios/.
Note of Thanks
Many people have contributed to the success of this book. My thanks go first of all to Dr. Markus Wirtz, who initiated this book with his comment, Why don't you write a Nagios book, then?!
, when he refused to accept my Nagios activities as an excuse for delays in writing another book. A very special thanks goes to Patricia Jung, who, as the technical editor for the German language version, overhauled the manuscript and pestered me with thousands of questions—which was a good thing for the completeness of the book, and which has ultimately made it easier for the reader to understand.
The book would not be possible, of course, without all the tools it describes. Very special thanks go to Ethan Galstad, who as author, developer and maintainer has made Nagios what it is today: an awesome, incredibly useful and helpful tool that also fulfills high-level requirements, and one that can rely on a very large—and above all very active— community. Also many thanks to Ton Voon, representing all members of the Nagios Plugins Development Team, who, together with his colleagues, manages the development of Nagios plugins.
My thanks also go to those who have not only developed the Nagios-related software introduced in this book, but have also helped to polish and improve the book with their proofreading and feedback: Matthias Flacke (of check_multi fame), Jörg Linge (PNP), and Steffen Waitz, who proofread the first edition, Hendrik Bäcker (npcd), Lars Michelsen, Michael Luebben (NagVis), Gerhard Laußer (check_logfiles), and the employees of NETWAYS GmbH (NagiosGrapher, EventDB, the exchange platform, NagiosExchange).
It is not possible for me to name all the individuals who have contributed in one way or another to the success of Nagios. I would therefore like to thank everybody who actively supports the Nagios community, whether this is through free software or through involvement in forums and mailing lists. Where would Nagios be without its users?
Part I. From Source Code to a Running Installation
Chapter 1. Installation
The simplest method of installation is for you to install the Nagios packages that are supplied with the distribution you are using. Nagios 2.x is by now extremely mature and is therefore a component of most distributions. The paths of individual directories in those packages maintained by Linux distributors are usually different from the default specified in the source package, and thus from the paths used in this book.
Nagios 3.0 is relatively new; it is recommended here that you get your hands dirty
by compiling and installing the software yourself. The following installation guide also applies to Nagios 2.x, and any differences between versions 2.x and 3.0 are mentioned explicitly in the text.
If you compile your own software, you have control over the directory structures and a number of other parameters. A Nagios system compiled in this way also provides an almost complete main configuration file, in which, initially, nothing has to be changed. But it should be mentioned here that compiling Nagios yourself might involve a laborious search for the necessary development packages, depending on what is already installed on the computer.
1.1 Preparations
For compiling Nagios itself you require gcc, make, autoconf, and automake. Required libraries are libgd[⁹] and openssl[¹⁰]. The development packages for these must also be installed (depending on the distribution, with either the ending -dev or -devel): libssl-dev, libgd-dev, libc6-dev.
With Debian and Ubuntu you prepare by using apt-get install to install the packages apache2, build-essential, and libgd2-dev. In Open-SUSE you install apache2 via YAST2, along with all C/C++ development libraries, as well as the package gd. In Fedora you run the command yum install on the command line and enter the packages httpd, gcc, glibc, glibc-common, gd, and gd-devel as arguments.
For the plugins it is recommended that you also install the following packages: ntpdate[¹¹] (possibly contained in the package ntp or xntp), snmp,[¹²] smbclient[¹³] (possibly a component of the package samba-client), the libldap2 library, and the relevant development package libldap2-dev[¹⁴] (depending on the distribution, the appropriate packages are also called openldap2-client and openldap2-devel). You will also need to install the client and developer packages for the database used (e.g., postgresql-client and postgresql-dev(el)).
1.1.1 Determining and setting up the required users
Prior to compiling and installing, use the command groupadd to set up the groups necessary for operation. Groups nagios and nagcmd are set up with groupadd, and the user nagios, who is assigned to these groups and with whose permissions the Nagios server runs is set up with useradd:
linux:~ #
groupadd -g 9000 nagios
linux:~ #
groupadd -g 9001 nagcmd
linux:~ #
useradd -u 9000 -g nagios -G nagcmd -d /usr/local/nagios \ -c Nagios Admin
nagios
Instead of the user (9000) and group IDs (9000 or 9001) used here, any other available IDs may be used. The primary group nagios of the user nagios should remain reserved exclusively for this user.
The CGI scripts are run by Nagios under the user ID of the user with whose permissions the Apache Web server runs. In order for this user to access certain protected areas of Nagios, an additional group is required, the so-called Nagios Command Group nagcmd. Only the Web user and the user nagios should belong to this group. The Web user can be determined from the Apache configuration file. In Debian/Ubuntu this is located at /etc/apache2/apache2.conf; in Fedora it is at /etc/httpd/httpd.conf:
linux:~ #
grep ^User
/etc/apache2/apache2.conf
User www-data
The user determined in this way (in Debian/Ubuntu www-data, in Open-SUSE www-run, and in Fedora httpd) is additionally assigned to the group nagcmd, shown here using the example for Debian/Ubuntu:
linux:~ #
usermod -G nagcmd www-data
In the example, the Web user is called www-data. The command usermod (this changes the data for an existing user account) also includes the Web user in the nagcmd group thanks to the -G option, by manipulating the corresponding entry in the file /etc/group.
In addition, the directory specified as the home directory of the user nagios, /usr/local/nagios, the configuration directory /etc/nagios, and the directory /var/nagios, which records variable data while Nagios is running, are set up manually and are assigned to the user nagios and to the group of the same name:
linux:~ #
mkdir /usr/local/nagios /etc/nagios /var/nagios
linux:~ #
chown nagios.nagios /usr/local/nagios /etc/nagios /var/nagios
[⁹] http://www.boutell.com/gd/
[¹⁰] http://www.openssl.org/ Depending on the distribution, the required RPM and Debian packages are sometimes named differently. Here you need to refer to the search help in the corresponding distribution. For Debian, the homepage will be of help. For example, if a configure instruction complains of a missing gd.h file, you can search specifically at http://www.debian.org/distrib/packages for the contents of packages. The search will then come up with all packages that contain the file gd.h.
[¹¹] http://ntp.isc.org/bin/view/Main/SoftwareDownloads
[¹²] http://net-snmp.sourceforge.net/
[¹³] http://samba.org/samba/
[¹⁴] http://www.openldap.org/
1.2 Compiling Source Code
The Nagios source code is available for download on the project page.[¹⁵] The installation description below is for version 3.0, which is provided by the developers as a tarball. A Nagios 2.x installation runs in an almost identical manner:
linux:~ #
mkdir /usr/local/src
linux:~ #
cd /usr/local/src
linux:local/src #
tar xvzf path/to/nagios-3.0.tar.gz
...
The three commands unpack the source code into the directory created for this purpose, /usr/local/src. A subdirectory called nagios-3.0 is also created, containing the Nagios sources. To prepare these for compilation, enter the parameter deviating from the default value when running the configure command. Table 1-1 lists the most important parameters:
linux:~ #
cd /usr/local/src/nagios-3.0
linux:src/nagios-3.0 #
./configure \ --sysconfdir=/etc/nagios \ --localstatedir=/var/nagios \ --with-command-group=nagcmd
...
The values chosen here ensure that the installation routine selects the directories used in the book and sets all parameters correctly when generating the main configuration file. This simplifies fine tuning of the configuration considerably. If you want to use the Embedded Perl Interpreter to accelerate the execution of Perl scripts, then you also need the two switches --with-perlcache and --enable-embedded-perl.
In Nagios 3.0 you can leave out --with-perlcache, as it is enabled automatically by --enable-embedded-perl. You can find more on the Embedded Perl Interpreter in Appendix G, page 669.
Table 1-1. Installation parameters for Nagios
If --prefix is not specified, Nagios installs itself in the /usr/local/nagios directory. We recommend that you stick to this directory.[¹⁶]
The system normally stores its configuration files in the directory etc beneath its root directory. In general it is better to store these in the /etc hierarchy however. Here we use /etc/nagios.[¹⁷]
Variable data such as the log file and the status file are by default stored in the directory /usr/local/nagios/var. This is in the /usr hierarchy which should only contain programs and other read-only files, not writable ones. In order to ensure that this is the case, we use /var/nagios.[¹⁸]
Irrespective of these changes, in most cases configure does not run through faultlessly the very first time, since one package or another is missing. For required libraries such as libgd, Nagios almost always demands the relevant developer package with the header files (here, libgd-dev or libgd-devel). Depending on the distribution, their names will end in -devel or -dev.
After all the tests have been run through, configure presents a summary of all the important configuration parameters:
*** Configuration summary for nagios 3.0 ***
:
General Options:
---------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagcmd Embedded Perl: yes, with caching Event Broker: yes Install $prefix: /usr/local/nagios Lock file: /var/nagios/nagios.lock Check result directory: /var/nagios/spool/checkresults Init directory: /etc/init.d
Apache conf.d directory: /etc/apache2/conf.d Mail program: /usr/bin/mail Host OS: linux-gnu
Web Interface Options:
------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/sbin/traceroute
In Nagios 2.x the lines Check result directory, Apache conf.d directory, and Mail program are missing.
If a yes is written after the item Embedded Perl, the Embedded Perl Interpreter is enabled. The Event Broker provides an interface for extensions that can be loaded as additional modules while the system is running.[¹⁹]
If you are satisfied with the result, make starts the actual compilation and then installs the software:[²⁰]
linux:src/nagios-3.0 #
make all
...
linux:src/nagios-3.0 #
make install
...
linux:src/nagios-3.0 #
make install-init
...
linux:src/nagios-3.0 #
make install-commandmode
...
linux:src/nagios-3.0 #
make install-config
...
The command make all compiles all the relevant programs, which are then copied to the appropriate directories, together with CGI scripts and documentation, by make install. Apart from /etc/nagios and /var/nagios, further directories are created under /usr/local/nagios, which are summarized in Table 1-2.
Table 1-2. Nagios directories under /usr/local/nagios
The command make install-commandmode generates the directory that is required for later usage of the command file mechanism (see 13.1 The Interface for External Commands, page 292) onwards. This step is optional, depending on the intended use, but since it is easy to forget later on, it is better to take precautions now. The final make install-config creates the example configuration, which will be used in Chapter 2, page 53.
[¹⁵] http://www.nagios.org/
[¹⁶] In accordance with the Filesystem Hierarchy Standard FHS, version 2.3, or local programs loaded by the administrator should be installed in /usr/local
[¹⁷] This is not entirely compatible with FHS 2.3, which would prefer to have the configuration files in /etc/local/nagios.
[¹⁸] This also does not quite match the requirements of the FHS 2.3. But since Nagios makes no differentiation between spool, cache, and status information, an FHS-true reproduction is not possible to achieve in a simple manner.
[¹⁹] At the time of going to press there were not yet any external extensions, which is why the Event Broker is currently only of interest to developers.
[²⁰] Caution is needed when updating from Nagios 2.x to Nagios 3.0: Here you should first back up the existing configuration, initially run only make all, and carefully read H.13 Upgrade from Nagios 2.x to 3.0 in page 693. In Nagios 3.0 a make install-config command overwrites existing files!
1.3 Starting Nagios Automatically
The command make install-init installs a suitable init script for the system start. Here make automatically tries to detect the correct path, which for most Linux distributions is /etc/init.d. Depending on your system, this may not be correct, which is why you should check it. In order for Nagios to start automatically when the system is booted, symbolic links are created in the /etc/rc?.d directories. With Debian and Ubuntu using System-V-Init, the included system script update-rc.d performs this task:
linux:~ #
update-rc.d nagios defaults 99
This command creates symlinks beginning with the prefix S99 to the directories rc2.d to rc5.d, so that Nagios starts automatically when changing to runlevels 2 to 5. In addition it ensures that K99 symlinks in the directories rc0.d, rc1.d, and rc6.d are responsible for stopping Nagios when the system is shut down and rebooted, as well as when it changes to maintenance mode. This corresponds to the following command-line commands:
linux:~ #
ln -s /etc/init.d/nagios /etc/rc2.d/S99nagios
linux:~ #
ln -s /etc/init.d/nagios /etc/rc3.d/S99nagios
linux:~ #
ln -s /etc/init.d/nagios /etc/rc4.d/S99nagios
linux:~ #
ln -s /etc/init.d/nagios /etc/rc5.d/S99nagios
linux:~ #
ln -s /etc/init.d/nagios /etc/rc0.d/K99nagios
linux:~ #
ln -s /etc/init.d/nagios /etc/rc1.d/K99nagios
linux:~ #
ln -s /etc/init.d/nagios /etc/rc6.d/K99nagios
For OpenSUSE the required symlinks are created using the script insserv:
linux:~ #
insserv nagios
Fedora users perform this task with chkconfig:
linux:~ #
chkconfig --add nagios
linux:~ #
nagios on
1.4 Installing and Testing Plugins
What is now still missing are the plugins. They must be downloaded separately from http://www.nagios.org/ and installed. As independent programs, they are subject to a different versioning system than Nagios. The current version at the time of going to press was version 1.4.11, but you can, for example, also use plugins from earlier version if you don't mind doing without the most recent features. Although the plugins are distributed in a common source distribution, they are independent of one another, so that you can replace one version of an individual plugin with another one at any time, or with one you have written yourself.
1.4.1 Installation
The installation of the plugin sources takes place, like the Nagios ones, in the directory /usr/local:
linux:~ #
cd /usr/local/src
linux:local/src #
tar xvzf path /to/nagios-plugins-1.4.tar.gz
linux:src/nagios-plugins-1.4.11 #
./configure \ --sysconfdir=/etc/nagios \ --localstatedir=/var/nagios \ --enable-perl-modules
...
When running the configure command you should specify the same non-default values as for the server, which here are the configuration directory (/etc/nagios) and the directory intended for the data saved by Nagios (/var/nagios). Since the Nagios plugins are not maintained by the same people as Nagios itself, you should always check in advance, with ./configure --help, whether the configure options for Nagios and the plugins really match or deviate from one another.
The switch --enable-perl-modules is only needed if you intend to install the Perl module Nagios::Plugin—for example, if you are using it to program your own plugins in Perl. You can read more on this in 24.2 The Perl Module Nagios::Plugin, page 560.
It is possible that a series of WARNINGs may appear in the output of the configure command, something like this:
...
configure: WARNING: Skipping radius plugin
configure: WARNING: install radius libs to compile this plugin (see REQUIREMENTS).
...
configure: WARNING: Tried /usr/bin/perl - install Net ::SNMP perl module if you want to use the perl snmp plugins
...
If you are not using Radius, you need not have qualms about ignoring the corresponding error messages. Otherwise you should install the missing packages and repeat the configure procedure. The quite frequently required SNMP functionality is missing a Perl module in this example. This may be installed either in the form of the distribution package or via the online CPAN archive:[²¹]
linux:~ #
perl -MCPAN -e 'install Net::SNMP'
...
If you are running the CPAN procedure for the first time, it will guide you interactively through a self-explanatory setup, and you can answer nearly all of the questions with the default option.
Running make in the directory nagios-plugins-1.4.11 will compile all plugins. Afterwards you have the opportunity to perform tests, with make check. Because these tests have not been particularly carefully programmed, you will often see many error messages that have more to do with the test itself than with the plugin. If you still want to try it, then the Cache Perl module must also be installed. Regardless of whether you use make check, you should manually check the most important plugins after the installation.
The command make install finally anchors the plugins in the subdirectory libexec (which in our case is /usr/local/nagios/libexec). However, not all of them are installed through this command. The source directory contrib contains a number of plugins that make install does not install automatically.
Most plugins in this directory are shell or Perl scripts. Where needed, these are simply copied to the plugin directory /usr/local/nagios/libexec. The few C programs first must be compiled, which in some cases may be no laughing matter, since a corresponding makefile, and often even a description of the required libraries, can be missing. If a simple make is not sufficient, as in the case of
linux:nagios-plugins-1.4.11/contrib #
make check_cluster2[²²]
cc check_cluster2.c -o check_cluster2
then it is best to look for help in the mailing list nagiosplug-help.[²³] The compiled program must also be copied to the plugin directory.
1.4.2 Plugin test
Because plugins are independent programs, they can already be used manually for test purposes right now—before the installation of Nagios has been completed. In any case you should check the check_icmp plugin, which plays an essential role. It checks whether another computer can be reached via ping, and it is the only plugin to be used both as a service check and a host check. If it is not working correctly, Nagios will not work correctly either, since the system cannot