Management NEMS Linux Lead image: Lead Image © Chris Gendreau; Fotolia
Lead Image © Chris Gendreau; Fotolia
 

Nagios on a Rasp Pi 3 with NEMS

Small but Mighty

We show you how to install and use the NEMS distribution of Nagios network monitoring on a Raspberry Pi. By Rick Haltermon

Enterprise asset monitoring can be a daunting and expensive task. If you are interested in asset monitoring but have avoided it in the past because of price or complexity, you can now get a fully configured open source Nagios distribution made for easy deployment on affordable hardware. Nagios Enterprise Monitoring Server (NEMS) [1] is a pre-configured, customized, and ready-to-deploy Nagios Core [2] image designed to run on the Raspberry Pi 3 microcomputer and the Odroid XU4/4Q – so far. NEMS was developed by Robbie Ferguson [3] to be a nearly turnkey package; that is, the majority of the work required to integrate the various open source software components has been done for you.

NEMS begins with a lightweight Debian Stretch deployment optimized for performance, reliability, and ease of use. It monitors network-attached servers, switches, applications, and services, generating alerts when things go wrong and again when the problem has been resolved.

The Hardware

I run NEMS on a Raspberry Pi 3, which needs a minimum 8GB microSD card (a 16GB+ card is recommended). My server has been running for more than a year with a 32GB microSD without coming close to filling the disk.

Access is through a browser and SSH, in which case no other hardware is necessary (i.e., a keyboard, monitor, or mouse). The Pi is powered by a 5V micro-USB. To avoid power issues, use a power supply that provides 2.5A to the Pi.

The Software

In this article, I cover the download and installation of the latest version of NEMS with a subsequent installation of the most current rolling updates. At the time of writing, the latest version was 1.2.1, with rolling updates upgrading the system to version 1.2.2. The latest version of NEMS is available from the developer's website [1].

After downloading the ZIP file of about 1.27GB, extract the image file from the archive. The software you use to copy the image file to the microSD is dependent on the operating system you are using to create the microSD. The NEMS web page has links to instructions for Windows, Linux, and Mac systems.

Installation

Before inserting the imaged microSD card into your Pi, make sure it is not plugged in or is turned off. Plugging in the Pi power supply will boot NEMS. The server will then obtain an IP address via DHCP and connect to your network. For ease of access via SSH and browsers, reserve an IP address on your DHCP server.

Using an SSH program (e.g., PuTTY), you connect to the server on port 22 with the reserved IP address. The default username is pi, and the default password is raspberry (Figure 1). Now enter

sudo nems-init
The NEMS initial terminal page. Note that the NEMS Version shown is older than the Current Version available (first line).
Figure 1: The NEMS initial terminal page. Note that the NEMS Version shown is older than the Current Version available (first line).

to initialize NEMS. The nems-init process:

As of version 1.2.1, you do not have to download and re-image when a newer point release becomes available, although major releases will require re-imaging.

The NEMS logon splash screen displays the version running, along with the most current version available. To update to the most current version, enter:

sudo nems-upgrade

The upgrade process includes downloading and installing project and operating system updates. Depending on the number of updates required, it can take anywhere from five to 20 minutes. After the upgrade is complete, reboot the server.

Once the reboot is complete, connect again via SSH and use the Nano editor to modify the resource.cfg file:

sudo nano /etc/nagios3/resource.cfg

Now add your SMTP information to the sendemail section (Listing 1). The settings in this section are used by the server to send email notifications. For a more detailed look at how to set your SMTP information for your specific needs, please see the documentation on the NEMS website.

Listing 1: resource.cfg (Excerpt)

### sendemail SMTP Config added in NEMS 1.1
# The "from address" for notifications
$USER5$=example@gmail.com
# The SMTP server
$USER7$=smtp.gmail.com
# the SMTP authentication username and password
$USER9$=example@gmail.com
$USER10$=examplepassword

Once more, reboot after changing and saving the settings. NEMS setup is now complete, and you'll see the updated version information on the splash screen.

Generating a Configuration File

The first step in generating a configuration file is to define the devices and services you want to monitor. After connecting to the server from a web browser, the default page shows information about the server's status and has a menu with links to all of the NEMS components (Figure 2).

NEMS default page.
Figure 2: NEMS default page.

NConf

Creating and maintaining Nagios configurations is traditionally very time consuming, and the process is prone to errors. NEMS addresses these issues with an updated version of NConf [4] called NEMS Configurator. This application is found on the Configuration menu and is used to automate the generation of Nagios3 configurations. To access, log on using the user ID and password that you entered during the nems-init process.

A few hosts and services are defined to get you started. You can use these as examples when you are building the configuration for your environment. Once you have defined the hosts and service to be checked, click on the Generate Nagios config link, and NConf will attempt to build a configuration file for Nagios3 (Figure 3).

NConf with highlighted Deploy link after generating a Nagios config with no errors or warnings.
Figure 3: NConf with highlighted Deploy link after generating a Nagios config with no errors or warnings.

