Ubuntu 18.10: Install Nagios for web base system monitor

This article will describe installing Nagios which is a web-base system monitor tool.

1 Before installing Nagios

Install Postfix with this script.

2 Install Nagios

NAGIOS_PASSWD will be used for Digest authentication password of nagiosadmin user.

#!/bin/sh -e

NAGIOS_PASSWD=nagios

nagios_install()
{
  sudo apt install -y apache2
  sudo a2enmod auth_digest
  sudo a2enmod authz_groupfile

  sudo apt install -y nagios4
  sudo sed -i /etc/apache2/conf-available/nagios4-cgi.conf \
       -e 's;Require all\tgranted;#Require all\tgranted;g' \
       -e 's;#Require\tvalid-user;Require\tvalid-user;g'
  sudo sed -i /etc/nagios4/cgi.cfg \
       -e 's;^use_authentication=0;use_authentication=1;g' \
       -e 's;^#default_user_name=guest;default_user_name=guest;g'
  for c in authorized_for_all_services \
             authorized_for_all_hosts \
             authorized_for_configuration_information; do
    sudo sed -i /etc/nagios4/cgi.cfg \
         -e "s;^${c}=nagiosadmin;${c}=nagiosadmin,guest;g"
  done
  sudo systemctl restart apache2

  # Create digest password file with expect command.
  sudo apt install -y expect
  expect -c "
set timeout -1
spawn sudo htdigest /etc/nagios4/htdigest.users Nagios4 nagiosadmin
expect \"New password: \"
send \"${NAGIOS_PASSWD}\n\"
expect \"Re-type new password: \"
send \"${NAGIOS_PASSWD}\n\"
expect eof
"
}

nagios_install

Nagios configuration to Apache2 is written in the following file.

/etc/apache2/conf-available/nagios4-cgi.conf

3 Access to Nagios

Access to Nagios via the following URL.

http://<server>/nagios4

0001_Nagios.png

Login with nagiosadmin as user and NAGIOS_PASSWD value as password for running command.

0002_DigestAuth.png