Monitoring a Host using Nagios

Home / Monitoring a Host using Nagios

Monitoring a Host using Nagios

December 5, 2015 | Article | No Comments

In previous article we have discussed about how to install and configure Nagios on our machine. In this article we will discuss about adding a host to list of host monitored by Nagios. In this article I use FreeBSD 8.3.

Defining the Host

First of all, we need to identify the host / machine we want to monitor. What is the IP address? What service it runs? The network? etc.

A simple note can help us for suppress the error. It also help us document what host has been added to and what services and can help us to organize later.

In this article I make some dummy host, a gateway and a web server. The gateway has IP address 192.168.3.1 while the web server has IP address 192.168.3.3.

Making a Simple Configuration File

To add a host to list, we simply make a new configuration file. The configuration file must be stored on /usr/local/etc/nagios. In this example, I create a configuration file mygtw.cfg for my gateway and myweb.cfg for my web server.

On gateway, I only interested to know whether the gateway is up or down. The method for checking is using PING. And here is what I wrote on mygtw.cfg file:

define host {
  use freebsd-server
  host_name mygtw
  alias mygtw
  address 192.168.3.1
}

define service{
  use local-service
  host_name mygtw
  service_description PING
  check_command check_ping!100.0,20%!500.0,60%
}

For my web, I have some services and I want to monitor them all. The services available on web server are: web server and mail server. I also interest in knowing whether the host is up or down. Thus, I wrote on myweb.cfg:

define host {
   use freebsd-server
   host_name myweb
   alias myweb
   address 192.168.3.3
}

define service {
   use local-service
   host_name myweb
   service_description PING
   check_command check_ping!100.0,20%!500.0,60%
}

define service{
   use local-service
   host_name myweb
   service_description http
   check_command check_http
}

define service{
   use local-service
   host_name myweb
   service_description mail
   check_command check_smtp
}

If you look carefully, the gateway and web server are both on hostgroup freebsd-server. Thus on hostgroup definition on localhost.cfg we need to add information about the group. The localhost.cfg is located on <strong>/usr/local/etc/nagios</strong>. On hostgroup section

define hostgroup{
   hostgroup_name freebsd-servers
   alias FreeBSD Servers
   members localhost,mygtw,myweb ; Comma separated list of hosts that belong to this group
}

Then edit file /usr/local/etc/nagios/nagios.cfg and add file name of configuration files we have create after cfg_file=/usr/local/etc/nagios/localhost.cfg. Thus, we have this section:

cfg_file=/usr/local/etc/nagios/localhost.cfg
cfg_file=/usr/local/etc/nagios/mygtw.cfg
cfg_file=/usr/local/etc/nagios/myweb.cfg

Now check and make sure there is no error. You can invoke folloing:

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

If there is no error, we can restart the nagios by

/usr/local/bin/nagios /usr/local/etc/nagios/nagios.cfg &

Open your browser and check the network now.

,

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial