If you have an working Nagios Core monitoring server and some Linux machines (physical or virtual) you might want or even need to monitor their state. Nagios is a cool and free solution that makes this quite simple.

After you have deployed Nagios Core 4.0.x and up as a monitoring host you need to install monitoring daemon on Linux hosts. I have managed to monitor multiple Linux hosts with Nagios Core. All my Linux hosts run Debian or Ubuntu and this quick guide is based on Debian (wheezy).

Let’s start :)

1. Login to the Linux host you want to monitor, change to root:

user@nagios:~$ sudo -s

[sudo] password for user:

2. Install necessary packages from the Internet:

$ apt-get install nagios-nrpe-server nagios-plugins

3. Edit the nrpe.cfg config file located in /etc/nagios/nrpe.cfg
by editing and uncommenting line

allowed_hosts=127.0.0.1

and changing 127.0.0.1 to your Nagios Core monitoring server IP Address
4. Restart nrpe daemon by issuing a command:

$ service nagios-nrpe-server restart

After above steps your host is ready to be monitored by your Nagios Core server.
Now we have to add the new host to the server config:
1. Login to the Nagios Core server, change to root:

user@nagios:~$ sudo -s[sudo] password for user:

2. Navigate to where nagios is installed, in my config it is:

/usr/local/nagios/

3. cd into /etc/ folder
If you haven’t add any Linux servers yet, and I assume you heaven’t since you are reading this guide
4. Edit your nagios.cfg file. Add the following lines

# Definitions for Linux hosts
cfg_file=/usr/local/nagios/etc/objects/linux.cfg

just under:

# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

If you have problems using VI editor, here’s a useful command library
5. Save changes, exit VI
6. Navigate to /usr/local/nagios/etc/objects#
and copy localhost.cfg into linux.cfg
7. Edit linux.cfg file and change all instances of localhost to hostname of which you want to monitor, and change 127.0.0.1 to the IP Address of monitored host.
You can add alias or whatever definitions you like. Nice definition list is located here
If you have linux-servers group created, and I assume you do since it’s declared in localhost.cfg you may want to add monitored hostname to the localhost.cfg in the following line:

define hostgroup{
hostgroup_name  linux-servers ; The name of the hostgroup
alias      Linux Servers; Long name of the group
members    localhost,YOUR_MONITORED_HOST_SHORTNAME*
}

*This short name is defined in linux.cfg define host section next to host_name, for example:

host_name    glpi

8. Save all changes, exit VI
9. Restart Nagios and Apache2 service by running:

service nagios restart
service apache2 restart

That would be all. Your Nagios Core server should now be able to view state of your host.