One of my Colleague had asked how he can use Nagios for PostgreSQL Monitoring. So, I thought of writing steps to show the blog readers about nagios Configuration for PostgreSQL/PPAS.

Following are the steps:

1. Download Nagios Core

wget http://nagios.sourceforge.net/download/cvs/nagios-HEAD.tar.gz

2. For Installing Nagios, following packages would be required,so make sure you have them installed on your server.

gcc 
make
binutils 
cpp 
libpq-dev 
libmysqlclient15-dev
libssl0.9.8 
libssl-dev pkg-config 
apache2 
libgd2-xpm 
libgd2-xpm-dev 
libgd-tools 
libpng12-dev 
libjpeg62-dev 
perl 
libperl-dev 
libperl5.8 
libnet-snmp-perl

3. Create nagios user and group as given below:

[root@localhost]# useradd nagios
[root@localhost]# passwd nagios
[root@localhost]# groupadd nagcmd
[root@localhost]# usermod -G nagcmd nagios
[root@localhost]# usermod -G nagcmd apache

4. Now, untar Nagios Core/Nagios Plugin using following command:

    tar -xvf  nagios-HEAD.tar.gz

5. Now configure Nagios Source Code as given below:

sh configure  --prefix=/opt/nagios --with-pgsql=/opt/PostgresPlus/8.4AS

Note:: Please note I would be installing nagios in /opt/nagios location. For more options on configure command, use following command:

./configure --help

6. Now install Nagios using the following commands:

make all
make
make install
make install-commandmode
make install-config

7. Now, configure Nagios for web interface, using following command:

make install-webconf

8. Create webinteface user nagiosadmin, password using following command:

/opt/nagios/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Note:: Please remember this password, since admin will use this command to connect to nagios using web-interface(explorer like firefox, chrome etc).

9. After installing Naios Core and configuring for web-interface, lets install Nagios Plugins using following command:

wget http://nagiosplug.sourceforge.net/snapshot/nagios-plugins-HEAD.tar.gz
./configure --prefix=/opt/nagios --with-pgsql=/opt/PostgresPlus/8.4AS
make
make install

Since, we have installed Nagios and plugins, now, lets configure it for PostgreSQL/PPAS.

1. Download check_postgres.pl from following link:

wget http://bucardo.org/downloads/check_postgres.tar.gz

2. Copy check_postgres.pl to /libexec as given below:

cp /usr/local/bin/check_postgres.pl /opt/nagios/libexec

3. Configure the Nagios Command as given below by adding following line in
nagiosinstallationdir/etc/commands.cfg as given below:

define command {
command_name check_edb_bloat
command_line $USER1$/check_postgres.pl --host $HOSTADDRESS$ --dbuser=enterprisedb --dbpass=edb -db edb -p 5444 --action bloat
}

Note:: Above is an example of adding the Monitoring service for PG Bloat in Nagios.

4. Lets create a Service file postgres.cfg in nagiosinstallationdir/etc/objects directory using following line (please feel free to replace the hostname)

define service {
    use                     generic-service
    host_name               localhost
    service_description     Postgres bloat
    is_volatile             0
    check_period            24x7
    max_check_attempts      3
    normal_check_interval   5
    retry_check_interval    1
    contact_groups          admins
    notification_interval   120
    notification_period     24x7
    notification_options
    check_command           check_edb_bloat!3000000!9000000!flr
}

5. Now update the nagiosinstallationdir/etc/nagios.cfg file for the postgres.cfg, by adding following command:

cfg_file=/opt/nagios/etc/objects/postgres.cfg

6. Verify the configuration files using following command:

root@ubuntu:~# /opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg 

Nagios Core 3.2.3
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 10-03-2010
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/opt/nagios/etc/objects/commands.cfg'...
Processing object config file '/opt/nagios/etc/objects/contacts.cfg'...
Processing object config file '/opt/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/opt/nagios/etc/objects/templates.cfg'...
Processing object config file '/opt/nagios/etc/objects/localhost.cfg'...
Processing object config file '/opt/nagios/etc/objects/postgres.cfg'...
Processing object config file '/opt/nagios/etc/objects/switch.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
	Checked 13 services.
Checking hosts...
	Checked 2 hosts.
Checking host groups...
	Checked 2 host groups.
Checking service groups...
	Checked 0 service groups.
Checking contacts...
	Checked 1 contacts.
Checking contact groups...
	Checked 1 contact groups.
Checking service escalations...
	Checked 0 service escalations.
Checking service dependencies...
	Checked 0 service dependencies.
Checking host escalations...
	Checked 0 host escalations.
Checking host dependencies...
	Checked 0 host dependencies.
Checking commands...
	Checked 25 commands.
Checking time periods...
	Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

7. Now start the nagios services using following command:

/etc/init.d/nagios restart

We are set to check the services in Nagios. Following are few snapshots:

Some nagios Configuration File details:

Important Nagios Configuration files:
Location: nagiosinstallationdir/etc/
nagios.cfg – Nagios Configuration file, which contains Global Parameters.
cgi.cfg – Nagios Web Interface Configuration file.
resource.cfg – Plugin Monitors resource configuration file (It contains sensitive information like username/password etc).

Location: nagiosinstallationdir/etc/objects

contacts.cfg: This is a configuration file in which user can specify name, email address and notification information with time period.
commands.cfg – This file contains the commands which can be use for services.You can use $HOSTNAME$ and $HOSTADDRESS$ macro on the command execution that will substitute the corresponding hostname or host ip-address.
timeperiods.cfg – User can define the timeperiods.
templates.cfg – template configuraton file
localhost.cfg – contains localhost monitoring information. Using this sample file user can define similar services for other hosts too.
printer.cfg – Sample config file for printer
switch.cfg – Sample config file for switch
windows.cfg – Sample config file for a windows machine

Enjoy!! 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s