Getting Started with Nagios Core

If you have taken a look at Nagios XI, you might be interested to learn that there is a free version available. Nagios Core forms the basis for Nagios XI and you get all of the same monitoring capabilities. So, why would anyone pay for Nagios XI when they can get Nagios Core for nothing?

Understandably, Nagios XI has many advantages over its free counterpart – you wouldn’t expect to get the same thing for free. The Nagios Core system is the backend for Nagios XI and although there is a Web interface available for Nagios Core, it is not nearly as sophisticated. Nagios Core needs a lot of setup, while Nagios XI comes as a plug-and-play package.

This is the dashboard for Nagios XI:

Nagios XI

Nagios doesn’t supply a dashboard for Nagios Core, but other users have done and you can download one. Users of both Nagios XI and Nagios Core can access a library of add-ons, which are called “plug-ins” and the library is called Nagios Exchange.

So, the look of your Nagios Core dashboard is entirely up to you. You can design one yourself, or pick one of the user-created dashboards from Nagios Exchange. Here is a view of the Nagios V-Shell dashboard, which is one of the options available to you.

Nagios V-Shell dashboard

One other aspect of the Nagios family that will help a company decide which package to go for is professional support. That is included in the price of Nagios XI, but not included with Nagios Core. Nagios has a really great user community, and Nagios Core users can access the message boards of that group for tips and help. However, many companies are obliged by their professional insurance to only use supported software, so in those cases, Nagios XI is the only choice.

For those systems administrators and small business owners who are happy to go with a community-supported package and are prepared to put in the work to save money. Here is a guide on how to get Nagios Core up and running.

Once you have these basics running, you can look into options for creating your own dashboard with a system such as Kibana or Grafana.

Nagios Core system requirements

You will need space for the Nagios Core software, which is also referred to as the Nagios server. You will also need space for an interface and extra services from plug-ins. However, to deal with just the Core software, your computer will need the following capacity:

  • CPU cores: 1
  • RAM: 512 MB
  • Diskspace: 500 MB

The software runs on Linux, and it can be installed on just about every distro that exists:

  • Ubuntu
  • Debian
  • CentOS
  • Fedora
  • Red Hat Enterprise Linux (RHEL)
  • Oracle Linux
  • SUSE SLES | openSUSE Leap
  • Raspbian
  • Arch Linux
  • Gentoo

It will also run on FreeBSD, Solaris, and macOS. It doesn’t run on Windows.

Get Nagios Core

First of all, to get the Nagios Core software, don’t go to nagios.com – that’s the site for Nagios XI. Instead, go to nagios.org. Access the Nagios Core Download page to get the software.

You have to register first, then you get access to the download page. This gives you the source code.

Install Nagios Core on Linux (Ubuntu)

Each distro of Linux has its own command line conventions. For simplicity, this guide will only show the Ubuntu instructions. However, if you use a different Linux type, skip forward to the next section.

