Nagios Tutorial: Continuous Monitoring with Nagios Core and XI

Nagios is a popular monitoring tool many DevOps teams use to ensure thorough and efficient tracking of systems, devices, apps, and services. However, the tool does have a steep learning curve, so setting up and starting to use Nagios can be tricky without prior experience or a good tutorial.

This article gives an overview of Nagios' capabilities and provides an ideal starting point for newcomers to the tool.

Read on to learn about Nagios' essential features, benefits, and architecture, and discover how companies use the tool to ensure continuous monitoring of IT environments.

Nagios monitoring tool

What Is Continuous Monitoring?

Continuous monitoring is a process of constant detecting, reporting, and responding to risks and events within an IT system. This process is a vital DevOps security practice and has multiple goals:

The need for continuous tracking comes from the issues of manual monitoring as traditional tracking is too prone to:

The ability to quickly detect, report, and respond to threats is vital to a company's overall cybersecurity. Continuous monitoring is also a standard practice within SecOps teams as reliable, real-time insights throughout environments improve:

Other popular terms for continuous monitoring are ConMon and Continuous Control Monitoring (CCM).

Why Is ConMon Important?

Continuous monitoring is a vital aspect of modern cybersecurity. A sound ConMon solution allows a security team to:

If you are looking for a ConMon solution, our articles on cloud monitoring and server monitoring tools can help you find the right software.

What Is Nagios?

Nagios is an open-source app for monitoring systems, networks, and IT infrastructure. The tool allows users to track the state and performance of:

Nagios runs periodic checks on critical thresholds and metrics to monitor for system changes and potential problems. If the software runs into an issue, the tool notifies admins and can also run automatic scripts to contain and remedy the situation.

You can use Nagios to monitor:

The tool is available in two main variants:

This software is a common tool of choice in DevOps circles due to the solution's scalability, efficiency, and flexibility.

Our article on the best DevOps tools presents the top options on the market and helps put together an ideal DevOps toolchain.

Why Do We Need Nagios?

As with all robust ConMon tools, Nagios eliminates the need for manual monitoring. The team gets to focus on more impactful tasks than identifying and fixing infrastructure errors. Nagios also standardizes and centralizes monitoring across all environments, devices, and systems.

Other reasons why DevOps and SecOps teams often see Nagios as their go-to continuous monitoring tool are:

If you are interested in a database server but are unsure how much it will set you back, our article on database server pricing can help estimate the cost of your future setup.

Benefits of Nagios

Here are the main benefits of using Nagios for continuous monitoring:

Our article on network security tools presents additional tools you can use alongside Nagios to ensure safe and transparent network operations.

Nagios Features

Here are the main features of the Nagios monitoring tool:

Nagios Architecture

Nagios runs on a host server (usually as a daemon) and the tool's operations rely on a server-agent architecture. You set up an agent at the network element that requires monitoring, and the agent communicates with the Nagios server. The tool retrieves metrics via the agent and makes decisions based on events and set thresholds.

Another way Nagios can communicate with systems is through native protocols, such as SNMP or WMI. Depending on the setup, both agent and protocol-based monitoring can either be:

Nagios architecture has three main components:

While you can use the web-based GUI to interact with the tool, teams can also work in the command-line interface (CLI).

Nagios architecture explained

Nagios Plugins

Plugins are stand-alone add-ons and extensions that allow users to:

Plugins are either compiled binaries (written in C, C++, etc.) or executable scripts (Shell, Perl, PHP, etc.) users run from a command line. Plugins run on the Nagios server and enable users to monitor both remote and local hosts via agents or local protocols. Nagios uses the results generated by a plugin to determine:

Nagios plugins come in three types:

All plugins follow a status code. The table below explains the default exit code statuses and their descriptions:

EXIT CODESTATUSDESCRIPTION
0OKThe system is working fine
1WARNINGThe system continues to operate but requires attention
2CRITICALThe system is not working correctly
3UNKNOWNThe plugin cannot assess the status of the host or service

Nagios GUI

The graphical user interface (GUI) offers an overview of all the processes going on within Nagios. The Nagios XI GUI provides viewing of the most critical monitoring data and has six submenus:

