Monitoring Ubuntu nodes with Nagios
Une version française de ce billet est disponible ici.
Nagios is considered by a lot of people as the number 1 tool when it comes to monitor from one server to a reasonable server farm. It has a good documentation, and lucky for people like me that are dealing with Ubuntu / Debian servers, the Ubuntu packages allows simple installation. The only problem are the Ubuntu packages are placing things in different places than the official “from the source” installation guides, and there are not much tutorial for installing a full monitoring system for total noobs like me. So here is my try to explain this.
The idea is to have one central monitoring Nagios host that will monitor a bunch of remote hosts. This is easily achieved through a plugin called Nagios Remote Plugin Executor (NRPE for short), which name quite explain what it does. This plugin has 2 parts:
- A daemon that you install on each remote host and that is accepting plugin commands from the nagios host
- A plugin in the Nagios host that knows how to send commands to each of the remote hosts
Setuping the remote hosts
This part is quite easy. Here are the commands:
sudo apt-get -y install nagios-nrpe-server
sudo sed -i.bak -r -e 's/allowed_hosts=127.0.0.1/allowed_hosts=$YOUR_NAGIOS_HOST_IP/g' /etc/nagios/nrpe.cfg
sudo /etc/init.d/nagios-nrpe-server restart
The second line is installing the daemon. The next one is instructing the daemon to accept commands only from your central nagios host (this is a minimal security precaution). Finally, you restart the daemon for taking the config change into account.
Note: when executing plugins remotely, it is more secure to not allow arguments to the plugins from the Nagios host, this is preventing script insertion, etc… This is the default setting in the config file, and this means you have to hard code the arguments of each command on the remote host. You can see the default ones and add some more at the end of the nrpe.cfg file. Here are the default commands:
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
Setuping the central Nagios host
Here is the command:
And that is it! The package will install postfix (required for sending email notification), apache and configure the ‘nagiosadmin’ user for you. All you have to do is to configure the objects in the /etc/nagios3/conf.d directory according to the documentation. Here is an example configuration of a remote host as well as a service calling the default remote hda1 check:
use generic-host ; Name of host template to use
alias My Server 1
address <ip of myServer1 here>
use generic-service ; Name of service template to use
service_description Disk Space
You can test the configuration with:
If everything is fine, you can restart Nagios with:
Finally, you can open a browser and go to http://YourNagiosHostIp/nagios3. The user is nagiosadmin and the password is the one you chose during installation.
This should give you a head start for working with Nagios.