Nagios Core serves as the basic event scheduler, event processor, and alert manager for elements that are monitored. It features several APIs that are used to extend its capabilities to perform additional tasks, is implemented as a daemon written in C for performance reasons, & is designed to run natively on Linux/*nix systems.

More information about nagios core and how it works can be found here. I will focus on setting in since if I you are reading this, you are probably know what it is, but have problems with setting in up and running. So here it is.

  1. Installing required packages
  2. Getting nagios-core installation files
  3. Necessary configuration
  4. Running install script
  5. After install tasks
  6. Enabling LDAP
  7. Finish!

Latest versions of nagios and plugins cane be found here:
nagios core: https://www.nagios.org/downloads/nagios-core/
nagios plugins: http://nagios-plugins.org/download/

1. Installing required packages

SSH to server, then su to root in order to avoid typing sudo all the time.

REMEMBER TO TYPE COMMANDS ONE AT A TIME IN ORDER TO SEE ERRORS AND WARNINGS!

Like always on Debian, start with updating and upgrading package repositories:

apt-get update -y
apt-get upgrade -y

Now, install required packages:

apt-get install -y wget build-essential unzip open-vm-tools

Next thing I often do is allowing specific user to act as root and to sudo without a password. I know it isn’t the most elegant way, but for installing and later, editing files with for example WinSCP – is quite comfortable. Later you can always revert the changes. Just add following line into: /etc/sudoers

your_user_name ALL=NOPASSWD: ALL

After all, reboot system (yes, I know, after Windows habits;))
Now, lets continue with installing rest of required packages (apache, php etc.):

apt-get install -y apache2 php5-gd libgd2-xpm-dev libapache2-mod-php5

Keep in mind to save somewhere passwords for apache etc…

2. Getting nagios-core installation files

Now, pwd to temporary directory and download nagios-core files:

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz

3. Necessary configuration

After downloading we need to add some users and groups:

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios

exctract archives and cd into nagios folder:

tar -zxf nagios-4.1.1.tar.gz
cd nagios-4.1.1/

4. Running install script

Time to run some install scripts:

./configure --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config

Now, we need to copy some defaults in order to actually start nagios:

install -c -m 644 sample-config/httpd.conf.in /etc/apache2/sites-enabled/nagios.conf

Now, add and allow nagios user to login to nagios:

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

Ok, now we DO NOT HAVE a running nagios core instance:)
We have managed to install it but we are still a few steps before actually running it.Let’s proceed to:

5. After install tasks

Copy event handlers to nagios directory

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/

go up one folder, back to /tmp:

cd ..

Now, download,untar and cd to nagios plugins directory:

wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
tar -zxf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1

and run install script:

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

Now, set permissions:

chown -R nagios:nagios /usr/local/nagios/etc/nagios.cfg
chown -R nagios:www-data /usr/local/nagios/var/rw/
chmod +x /etc/init.d/nagios

And check nagios config:

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

Output of above command should be as follows:

Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
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

If something is wrong, check and correct errors

Now, enable apache modules and make sure nagios is started on each reboot:

a2enmod rewrite
a2enmod cgi
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Now we need to change a few lines in nagios.conf as we copied default config which includes environmental variable which we do not have. This “normal” behaviour but will not allow to start nagios deamon. Error you will get looks something like:

root@nagios-core-test3:/tmp/nagios-plugins-2.1.1# /etc/init.d/nagios start
[....] Starting nagios (via systemctl): nagios.serviceFailed to start nagios.service: Unit nagios.service failed to load: No such file or directory. failed!

In order to correct this we need to change paths in nagios.conf from variables to absolute strings. Nano file /etc/apache2/sites-enabled/nagios.conf, and change:

[table id=2 /]

Ok, restart apache or even the whole server. After reboot you can check apache and nagios status

service apache2 status
service nagios status

You should get output like (apache2):

root@nagios-test04:/home/milosz# service apache2 status
● apache2.service - LSB: Apache2 web server
 Loaded: loaded (/etc/init.d/apache2)
 Active: active (running) since Tue 2015-11-24 14:27:41 CST; 1min 17s ago
 Process: 527 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCES S)
 CGroup: /system.slice/apache2.service
 ├─801 /usr/sbin/apache2 -k start
 ├─821 /usr/sbin/apache2 -k start
 ├─822 /usr/sbin/apache2 -k start
 ├─823 /usr/sbin/apache2 -k start
 ├─824 /usr/sbin/apache2 -k start
 └─825 /usr/sbin/apache2 -k start

Nov 24 14:27:41 nagios-test04 apache2[527]: Starting web server: apache2.

and for nagios:

root@nagios-test04:/home/milosz# service nagios status
● nagios.service - LSB: Starts and stops the Nagios monitoring server
 Loaded: loaded (/etc/init.d/nagios)
 Active: active (running) since Tue 2015-11-24 14:27:34 CST; 2min 21s ago
 Process: 460 ExecStart=/etc/init.d/nagios start (code=exited, status=0/SUCCESS)
 CGroup: /system.slice/nagios.service
 ├─497 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
 ├─499 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
 ├─500 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
 ├─501 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
 ├─502 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
 └─805 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

Nov 24 14:27:34 nagios-test04 nagios[497]: nerd: Channel servicechecks registered successfully
Nov 24 14:27:34 nagios-test04 nagios[497]: nerd: Channel opathchecks registered successfully
Nov 24 14:27:34 nagios-test04 nagios[497]: nerd: Fully initialized and ready to rock!
Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Successfully registered manager as @wproc with query handler
Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 501;pid=501
Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 499;pid=499
Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 502;pid=502
Nov 24 14:27:34 nagios-test04 nagios[497]: wproc: Registry request: name=Core Worker 500;pid=500
Nov 24 14:27:34 nagios-test04 nagios[460]: Starting nagios: done.
Nov 24 14:27:40 nagios-test04 nagios[497]: Successfully launched command file worker with pid 805

At this point nagios is working! You can login to the console by specifying login nagiosadmin and password for this account.

In the next part I will cover LDAP configuration and basic host and services creation/adding, so stay tuned!