First, ensure that Security-Enhanced Linux (SELinux is not active because it will interfere with the installation process.

Make sure that you have all of the supporting applications installed before proceeding with the Nagios installation.

$ sudo apt-get update
$ sudo apt-get install -y autoconf gcc libc6 make wget unzip apache2   php libapache2-mod-php7.4 libgd-dev
$ sudo apt-get install openssl libssl-dev
Download the Nagios source code.
$ cd /tmp
$ wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
$ tar xzf nagioscore.tar.gz
Compile the code.
$ cd /tmp/nagioscore-nagios-4.4.14/
$ sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
$ sudo make all

Set up a user account and a group. Be aware that everyone installing Nagios Core creates the www-data user and nagios group – factors of which many hackers will be aware, so be sure to guard these accounts well.

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

Build all of the binaries and set up the system to run on startup, you also need to install command mode and the configuration file. This gives you a default configuration file, which will get the system running – Nagios won’t start up without the presence of a configuration file. You can fine-tune the records in the file later.

$ sudo make install
$ sudo make install-daemoninit
$ sudo make install-commandmode
$ sudo make install-config

The following lines set up supporting services with the Apache Web server and let it get through your firewall – it needs port 80 to be open for inbound traffic.

$ sudo make install-webconf
$ sudo a2enmod rewrite
$ sudo a2enmod cgi
$ sudo ufw allow Apache
$ sudo ufw reload

Set up a user account on Apache. This will be called nagiosadmin. The setup process will prompt you for a password. Setting up subsequent accounts uses the same command but without the -c. After setting up the account, you will need to restart the Apache Web server.

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
$ sudo systemctl restart apache2.service

Now you can start up Nagios Core and test that it is working.

$ sudo systemctl start nagios.service

You need to know the IP address of the server that you have installed Nagios on. With that information, Open a Web browser and get to that address on the HTTP schema. So, the address should have the IP address of your server instead of 999.999.999.999:

http://999.999.999.999/nagios

You will have to give the username nagiosadmin and the password that you set up in your Apache Web server. With this, you should be shown the following default Nagios Core Home page:

Installing Nagios Core on Linux (Ubuntu)

You now need to install several base plug-ins. There are many other plug-ins available for free, but these are the essentials. Get supporting services installed and running first:

$ sudo apt-get install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext

Implement the following commands:

$ cd /tmp
$ wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.6.tar.gz
$ tar zxf nagios-plugins.tar.gz
$ cd /tmp/nagios-plugins-release-2.4.6/
$ sudo ./tools/setup
$ sudo ./configure
$ sudo make
$ sudo make install

Install Nagios Core on other Linux distros

There are slight variations to the syntax in each Linux distro and so, depending on which one you have, you would need to make slight adjustments to the instructions given here for Ubuntu. We won’t show instructions here for every version of Linux because that would fill up many pages in the guide.

So, instead, we direct you to the following pages of the nagios.org site for your distro:

You can also get the instructions for installing FreeBSD and Solaris from the nagios.org site.

Install Nagios Core on macOS

The various versions of macOS all have the same command line conventions as each other, but these are a little different from Linux, so installation instructions for Nagios Core on Macs are detailed here.

Two prerequisites for running Nagios on macOS are Xcode and MacPorts. If you don’t have them already, you can get them from:

https://apps.apple.com/us/app/xcode/id497799835?mt=12

https://www.macports.org/install.php

Install Xcode with:

$sudo xcodebuild -license
$sudo xcode-select --install

Follow any instructions that appear and click on Agree where necessary. Complete the installation of prerequisites with:

$ sudo /opt/local/bin/port install zlib libpng jpeg gd2 apache2 php70 php70-apache2handler

Now you can get the Nagios Core source code and compile it:

$ cd /tmp
$ curl -L -o nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
$ tar xzf nagioscore.tar.gz
$ cd /tmp/nagioscore-nagios-4.4.14/
$ sudo ./configure --with-httpd-conf=/opt/local/apache2/conf/extra --with-gd-lib=/opt/local/lib --with-gd-inc=/opt/local/include
$ sudo make all

Set up a group and a user account.

$ sudo make install-groups-users
$ sudo dseditgroup -o edit -a _www -t user nagios

Install all components.

$ sudo make install
$ sudo make install-daemon init

Edit the global property list in vi.

$ sudo vi /Library/LaunchDaemons/org.nagios.nagios.plist

Enter insert mode by pressing i

Copy and paste the following into the vi editor:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
       <key>Label</key>
       <string>org.nagios.nagios</string>
       <key>UserName</key>
       <string>nagios</string>
       <key>GroupName</key>
       <string>nagios</string>
       <key>Program</key>
       <string>/etc/rc.d/init.d/nagios</string>
       <key>ProgramArguments</key>
       <array>
               <string>nagios</string>
               <string>start</string>
       </array>
       <key>KeepAlive</key>
       <dict>
               <key>SuccessfulExit</key>
               <false/>
               <key>NetworkState</key>
               <true/>
       </dict>
       <key>RunAtLoad</key>
       <true/>
       <key>ProcessType</key>
       <string>Background</string>
</dict>
</plist>

Press escape to exit insert mode and then type :wq and press Enter to write and quit.

Install command mode and a default configuration file:

$ sudo make install-commandmode
$ sudo make install-config

Set up the Apache web server configuration files.

$ sudo make install-webconf

Open the file /etc/apache2/httpd.conf with your favorite editor. Look for these lines:

 <IfModule dir_module>
   DirectoryIndex index.html
</IfModule>

Replace them with the following:

<IfModule dir_module>
   DirectoryIndex index.php index.html index.htm AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps
</IfModule>

Add the following lines at the bottom of the file:

Include conf/extra/nagios.conf
Include conf/extra/mod_php70.conf

Save the file and exit the editor.

Execute the following commands at the Terminal prompt:

$ sudo cp /opt/local/etc/php70/php.ini-production /opt/local/etc/php70/php.ini
$ cd /opt/local/apache2/modules/
$ sudo /opt/local/apache2/bin/apxs -a -e -n php7 mod_php70.so
$ printf '\nInclude conf/extra/nagios.conf\n' | sudo tee -a /opt/local/apache2/conf/httpd.conf
$ printf '\nInclude conf/extra/mod_php70.conf\n' | sudo tee -a /opt/local/apache2/conf/httpd.conf
$ sudo sed -i '' 's/DirectoryIndex index.html/DirectoryIndex index.php index.html index.htm AddType application\/x-httpd-php .phpAddType application\/x-httpd-php-source .phps/g' /opt/local/apache2/conf/httpd.conf

Make sure your firewall lets traffic in through TCP port 80.

Create an Apache user account to be able to log into Nagios. The account name is nagiosadmin.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

You will be prompted for a password for the account. Setting up subsequent accounts uses the same command but without the -c.

After setting up the account, you will need to start the Apache Web server and then you can start the Nagios Core daemon.

$ sudo /opt/local/bin/port load apache2
$ sudo /etc/rc.d/init.d/nagios start

Test that the service is running and access the dashboard. Get the IP address of the computer that you are running the Nagios Core on and then in a Web browser from any network-connected computer, enter the following address, giving the proper IP address instead of 999.999.999.999:

http://10.25.5.143/nagios

You will be prompted for a username and password. The username is nagiosadmin and the password is the one you gave when you set up that account.

If you now see the default Nagios Home page, your Nagios Core system was installed correctly and is running.

You now need to install some standard plug-ins. This installation process is why you needed to have MacPorts installed. The following lines install those essential plug-ins and also update the resource.cfg file to include the plug-in directory in the environment.

$ sudo /opt/local/bin/port install nagios-plugins

$ sudo sed -i '' 's/\/usr\/local\/nagios\/libexec/\/opt\/local\/libexec\/nagios/g' /usr/local/nagios/etc/resource.cfg

$ sudo /etc/rc.d/init.d/nagios stop

$ sudo /etc/rc.d/init.d/nagios start

Those last two lines restart Nagios to ensure that the changes take effect.

Uses for Nagios Core

Once you have your Nagios Core system set up, you should start to explore all the available plug-ins. Even without any plug-ins, you can use Nagios to monitor networks, servers, and software. The tool is very flexible and once you get familiar with identifying the right plug-ins in Nagios Exchange, you will be able to tailor your system to watch over the precise technologies that you have running on your site.

Interfaces for Nagios Core

Interface plug-ins that you might try can be accessed through the Nagios Frontends page, rather than wading through the search facility in Nagios Exchange. Ultimately, these are all stored in Nagios Exchange, the Frontends page is just a shortcut to them.