+Cacti

Nagios with Cacti through the NPC plugin on CentOS 6.3

https://sites.google.com/site/ryanmelissari/home/nagios-on-centos-63

This was done using a Minimal install of CentOS 6.3 64-bit, but any RHEL based distribution should work.  This should help setting up a nagios + cacti install through the cacti NPC plugin.

Install prerequisites:

$ su -

# yum install -y mysql-server.x86_64 mysql-devel.x86_64 php-mysql.x86_64 php-devel.x86_64 php.x86_64 php-snmp.x86_64 httpd.x86_64 net-snmp.x86_64 net-snmp-devel.x86_64 net-snmp-utils.x86_64 rrdtool.x86_64 rrdtool-devel.x86_64 ruby-rrdtool.x86_64 gcc.x86_64 make.x86_64 wget.x86_64

Download Cacti from http://www.cacti.net/ and extract in root:

# cd /root/ ; wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz 

# tar -xvf /root/cacti-0.8.8a.tar.gz

Configure mysql and set root password to P@ssw0rd (set this to a better password):

# service mysqld start ; chkconfig mysqld on 

# mysqladmin -u root password 'P@ssw0rd'

# mysql_secure_installation

    Set root password? [Y/n] n

    Remove anonymous users? [Y/n] Y

    Disallow root login remotely? [Y/n] Y

    Remove test database and access to it? [Y/n] Y

    Reload privilege tables now? [Y/n] Y    

Import the cacti database (Change P@ssword to your password.  This sed syntac is just putting the necessary commands into the .sql file so we can import the database structure in the right database and give the cacti user the right permissions):

# sed -i -e '1i USE cacti;' /root/cacti-0.8.8a/cacti.sql ; sed -i -e '1i CREATE DATABASE cacti;' /root/cacti-0.8.8a/cacti.sql ; echo "CREATE USER cacti;" >> /root/cacti-0.8.8a/cacti.sql ; echo "GRANT ALL ON cacti.* TO 'cacti'@'localhost' IDENTIFIED BY 'P@ssw0rd';" >> /root/cacti-0.8.8a/cacti.sql ; mysql -u root -p < /root/cacti-0.8.8a/cacti.sql

Create a cacti user and make it apart of the apache group.  Also gave it nologin shell for security:

# useradd -s /sbin/nologin -M -N -G apache cacti

Move the source files to web directory with correct permissions:

# mkdir -p /var/www/html/cacti ; cp -R /root/cacti-0.8.8a/. /var/www/html/cacti ; chown -R cacti:apache /var/www/html/cacti

Attach mysql to cacti, changing the password to what you set earlier:

# vi +/database_username /var/www/html/cacti/include/config.php

$database_username = "cacti";

$database_password = "P@ssw0rd";

Configure iptables:

# vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# service iptables restart

Turn on snmp:

# service snmpd start ; chkconfig snmpd on

Enable php in Apache:

# vi /etc/httpd/conf.d/php.conf

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

Start Apache:

# service httpd start ; chkconfig httpd on

Browse to http://localhost/cacti/

(click next)

New Installation:

(click next)

Finish Installation:

(click finish)

Log into http://localhost/cacti using default username/password:

login: admin

password: admin

Download Nagios from http://www.nagios.org/download/core/thanks/

# cd /root/ ; wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gz ; tar -xvf nagios-3.4.4.tar.gz

Configure user accounts:

# useradd -s /bin/bash nagios ; groupadd nagcmd ; usermod -G nagcmd nagios ; usermod -G nagcmd apache ; usermod -G nagcmd cacti

Compile & Install Nagios:

# cd /root/nagios/ ; ./configure --with-command-group=nagcmd ;  make all ; make install ; make install-init ; make install-config ; make install-commandmode ; make install-webconf

Download Nagios-Plugins from http://nagiosplugins.org/ and extract:

# cd /root/ ; wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz ; tar -xvf nagios-plugins-1.4.16.tar.gz

Install Nagios-Plugins:

# cd /root/nagios-plugins-1.4.16 ; ./configure --with-nagios-user=nagios --with-nagios-group=nagios ; make ; make install

NRPE:

# cd /root ; wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz ; tar -xvf nrpe-2.13.tar.gz ; cd /root/nrpe-2.13 ; ./configure ; make ; make install

Enable nrpe check for nagios (Add to the bottom of define commands):

# vi /usr/local/nagios/etc/objects/commands.cfg

#NRPE

define command{

    command_name    check_nrpe

    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

    }

Start Nagios:

# /etc/rc.d/init.d/nagios start

Setup Web User for Nagios (Create Nagios web password):

# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin

New password: 

Re-type new password: 

Prerequistes to NPC (ndoutils 1.4b7):

