Archive for the ‘Nagios/Cacti’ Category

Nagios – SNMP Trap integration

October 14, 2009

We need to check the followings first:

1. A host that has nagios installed and configured. Get Nagios.
2. Forward SNMP traps from the device you want to monitor to the nagios host and make sure that the traps reach the nagios host. By default it should be UDP traffic on port 162. On a windows machine it should be under Services. Look for snmp service and configure it.
3. The MIBs of the device you want to monitor. Ask the manufacturer or look for that online. Sometimes you might be able to find them publicly available.
4. Install snmptrapd which is part of the open source package net-snmp. snmptrapd is a daemon that listens for SNMP messages and can trigger different events based on each message.

Configure snmptrapd

create a new file called snmptrapd.conf and add the following lines:

authCommunity log,execute,net public
traphandle default /opt/snmptrap/sbin/snmptt –ini=/opt/snmptrap/etc/snmptt.ini

nagios

August 27, 2008

1) Create Account Information

Become the root user. Create a new nagios user account and give it a password.

 /usr/sbin/useradd -m nagios
 passwd nagios

you will need to also add a nagios group (it’s not created by default). You should be able to skip this step on desktop editions of Ubuntu.

 /usr/sbin/groupadd nagios
 /usr/sbin/usermod -G nagios nagios

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user to the group.

 /usr/sbin/groupadd nagcmd
 /usr/sbin/usermod -G nagcmd nagios
 /usr/sbin/usermod -G nagcmd www-data

2) Download Nagios and the Plugins

Download the source code tarballs of both Nagios and the Nagios plugins (visit http://www.nagios.org/download/ for links to the latest versions). At the time of writing, the latest versions of Nagios and the Nagios plugins were 3.0.3 and 1.4.11, respectively.

 wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.2.tar.gz
 wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz

3) Compile and Install Nagios

Extract the Nagios source code tarball.

 cd ~/downloads
 tar xzf nagios-3.0.2.tar.gz
 cd nagios-3.0.2

Run the Nagios configure script, passing the name of the group you created earlier like so:

 ./configure --with-command-group=nagcmd or 

 ./configure --prefix=prefix --with-cgiurl=cgiurl --with-htmurl=htmurl
 --with-nagios-user=someuser --with-nagios-group=somegroup --with-command-group=cmdgroup

Compile the Nagios source code.

 make all

Install binaries, init script, sample config files and set permissions on the external command directory.

 make install
 make install-init
 make install-config
 make install-commandmode

Don’t start Nagios yet – there’s still more that needs to be done…

4) Customize Configuration

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You’ll need to make just one change before you proceed…

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

 vi /usr/local/nagios/etc/objects/contacts.cfg

5) Configure the Web Interface

Install the Nagios web config file in the Apache conf.d directory.

 make install-webconf

Configure Aliases and Directory Options For The Web Interface

First you’ll need to create appropriate entries for the Nagios web interface (HTML and CGIs) in your web server config file. Add the following snippet to your web server configuration file (i.e. httpd.conf), changing it to match any directory differences on your system.

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

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

 Alias /nagios /usr/local/nagios/share

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

Note: The default Nagios installation expects to find the HTML files and CGIs at http://yourmachine/nagios/ and http://yourmachine/nagios/cgi-bin/, respectively. These locations can be changed using the –with-htmurl and –with-cgiurl options in the configure script.

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

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

Restart Apache to make the new settings take effect.

 /etc/init.d/apache2 reload

6) Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

 cd ~/downloads
 tar xzf nagios-plugins-1.4.11.tar.gz
 cd nagios-plugins-1.4.11

Compile and install the plugins.

 ./configure --with-nagios-user=nagios --with-nagios-group=nagios
 make
 make install(as root)

7) Start Nagios

Configure Nagios to automatically start when the system boots.

 ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios configuration files.

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

If there are no errors, start Nagios.

 /etc/init.d/nagios start

8) Login to the Web Interface

You should now be able to access the Nagios web interface at the URL below. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

 http://localhost/nagios/

Click on the “Service Detail” navbar link to see details of what’s being monitored on your local machine. It will take a few minutes for Nagios to check all the services associated with your machine, as the checks are spread out over time.

9) Other Modifications

If you want to receive email notifications for Nagios alerts, you need to install the mailx or mail relayer program.

Here is a mail relayer.

Cacti Installation

August 27, 2008

Cacti Installation

Extract Cacti

  1. Get Cacti (http://www.cacti.net/downloads/cacti-0.8.7a.tar.gz) and place in /var/tmp/
  2. gtar xvfz /var/tmp/cacti-0.8.7.tar.gz
  3. mv /var/tmp/cacti-0.8.7 /usr/local/apache/htdocs/cacti

Create Cacti DB in MySQL

Note: have your mysql root password ready

  1. mysqladmin --user=root -p create cacti
  2. mysql --user=root -p cacti < /usr/local/share/cacti/cacti.sql
  3. mysql --user=root -p mysql
     GRANT ALL ON cacti.* TO cactiuser@localhost;
     GRANT USAGE ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword';
     GRANT ALL ON cacti.* TO cactiuser@"%";
     GRANT USAGE ON cacti.* TO cactiuser@"%" IDENTIFIED BY 'cactipassword';
     flush privileges;
     exit

Update Cacti with DB username/password

  1. vi /usr/local/apache/htdocs/cacti/include/config.php
      $database_default = "cacti";
      $database_hostname = "localhost";
      $database_username = "cactiuser";
      $database_password = "cactipassword";

Add Cacti Poller to Crontab

  1. vi /etc/crontab
      */5 * * * * /usr/local/php/bin/php /opt/apache/htdocs/cacti/poller.php >/dev/null 2>&1(Linux)
      0,5,10,15,20,25,30,35,40,45,50,55 * * * *  /usr/local/php/bin/php /opt/apache/htdocs/cacti/poller.php >/dev/null 2>&1(Solaris)

Configure Apache for Cacti

  1. vi /usr/local/etc/apache22/httpd.conf
      <Directory /usr/local/apache/htdocs/cacti/>
             AllowOverride None
             Order allow,deny
             Allow from all
      </Directory>
      Alias /cacti/ /usr/local/apache/htdocs/cacti/

Log in for the 1st time!

  1. http://x.x.x.x/cacti/
        1. Accept the defaults
        2. Login as admin/admin
        3. Change admin password

Installing rrdtool

August 27, 2008

$ ./configure –prefix=/usr/local/rrdtool –disable-python –disable-tcl

before you run make command please ensure the following change in rrdtool-1.2.28/bindings/perl-shared/Makefile

  change CC=cc to CC=gcc
  change CCCDLFLAGS = -KPIC to CCCDLFLAGS =
  change LD = cc to LD = gcc
  change OPTIMIZE = xo3 -xspace -xildoff to OPTIMIZE =

$ make

And finally as root

make install