Nagios Core / XI Setup with SNMP -v3 Auth

Ravinayag
5 min readJun 14, 2021

--

Engaged with a small task to quickly set up, troubleshoot the Nagios monitoring service for Linux hosts using SNMP v3. This document describes how you can quickly turn your infrastructure monitoring with nagios.

Your Nagios server — which is going to monitor your Linux hosts.
Client/Linux hosts — it may be your Linux server/windows server any client system.

For this documentation purpose, I have used Nagios core 4.4 for Nagios server-side and a simple SNMP v3 auth service for client systems.

Prerequisites:

Then install the following prerequisites: Nagios-Server

sudo apt-get install build-essential libc6 libgd2-xpm-dev apache2 apache2-utils unzip autoconf make wget php libapache2-mod-php libgd-dev libmcrypt-dev make libssl-dev snmp libnet-snmp-perl gcc bc gawk dc gettext

Downloading the Source

cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.5.tar.gz
tar xzf nagioscore.tar.gz

Create User And Group

Create the user and group as “nagios”. The www-data user is also added to the nagios group.

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

Compiling

$ cd /tmp/nagioscore-nagios-4.4.5/
$ sudo ./configure --with-nagios-group=nagios --with-command-group=nagios --with-httpd_conf=/etc/apache2/sites-enabled/
$ sudo make all
$ sudo make install
$ sudo make install-daemoninit
$ sudo make install-commandmode
$ sudo make install-config

Reference for each make command Installs from above

This step installs the binary files, CGIs, and HTML files.

sudo make install

This step installs the service daemon files and also configures them to start on boot.

sudo make install-daemoninit

This step installs and configures the external command file.

sudo make install-commandmode

This step installs the *SAMPLE* configuration files. These are required as Nagios needs some configuration files to allow it to start.

sudo make install-config

Install and Configure Apache Files

Install and configure apache files using the below commands,

$ sudo make install-webconf
$ sudo a2enmod rewrite
$ sudo a2enmod cgi

Restart an Apache to take effect

$ sudo systemctl restart apache2

Firewall — If enabled, else ignore

You need to allow port 80 inbound traffic on the local firewall so you can reach the Nagios Core web interface.

sudo ufw allow Apache
sudo ufw reload

Create user to access Nagios web interface

Create user in apache and set password.

$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
$ sudo systemctl start nagios.service

Now install nagios plugins

Nagios Core needs plugins to operate properly. The following steps will walk you through installing Nagios Plugins.

Go back to /tmp directory, Download the nagios core plugin, and extract it as shown below.

$ cd /tmp
$ sudo wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
$ tar zxf nagios-plugins.tar.gz

Compile and install nagios core plugins,

$ cd /tmp/nagios-plugins-release-2.2.1/
$ sudo ./tools/setup
$ sudo ./configure
$ sudo make
$ sudo make install

Once the installation is complete, go to the nagios installation directory “/usr/local/nagios/etc” and create a new directory for storing all server hosts configuration.

cd /usr/local/nagios/etc
mkdir -p /usr/local/nagios/etc/servers

Next, edit the Nagios configuration ‘nagios.cfg’ using your favorite editor.

vi nagios.cfg

Uncomment the ‘cfg_dir’ option that will be used for storing all server hosts configurations.

cfg_dir=/usr/local/nagios/etc/servers

Save and close.

Next edit the configuration file “resource.cfg” and define the path binary files of Nagios Monitoring Plugins.

vi resource.cfg

Define the Nagios Monitoring Plugins path by changing the default configuration as below.

$USER1$=/usr/lib/nagios/plugins

Save and close.

After that, add the nagios admin email contacts by editing the configuration file “objects/contacts.cfg”.

vi objects/contacts.cfg

Change the email address to your own.

define contact{
......
email myadmin_email@example.com
}

Save and close.

Now define the nrpe check command by editing the configuration file “objects/commands.cfg”.

vi objects/commands.cfg

Add the following configuration to the end of the line.

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Save and close, and the Nagioscore configuration has been completed.

Verify Nagios Configuration

Verify the Nagios core configuration

$ sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgNagios Core 4.4.5
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-08-20
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check

Next, start the Nagios service and add it to the system boot.

$ sudo  systemctl start nagios
$ sudo systemctl enable nagios
$ sudo systemctl restart apache2

Testing, you can access nagios web interface

point your web browser to the IP address or FQDN of your Nagios Core server followed by /nagios, for example:

http://server_IP_address/nagios       ORhttp://example.com/nagios

You will be prompted for a username and password.

Enter the credentials of “nagiosadmin” user that you have created in “Nagios web Interface” and the password is what you provided earlier. You will be redirected to nagios default page after successful login.

  1. To Monitor the services. go to Current status -> Services at left pane as shown below

2, Go to a host or service object and “Re-schedule the next check” under the Commands menu.

Congratulations you have installed Nagios Core Server.

This is Smaple image for ref.

Phase -2 — Enabling the SNMP Monitoring- Client side

--

--

Ravinayag

Blockchain enthusiast & Research | DevOps Explorer | Hyperledger Explorer