Category Archives: monitoring

Monitoring a Host using Nagios

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 &amp;

Open your browser and check the network now.

The post Monitoring a Host using Nagios appeared first on Xathrya.ID.

Installing Nagios for Monitoring on FreeBSD 8.3

Nagios, one of the best tool we can find for building monitoring server. Nagios is free, open source, modular, easy to use, and high scalable. Initially, Nagios was designed for Linux Operating System, but later it run on almost any UNIX-like Operating System, including FreeBSD.

In this article we will discuss about how to install and use a simple configuration for Nagios. Of course, from the theme you can imply that I use FreeBSD 8.3.

Installation

Installing Nagios is as easy as installing any FreeBSD ports.

cd /usr/ports/net-mgmt/nagios
make install clean

Make sure you choose NETSNMP on nagios group and user. This allows Nagios to manage network using SNMP (Simple Network Management Protocol).

Autostart on Boot

To run Nagios automatically at boot time, we can edit /etc/rc.conf and add nagios_enable=”YES” at end of line. Another way, we can invoke following command:

echo 'nagios_enable="YES"' &gt;&gt; /etc/rc.conf

Running Simple Configuration

Configuration is simple. In fact, there is no need for us to write configuration from scratch. Nagios has provide a basic configuration and ready to use for generic situation. Using it is as simple as copying the file to Nagios working directory. Here is commands:

cd /usr/local/etc/nagios
cp cgi.cfg-sample cgi.cfg
cp nagios.cfg-sample nagios.cfg
cp resource.cfg-sample resource.cfg

cd /usr/local/etc/nagios/objects
cp commands.cfg-sample commands.cfg
cp contacts.cfg-sample contacts.cfg
cp localhost.cfg-sample localhost.cfg
cp printer.cfg-sample printer.cfg
cp switch.cfg-sample switch.cfg
cp templates.cfg-sample templates.cfg
cp timeperiods.cfg-sample timeperiods.cfg

Now check and make sure there is no error occured:

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

Next we need to make administrator account for accessing Nagios home page. We use default password, which is nagiosadmin

htpasswd -c /usr/local/etc/nagios/htpasswd.users nagiosadmin

Next, we need Apache to identifying Nagios. Therefore, edit httpd.conf using ee /usr/local/etc/apache22/httpd.conf. Add following text:

ScriptAlias /nagios/cgi-bin/ /usr/local/www/nagios/cgi-bin/
Alias /nagios /usr/local/www/nagios/

<Directory /usr/local/www/nagios>
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic
   AuthUSerFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user
</Directory>

<Directory /usr/local/www/nagios/cgi-bin>
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthType Basic

   AuthUSerFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user
</Directory>

Now, restart the Apache.

The configurations are stored on /usr/local/etc/nagios/. If we want to use the configuration, we can simply rename or copy the .cfg-sample file to .cfg file.

Before we play around with the files, it’s better for us to backup the directory to something else. For example:

mkdir /home/xathrya/nagios-samples/
cp * /nagios-samples/
mv bigger.cfg-sample bigger.cfg
mv cgi.cfg-sample cgi.cfg
mv checkcommands.cfg-sample checkcommands.cfg
mv localhost.cfg-sample localhost.cfg
mv misccommands.cfg-sample misccommands.cfg
mv nagios.cfg-sample nagios.cfg
mv resource.cfg-sample resource.cfg

Now we have all configuration files we need on /usr/local/etc/nagios.

Next open localhost.cfg file and adjust the setting to our network. This file will instruct Nagios to monitoring localhost or self monitoring.

In this case, we have defined commands to monitor service on localhost, defining contact information of administrator/user for Nagios notify to, etc.

Later we will check whether we have error on Nagios, using:

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

If there is no error, you should get message like this:

.........

.........
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check

Now we start Nagios with following command:

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

Now try to open browser and open the Nagios by URL. In my case, my machine has IP address 192.168.3.11 thus I can access nagios using URL http://192.168.3.11/nagios.

And that’s it. You now have Nagios monitoring your network

The post Installing Nagios for Monitoring on FreeBSD 8.3 appeared first on Xathrya.ID.