Since Nagios 4 is still unavailable in Debian/Ubuntu’s upstream apt repos, this article will present a high-level guide on how to manually set up Nagios 4 on Ubuntu 16.04, as well as how to customize/configure it.
The latest packages should be installed via apt-get:
apache2 libapache2-mod-php7.0 php7.0 wget unzip zip autoconf gcc libc6 make apache2
If you have Apache2 running within containers, you may have trouble starting Apache2 in the main host. When trying to start Apache2, you may encounter an error with this error message: “There are processes named ‘apache2’ running which do not match your pid file …”
To get around it, edit /etc/init.d/apache2
pidof $DAEMON, and replace with: pgrep --ns 1 --nslist uts $NAMEsudo systemctl daemon-reloadcd into the resulting directory./configure --with-httpd-conf=/etc/apache2/conf-availablemake allsudo make install-groups-users
sudo make install
sudo make install-init
sudo make install-daemoninit
sudo make install-config
sudo make install-commandmode
sudo make install-webconf
cd into the resulting directory./configuremakesudo make installhtpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminsudo usermod -aG nagios www-dataThe resulting installation from the above steps should place all the relevant Nagios files under /usr/local/nagios
You can see the systemd service script uses this directory for the binary, configuration scripts, and log files. The service script should be at /lib/systemd/system/nagios.service
The plugins can be found in /usr/local/nagios/libexec
The installation should have created a nagios.conf file within /etc/apache2/conf-available
sudo service nagios restartcgi module in Apache: sudo a2enmod cgisudo a2enconf nagiossudo service apache2 restartBy default Apache will bind to and listen on TCP port 80. To change this, edit /etc/apache2/ports.conf and restart Apache afterwards.
Open up a browser and go to: http://<SERVER IP>:<APACHE PORT>/nagios
The NRPE plugin allows Nagios to monitor remote hosts via a thin agent executor installed within each host.
Note: Nagios plugins will have to be installed in the remote hosts as well (hence the name “remote plugin executor”).
First, we will install the NRPE plugin into Nagios Core (i.e. the same server where Nagios Core was installed).
cd into the resulting directory./configuremake allsudo make install-plugincfg_dir=/usr/local/nagios/etc/serverssudo mkdir -p /usr/local/nagios/etc/servers
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
To add remote hosts to be monitored, it needs to install the NRPE daemon and Nagios plugins.
sudo apt-get -y install gcc openssl libssl-dev make./configuremake allsudo make install-groups-userssudo make install-daemonsudo make install-configallowed_hosts line and append the controller’s IP address to the end (don’t forget the comma separator)check_hda1 command
check_disk and ensure the device name at the end matches the root disksudo sed -i "s/check_hda1/check_disk/g" /usr/local/nagios/etc/nrpe.cfg
MAIN_DISK=`df -h / | tail -n1 | awk '{print $1}'`
sudo sed -i "s/\/dev\/hda1/"${MAIN_DISK//\//\\/}"/" /usr/local/nagios/etc/nrpe.cfg
sudo make install-init
sudo systemctl enable nrpe
sudo service nrpe restart && sudo service nrpe status
The following steps should be completed in the server where Nagios Core is installed.
./check_nrpe -H <AGENT HOSTNAME><AGENT HOSTNAME>.cfg
AGENT_NAME with the agent’s hostname define host {
use linux-server
host_name AGENT_NAME
alias AGENT_NAME
address AGENT_NAME
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
define service {
use generic-service
host_name AGENT_NAME
service_description CPU load
check_command check_nrpe!check_load
}
define service {
use generic-service
host_name AGENT_NAME
service_description Disk free space
check_command check_nrpe!check_disk
}
'!') is the command that will be executed in the remote hosts (e.g. check_load, check_disk)
cat /usr/local/nagios/etc/nrpe.cfg | grep '^command’