# cd /root/ ; wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b7/ndoutils-1.4b7.tar.gz ; tar -xvf ndoutils-1.4b7.tar.gz ; cd /root/ndoutils-1.4b7 ; ./configure --disable-pgsql --with-mysql-lib=/usr/lib64/mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios ; make

Download NPC from http://www.mediafire.com/?iefyesb24ppsbwl (You will have to actually go and download it):

# cd /root ; tar -xvf npc-2.0.4.tar.gz ; cp -R /root/npc /var/www/html/cacti/plugins

Copy plugins:

# cp /root/ndoutils-1.4b7/src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o ; cp /root/ndoutils-1.4b7/config/ndomod.cfg /usr/local/nagios/etc/ndomod.cfg ; cp /root/ndoutils-1.4b7/src/ndo2db-3x /usr/local/nagios/bin/ndo2db ; cp /root/ndoutils-1.4b7/config/ndo2db.cfg /usr/local/nagios/etc/ndo2db.cfg

Configure nagios to use tcp rather than udp:

# vi +/output=127.0.0.1 /usr/local/nagios/etc/ndomod.cfg

output=127.0.0.1

#output=/usr/local/nagios/var/ndo.sock

# vi +/output_type=tcpsocket /usr/local/nagios/etc/ndomod.cfg

output_type=tcpsocket

#output_type=unixsocket

# vi +/socket_type=unix /usr/local/nagios/etc/ndo2db.cfg

#socket_type=unix

socket_type=tcp

Change some configuration options in nagios:

# echo "broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg" >> /usr/local/nagios/etc/nagios.cfg ; sed -i 's/process_performance_data=0/process_performance_data=1/g' /usr/local/nagios/etc/nagios.cfg

More configuration changes to plugins (This is one block of code you can copy and paste into your shell):

# sed -i 's/db_host=localhost/db_host=127.0.0.1/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_name=nagios/db_name=cacti/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_prefix=nagios_/db_prefix=npc_/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_user=ndouser/db_user=cacti/g' /usr/local/nagios/etc/ndo2db.cfg ; sed -i 's/db_pass=ndopassword/db_pass=P@ssw0rd/g' /usr/local/nagios/etc/ndo2db.cfg ; chmod go+r /usr/local/nagios/etc/ndomod.cfg ; chmod go+r /usr/local/nagios/etc/ndo2db.cfg

Download cacti plugins:

# cd /var/www/html/cacti/plugins ; wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz ; mv plugin\:settings-v0.7-1.tgz settings-v0.7-1.tgz ; tar -xvf settings-v0.7-1.tgz ; cd /var/www/html/cacti/plugins ; wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz ; mv plugin\:monitor-v1.2-1.tgz monitor-v1.2-1.tgz ; tar -xvf monitor-v1.2-1.tgz

Browse to http://localhost/cacti and then Console -> Configuration -> Plugin Management.  Then install and enable the NPC plugin:

Browse to http://localhost/cacti and then Console -> Configuration -> Settings -> NPC

Nagios Command File Path: /usr/local/nagios/var/rw

Nagios URL: http://localhost/nagios

Create the database tables for ndo2db:

# cd /root/ndoutils-1.4b7/db/ ; ./installdb -u root -p "P@ssw0rd" -h localhost -d cacti

Create init.d script for ndo2db and configure to start at boot:

# vi /etc/init.d/ndo2db

Copy Contents of: ndo2db script (Courtesy of Gaëtan from http://www.itpointofview.com/?p=191

# chmod gou+x /etc/init.d/ndo2db

# /etc/init.d/ndo2db start

# chkconfig ndo2db on

Add nagios to apache group:

#usermod -a -G nagios apache

Set SELinx security for nagios:

# chcon -R -t httpd_sys_content_t /usr/local/nagios

Set correct permissions on plugins:

# chown -R nagios:apache /var/www/html/cacti/plugins ; chown -R nagios:nagios /usr/local/nagios

Restart and enable Nagios on boot:

# chkconfig nagios on ; service nagios restart

Restart the box and test that everything comes back up, you are done!

# yum -y update ; shutdown -r now

Syslog for Cacti (Not yet completed):

Syslog for cacti:

# cd /var/www/html/cacti/plugins ; wget http://docs.cacti.net/_media/plugin:syslog-v1.22-2.tgz ; chown nagios:apache plugin\:syslog-v1.22-2.tgz ; mv plugin\:syslog-v1.22-2.tgz syslog-v1.22-2.tgz ; tar -xvf syslog-v1.22-2.tgz

Spine for cacti:

# cd /root/ ; wget http://www.cacti.net/downloads/spine/cacti-spine-0.8.8a.tar.gz ; tar -xvf cacti-spine-0.8.8a.tar.gz ; cd /root/cacti-spine-0.8.8a ; ./configure ; make

Configure cron to run the poller every 60 seconds:

# crontab -e

*/1 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

Problems encountered during setup:

It appears as though you do not have permission to view information for any of the hosts you requested...

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