Nagios GUI Quick view
Nagios Details menu
Nagios Graphs menu
Nagios Maps menu
Nagios Incident management menu
Nagios Monitoring process menu

In the top menu, you will find:

Nagios GUI top menu

Nagios Core Installation

The step-by-step guide below shows how to install Nagios Core on Ubuntu 20.04.

Step 1: Check for System Updates

1. You should first check the web for the latest available packages:

$ sudo apt update

2. Next, upgrade the system packages to the latest versions:

$ sudo apt upgrade

Step 2: Install Prerequisite Packages

After updating the system, you need to install the packages required to run Core. Enter the following code into the command line:

$ sudo apt install wget unzip vim curl gcc openssl build-essential libgd-dev libssl-dev libapache2-mod-php php-gd php apache2

Step 3: Download Nagios Core

Download Nagios Core. To do so, browse to the official Git repository and select the latest release. Alternatively, you can download the tool from the official website. At the time of writing this article, the latest version of Nagios is 4.4.6, so we use the following command to extract the tool:

$ export VER="4.4.6"

Now, use the curl command:

$ curl -SL https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-$VER/nagios-$VER.tar.gz | tar -xzf -

This command downloads a directory called nagios-4.4.6 and adds it to your current working directory.

Step 4: Install Nagios

We now need to install Core by compiling from the source.

1. Navigate into the Nagios directory:

$ cd nagios-4.4.6

2. Run the configure script:

$ ./configure
Installing Nagios Core on Ubuntu (configure check)

3. Run the make all command to compile the program alongside the CGIs:

$ sudo make all

4. Next, we need to create group users:

$ sudo make install-groups-users
$ sudo usermod -a -G nagios www-data

5. Now install Nagios Core on your Ubuntu system:

$ sudo make install
Installing Nagios Core on Ubuntu

6. As you can see, some additional instructions appear on the screen. Run the following command to install the init script in the /lib/systemd/system path:

$ sudo make install-init

7. Next, install and configure permissions on the directory:

$ sudo make install-commandmode

8. Finally, install sample config files in /usr/local/nagios/etc/:

$ sudo make install-config

Step 5: Set up Apache and Nagios UI

1. You need to enable the Apache module required for the Nagios web interface, so run the following command:

$ sudo make install-webconf
$ sudo a2enmod rewrite cgi
$ sudo systemctl restart apache2

2. Type in the following command for the classic Nagios monitoring theme:

$ sudo make install-classicui

Step 6:  Create the First Nagios User

We now need to create a user that can log in to Nagios. The following command creates a user called nagadmin:

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagadmin

You need to provide a password for the user and confirm it (by default, passwords are stored in /usr/local/nagios/etc/htpasswd.users).

Step 7: Install Nagios Plugins

Look at the latest available plugins at the official repository (at the time of writing this article, the newest released version is 2.3.3).

1. To download plugins, type the following command:

$ VER="2.3.3"
$ curl -SL https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz | tar -xzf -

2. This command creates a new directory (nagios-plugins-2.3.3) in your current working directory. To install plugins, you first need to navigate to the new directory:

$ cd nagios-plugins-2.3.3

3. Now compile the plugins from source:

$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios
$ sudo make install

4. To make sure all configurations are in order, run the following command:

$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Step 8: Start the Nagios Daemon

1. The last step is to start the Nagios service, which we achieve with the following command:

$ sudo systemctl enable --now nagios

2. To make sure the tool is running, use the following command:

$ sudo systemctl status nagios
Checking Nagios Core status

3. You can now access the tool by opening your browser and navigating to the http://server-IP/nagios URL.

4. Once prompted, type in the credentials defined in step 6 to sign in and you are ready to start monitoring.

Disadvantages of Using Nagios

While rich with capabilities, Nagios is not a perfect tool. Here are the main disadvantages of using Nagios:

Excellent Monitoring Capabilities, Even With the Free Version of the Tool

Nagios is a sound option for any business looking for reliable system monitoring. If your team never used the tool before, consider setting up Nagios Core for free and testing the tool's capabilities first-hand. After a few weeks with Core, you will know whether the team requires XI or not. Either way, your IT monitoring will see massive improvements.