Tip

Remote server monitoring with Nagios

After the network monitoring tool Nagios is fully configured, learn the next step in setting it up for remote server monitoring.

This is the second installation in a series of tips on using the open source network monitoring tool Nagios. Part one of the series covered Nagios installation and configuration, while part three details using Nagios plugins. In this second part of our series, you’ll learn how to use Nagios for remote server monitoring.

After setting up a Nagios host, you'll learn what to do next. Assuming the Nagios host is now fully functional, it's time to set it up to monitor remote hosts.

More on this topic

  • Nagios: Configuration and integration advice
  • Use Nagios to trend and troubleshoot performance issues
  • Nagios: Preventing data center downtime
  • Installing Nagios on Solaris for network and server monitoring
  • Is Nagios right for your data center?

Speaking generically, there are two ways to set up Nagios remote host monitoring. The easiest is to set up straight remote server monitoring. This allows you to check the availability of services, but you can't request parameters that are local to the host. Alternatively, you can install the Nagios Remote Program Execution (NRPE) agent on the remote host. Because NRPE uses a locally installed daemon, it allows you to monitor local parameters such as available disk space. Setting up NRPE, however, is more difficult than setting up remote server monitoring. Today I’ll discuss the simpler option, but I’ll delve into NRPE in a follow-up tip.

To configure Nagios for remote server monitoring, you have to start from the /etc/nagios/nagios.cfg configuration file. In this file, the Nagios configuration is build. This happens by referring to the objects files. In these, the different aspects of Nagios functionality are defined.

In nagios.cfg, Nagios learns how to handle its objects:

cfg_file=/etc/nagios/objects/commands.cfg

cfg_file=/etc/nagios/objects/contacts.cfg

cfg_file=/etc/nagios/objects/timeperiods.cfg

cfg_file=/etc/nagios/objects/templates.cfg 

 

# Definitions for monitoring the local (Linux) host

cfg_file=/etc/nagios/objects/localhost.cfg

 

# Definitions for monitoring a Windows machine

#cfg_file=/etc/nagios/objects/windows.cfg

 

# Definitions for monitoring a router/switch

#cfg_file=/etc/nagios/objects/switch.cfg 

 

# Definitions for monitoring a network printer

#cfg_file=/etc/nagios/objects/printer.cfg

By default, monitoring of the local host is activated from the nagios.cfg file. If you want to set it up to also monitor a remote host, you need to add a specific line. Such a line could look like this: 

cfg_file=/etc/nagios/objects/server1.cfg

As you can see, this line refers to the /etc/nagios/objects/server1.cfg file. Make sure that it exists and requires the instructions needed for appropriate monitoring. To start with, you need a host definition. To monitor a server with the name server1, it should be modified as follows:

define host{

        use                     linux-server            ; Name of host template to use

                                                        ; This host definition will inherit all variables that are defined

                                                        ; in (or inherited by) the linux-server host template definition.

        host_name         server1

        alias                   fedora-server

        address              192.168.1.85

        }

In this example file, you can see that the first line specifies that a template with the name linux-server is to be used. This template contains settings that you typically want to apply to all hosts that are monitored, such as timeout settings or a specification of the number of packets that you want to send over.

In the next part of the configuration file, you need to specify what you want to monitor. Typically, these are services, such as an SSH server of a Web server. To do this, you can include the service in the server1.cfg file, as in the following example, which pings the host on a regular basis:

define service{

        use                             local-service         ; Name of service template to use

        host_name                 server1

        service_description   PING

        check_command       check_ping!100.0,20%!500.0,60%

        }

In this example, you can see that a template is used as well. It has the name local-service and contains default settings that are typically used for service monitoring. The other important part here is the check_command; check_ping. This command is available as an external plug-in, a custom made program that is written for Nagios operation.

Likewise, you can check other services as well, such as SSH:

define service{

        use                                local-service         ; Name of service template to use

        host_name                    localhost

        service_description      SSH
        check_command          check_ssh
        notifications_enabled   0
        }

You see that this example refers to specific Nagios commands. On a default Nagios installation, you'll find these commands in /usr/lib/nagios/plugins. Some commands are available by default; if the command you need is not, you can create your own. In a follow-up article, you'll learn how to do that.
 


In /usr/lib/nagios/plugins, you can find some commands that are installed by default
(click for a larger image)
 

After setting up a host-specific configuration for all the remote hosts you want to monitor, you have to re-start Nagios on the Nagios host to activate the changes. While starting Nagios, you may occasionally encounter errors. If this is the case, you can have a look at the Nagios error log, which is in /var/log/nagios/config.err by default. This configuration file tells you exactly in which line something is wrong, allowing you to easily fix the problem.

Conclusion

In this article you've learned how to set up remote server monitoring using remote host definitions that contain a specification for each individual service that needs monitoring. The advantage of this approach is that it is easy to set up; however, you can't use it to monitor local parameters on the host. In a future follow-up article, you'll read how to do that using NRPE and SSH.

Dig Deeper on Systems automation and orchestration

Software Quality
App Architecture
Cloud Computing
SearchAWS
TheServerSide.com
Data Center
Close