If all goes well, you will receive no errors or warnings. If you see any errors, the Deploy link will not be available. You should investigate any warnings and decide whether you want to continue with deployment of the updated configuration; click the Deploy button, and NConf sends a request to Nagios3 to load the new configuration file.

NConf is no longer being developed by the original authors. Version 1.4 was developed and is supported by Robbie Ferguson for NEMS. Despite this, you can find helpful information on the original authors' website.

Reporting

To review the status of checks done by Nagios3, you can use the JSON output of the included Nagios API or use one of the three reporting applications available by selecting Reporting: Nagios Core [5], NagVis [6], and Check_MK [7]. Each provides a different view of the Nagios3 monitoring data.

Nagios Core is an event scheduler, event processor, and alert manager for monitored devices and services (Figure 4). Detailed information about Nagios Core is available on the project's website.

Nagios Core tactical overview page.
Figure 4: Nagios Core tactical overview page.

NagVis visualizes Nagios3 data and displays IT processes (e.g., an email system or a network infrastructure) as mapped objects (Figure 5). Using back-end data, NagVis updates these objects periodically to reflect their status. These maps also allow you to arrange objects and display them in different layouts.

NagVis Hosts view.
Figure 5: NagVis Hosts view.

The nems-init process does not set the logon ID and password for this application. The first time you log on to NagVis, you use admin as the default for both the username and password. After logging on, you should use the change password option under User menu to change it.

I find I do most of my real-time monitoring with the Check_MK tool. This application has a very good overview of the status of hosts and services (Figure 6). It is updated often, and the graphics provide a great view of current issues, as well as those from the past four hours that have been resolved.

Example of the Check_MK Overview.
Figure 6: Example of the Check_MK Overview.

Monitoring Your Pi

Under the NEMS System menu, three applications are available to monitor the status of your Raspberry Pi: Monitorix [8], RPi-Monitor [9], and Webmin [10].

Monitorix is a system monitoring tool designed to monitor as many services and system resources as possible on a Linux/Unix machine (Figure 7). This application does not require any configuration because it has been preconfigured by the NEMS developer to provide system resource graphs for time periods of up to a year, which should help you spot issues such as low disk space, high RAM usage, or temperature problems.

Example of a Monitorix performance graph.
Figure 7: Example of a Monitorix performance graph.

The RPi-Monitor application is a self-monitoring tool designed to provide system information for the Raspberry Pi. It includes information such as operating system version, memory usage, uptime, and CPU performance (Figure 8). A FAQ is available on the RPi-Monitor website.

RPi-Monitor Status page.
Figure 8: RPi-Monitor Status page.

The final tool mentioned is Webmin, which does much more than monitor your system. First, its Dashboard tab provides a wealth of status information (Figure 9). It also acts as a web-based interface for administration of the operating system. Using a browser, you can set up user accounts, DNS, file sharing, and much more. Webmin eliminates the need to edit many Unix configuration files manually (e.g., /etc/passwd), and it lets you manage a system remotely.

Webmin homepage.
Figure 9: Webmin homepage.

Backup and Restore

The NEMS developer has created a simple backup and restore process that will, in the event of a hardware failure or after an upgrade, prevent you from having to rebuild your Nagios3 configuration from scratch. The backup and restore links are located under the Migrator tab.

Select the backup link to start the NEMS configuration backup process. When prompted, enter your NEMS user ID to start the download. Just save the download file in a convenient location. I have automated this process by creating a daily scheduled job that runs the wget tool to grab and save the backup file:

wget --user=<UserID> --password=<Passw0rd> -O "backup.nems" http://<NEMSIPAddress>/backup/

Clicking the restore link opens a page in your browser that contains detailed restore instructions. Generally, you will copy the backup.nems file to a flash drive, insert the flash drive in a Raspberry Pi running NEMS, issue the nems-restore command, and follow the prompts.

Considering the low cost of a Raspberry Pi and microSD card, I recommend keeping a spare Pi with a microSD card that contains an image of the running microSD card as a backup. To build the image, shut down the Pi and create an image file from the microSD card using the same tools you used to write the NEMS image to the microSD card originally; then, copy that image file to a standby microSD card.

In the event of failure of your production system, just fire up the backup, copy your most current NEMS backup file to the backup system, and do a configuration restore. Your NEMS monitoring is now back online.

Conclusion

After running NEMS for more than a year in a production environment, I have found the system to be very economical both to acquire and to run.

The software is stable and scaleable. A NEMS monitor would provide monitoring services for everything from a small remote office to a data center environment.

Support of NEMS has exceeded the support I have seen from many open source developers. I have contacted the developer of NEMS a few times over the last 18 months, and the replies have always been quick and accurate. A NEMS community forum link is also available on the NEMS project page.

NEMS could be your ideal solution if you are considering implementing a network device and service monitoring function in your own network, and you want a cost-effective solution that does not require Linux expertise either to implement or support.