** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integration

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
cachorroyayo
Cacti User
Posts: 53
Joined: Thu Sep 17, 2009 5:37 pm
Location: Lima - Peru

** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integration

Post by cachorroyayo »

Hello Forum

In order to try to cooperate with all the people help me, I consider a great way to thank those who helpme sharing this procedure with you.
I hope you can test and enjoy it.




Cacti - Plugins - NDOUtils - NPC - Nagios.


I’ve spent a good time trying to link Nagios with Cacti using NPC plugin and NDOUtils without success… But finally I did.

I’ve use a CentOS 6.3 (I guess architecture doesn’t matter as you procedure, but I use i386)
The Cacti version is 0.8.8a fom http://www.cacti.net with plugins architecture out-of-the-box
Thank you very very much Cacti development team.
Nagios was compiled from source, not downloaded from yum, I’ll tell you why after.

Warm-up


CACTI INSTALLATION
You will need to install

Code: Select all

[root@host]# yum install -y rrdtool  rrdtool-devel ruby-rrdtool mysql-server mysql-devel php-mysql  php-devel  php php-snmp httpd net-snmp net-snmp-devel net-snmp-utils
DOWNLOAD Cacti from the main site.
http://www.cacti.net

Code: Select all

[root@host]# wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
Untar the package

Code: Select all

# tar zxvf cacti- cacti-0.8.8a.tar.gz
Move the resultant folder to your preferred path I used to use (FreeBSD by default)

Code: Select all

# mv cacti-0.8.8a /usr/local/share/cacti/

CONFIGURE MySQL's Root Password

Code: Select all

# mysqladmin --user=root password cact1.123

Code: Select all

# mysqladmin --user=root --password reload

Code: Select all

# mysql -u root -pcact1.123

Code: Select all

mysql> CREATE USER cacti;
mysql> CREATE DATABASE cacti;
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cacti';
mysql> FLUSH PRIVILEGES;
Cacti’s Data Base
The Cacti database is included in the tar.gz source file, with all the structure we need, then you need to replace the Database you’ve created in the previous step with the database that comes with your tar.
The database we will use is in the path you move cacti to (/usr/local/share/cacti in my case).

Code: Select all

mysql -u root -pcact1.123 cacti < cacti.sql
Create a Cacti User

Code: Select all

# /usr/sbin/adduser cacti
Set Permission to folder

Code: Select all

# chown -R cacti:apache /usr/local/share/cacti/
CONFIGURE PHP for Cacti

Code: Select all

#vi /usr/local/share/cacti/include/config.php

Code: Select all

 $database_type = "mysql";
  $database_default = "cacti";
  $database_hostname = "localhost";
  $database_username = "cacti";
  $database_password = "cacti";
START SERVICES for first time

Code: Select all

root@host]# /etc/init.d/httpd start
Iniciando httpd:
[root@host]# /etc/init.d/mysqld start
Iniciando MySQL:                        [  OK  ]
[root@host]# /etc/init.d/snmpd start
Iniciando snmpd:                        [  OK  ]

ADD SERVICES to startup process

Code: Select all

[root@host]# /sbin/chkconfig --level 352 httpd on

Code: Select all

[root@host]# /sbin/chkconfig --level 352 mysqld on

Code: Select all

[root@host]# /sbin/chkconfig --level 352 snmpd on
CRON

Code: Select all

# crontab –e

Code: Select all

 */5 * * * * /usr/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
As you can see I do not use cacti (user) before /usr/bin/php; I don’t know why it does not work properly on CentOS 6.3, but if you run poller as root it works fine too.

APACHE Configuration
Create a cacti.conf file in the conf.d folder - - - >

Code: Select all

vi /etc/httpd/conf.d/cacti.conf

Code: Select all

DocumentRoot "/usr/local/share/cacti"

Alias /cacti /usr/local/share/cacti
<Directory /usr/local/share/cacti>
           Order allow,deny
           Allow from all
</Directory>
The php.conf file is in the follow path /etc/httpd/conf.d/php.conf),
Ensure to have the follow two lines, if you don’t, then add them to your file, save and proceed.

Code: Select all

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Just to be sure, restart or reload your httpd daemon (service httpd restart|reload)

Go to your cacti URL:
http://IP/cacti/

Follow the steps in the installation wizard.
When you sign in for the first time, the admin password is ‘admin’, change it, just for securing the system.


NAGIOS INSTALLATION

If you trust me, you will prefer download your Nagios.tar.gz and compile it like a real man (kidding).
Why?
Ok, if you download it from EPEL Repo and install it using yum, maybe some paths will no match with OUR procedure.
Then the THIS won't work.


We will use Nagios 3.4.1 the latest version of Nagios and Nagios-Plugins
In order to install them we follow the steps on the Nagios Official documentation.

Create a Nagios user

Code: Select all

[root@host]# useradd -m -s /bin/bash nagios
Set a Password to Nagios user

Code: Select all

[root@host]# passwd nagios
Create a nagcmd group

Code: Select all

[root@host]# groupadd nagcmd
Add nagios user to the previous group

Code: Select all

[root@host]# usermod -G nagios,nagcmd nagios
Add Apache user to the nagcmd group

Code: Select all

[root@host]# usermod -a -G nagios,nagcmd apache
Add cacti user you created previously to the same group

Code: Select all

[root@host]# usermod -a -G nagios,nagcmd cacti
Go to /tmp folder as a downloads repository folder

Code: Select all

[root@host]# cd /tmp
Download Nagios

Code: Select all

[root@host]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
Download Nagios-Plugins

Code: Select all

[root@host]# wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
Untar Nagios

Code: Select all

[root@host]# tar xvzf nagios-3.4.1.tar.gz
Untar Nagios-Plugins

Code: Select all

[root@host]# tar xzf nagios-plugins-1.4.15.tar.gz
Go to /Nagios-3.4.1 folder (remember you are in /tmp)

Code: Select all

[root@host]# cd nagios-3.4.1
START COMPILE Nagios

Code: Select all

[root@host]#./configure --with-command-group=nagcmd

Code: Select all

[root@host]# make all

Code: Select all

[root@host]# make install

Code: Select all

[root@host]# make install-init

Code: Select all

[root@host]# make install-config

Code: Select all

[root@host]# make install-commandmode

Edit your Nagiosadmin information

Code: Select all

[root@host]# vi /usr/local/nagios/etc/objects/contacts.cfg
Change the mail of the nagiosadmin user to yours, and keep compiling you’re almost done.

Code: Select all

[root@host]# make install-webconf
Set Nagiosadmin’s password

Code: Select all

[root@host]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
enter a great password
Restart|Reload Apache

Code: Select all

[root@host]# /etc/rc.d/init.d/httpd reload

Go to /Nagios-Plugins-3.2.3 (remember you are in /tmp)

Code: Select all

[root@host]# cd /tmp/nagios-plugins-1.4.15/
Start compile Nagios-Plugins

Code: Select all

[root@host]#./configure --with-nagios-user=nagios --with-nagios-group=nagios

Code: Select all

[root@host]# make

Code: Select all

[root@host]# make install

Install NRPE

Code: Select all

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

Code: Select all

tar xzf nrpe-2.13.tar.gz

Code: Select all

cd nrpe-2.13

Code: Select all

./configure

Code: Select all

make all

Code: Select all

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

Code: Select all

###NRPE
define command{
    command_name    check_nrpe
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
    }

Code: Select all

/etc/rc.d/init.d/nagios restart


Check Nagios conf, you will use this command several times (remember it)

Code: Select all

[root@host]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Start nagios for first time

Code: Select all

 [root@host]# /etc/init.d/nagios start
http://IP/nagios/


CACTI PLUGINS

Cacti plugins will give your Cacti installation some additioanals features, you will love to work with.
The previous verions of Cacti needs to be patched to work with the plugins, even your database should be modified (ALTER TABLE... ) in order to work with the plugins.
As I said at the top of this document I'm very very happy with Cacti's
Go to Cacti plugins folder
[root@host]#cd /usr/local/share/cacti/plugins

Download some plugins for testing (Note: you always need to download Settings plugin, is the main plugin)

Settings Plugin

Code: Select all

[root@host]#wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz

Code: Select all

[root@host]#mv plugin\:settings-v0.7-1.tgz settings-v0.7-1.tgz

Code: Select all

[root@host]#tar zxvf settings-v0.7-1.tgz
Monitor Plugin

Code: Select all

[root@host]#wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz

Code: Select all

[root@host]#mv plugin\:monitor-v1.2-1.tgz monitor-v1.2-1.tgz

Code: Select all

[root@host]#tar zxvf monitor-v1.2-1.tgz
NPC (our desired plugin to link Nagios with Cacti)

NPC (Nagios Plugin for Cacti) you can find it here http://www.mediafire.com/?iefyesb24ppsbwl,
Why I don’t put the full path?
Because the main URL gives you an unique resultant URL for each download you do.
In my case the URL was.

Code: Select all

[root@host]#wget http://205.196.123.83/ccuyad4sd6gg/iefyesb24ppsbwl/npc-2.0.4.tar.gz

Code: Select all

[root@host]#tar zxvf npc-2.0.4.tar.gz
NDOUTILS
Go to your downloads folder (/tmp)

Code: Select all

[root@host]#cd /tmp
Download NDOUtils
Once you’ve downloaded ndoutils, untar the file and go to the uncompress folder.

Code: Select all

 [root@host]#wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b7/ndoutils-1.4b7.tar.gz

Code: Select all

[root@host]#tar xvfz ndoutils-1.4b7.tar.gz|

Code: Select all

[root@host]#cd ndoutils-1.4b7
Compile NDOUtils

Code: Select all

[root@host]#./configure

Code: Select all

[root@host]#make
Here is why I suggested you compile Nagios, because if you use yum, all the packages and Nagios folders have been placed on /etc/

Copy the files as suggest

Code: Select all

[root@host]#cp src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o

Code: Select all

[root@host]#cp config/ndomod.cfg /usr/local/nagios/etc/ndomod.cfg
Edit the ndomod.cfg file
Ensure the file ends in the follow way. And save it.

Code: Select all

[root@host]#vi /usr/local/nagios/etc/ndomod.cfg

Code: Select all

output_type=tcpsocket
#output_type=unixsocket

output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock
Edit the nagios.cfg file

Code: Select all

[root@host]#vi /usr/local/nagios/etc/nagios.cfg
Add the follow line to your file.

Code: Select all

broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
After, change 0 to 1 the statement value

Code: Select all

             process_performance_data=1
Keep copying the remaining files.

Code: Select all

[root@host]#cp src/ndo2db-3x /usr/local/nagios/bin/ndo2db

Code: Select all

[root@host]#cp config/ndo2db.cfg /usr/local/nagios/etc/ndo2db.cfg
Edit the ndo2db.cfg file
The result must be as follows

Code: Select all

[root@host]#vim /usr/local/nagios/etc/ndo2db.cfg

Code: Select all

#socket_type=unix
socket_type=tcp

db_host=127.0.0.1
db_name=cacti
db_prefix=npc_
db_user=cacti
db_pass=***********
Set corresponding permissions to the files

Code: Select all

[root@host]#chmod go+r /usr/local/nagios/etc/ndo2db.cfg

Code: Select all

[root@host]#chmod go+r /usr/local/nagios/etc/ndomod.cfg

We will create a script for ndo2db and obviously set +X permission
The file starts empty, you’ll need to fill it with the information you’ll find in the follow http://www.itpointofview.com/?p=191

Code: Select all

[root@host]#vi /etc/init.d/ndo2db
The sctipy info is here web in the NDO Database Configuration section

Code: Select all

[root@host]#chmod gou+x /etc/init.d/ndo2db
Start the daemon and add to the startup process

Code: Select all

 [root@host]#/etc/init.d/ndo2db start

Code: Select all

[root@host]#chkconfig ndo2db on
Reboot your box and when it start again your NDO should be working fine

Code: Select all

[root@host]#reboot




WEB PROCESS

Once your system started after the previous reboot go to your cacti’s URL http://ip/cacti/ use your admin user and password and go to “Plugins Management” on the left Menu bar.

Will appear the plugins you previously downloaded with a blue arrow looking below, click the arrow to expand the menu and after do this, press the green arrow.

Immediately, close to Console and Graphs labels will appear your Plugin in a new label/tag.

Go to Settings in the left-side menu and click the link and look for NPC.
Click NPC link and in the text box Nagios URL set the Nagios’s URL of your installation (in my case http://127.0.0.1/nagios/)

Enable the check “Remote Commands” and set the nagios command (/usr/local/nagios/var/rw/nagios.cmd) you can find it using find command

Code: Select all

# find / -name nagios.cmd
*In my case is what I’ve defined above.

Click Save and you’re almost done.

After the previous process, if we have some hosts and hostgroups defined on Nagios (if you don’t, then do it… we’ll need hosts and hostgroups) we need to go to NPC label above your browser (close to Graphs), and in the left side you will see the "Reporting" folder, just below it you’ll find the N2C objetct, click it and you’ll see all the hostgroups you’ve defined in Nagios.

Suppose you have 3 servers (perhaps 3 Linux Servers) and now suppose your Hostgroup’s Name is "Linux Servers", click the HostGroup Check and choose a Template (in this case Local Linux Machine),then click the (+) sign to import.

If appears a message saying “Importing Host 1 of 3” we are good, then you can go to “Console” Tag of Cacti, go to devices and you’ll find your Nagios’s imported Servers.


I hope you can use this guide.... If you find some errors please let me know.
I will appreciate your feedback.


Enyoi it.
Seincerly
Eduardo Mejia Vizcarra.
Lima - Peru
adrenaline7
Posts: 8
Joined: Tue Jan 22, 2013 6:36 am

Re: ** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integra

Post by adrenaline7 »

Hi, I've installed everything and followed your guide in case of troubleshoots. Well done bro!
But now I have a big problem with npc.. Nagios, Cacti and NDOUtils work, buti with npc I cannot see host and host services..
Any issues?
Thank you
cachorroyayo
Cacti User
Posts: 53
Joined: Thu Sep 17, 2009 5:37 pm
Location: Lima - Peru

Re: ** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integra

Post by cachorroyayo »

Thank you for your comment buddy !!

Well, one of the issues I had, was when I tried to import form NPC tag to Nagios.
My 'error' was, do not select a template, to import.


Sincerely
Eduardo Mejia Vizacarra
Lima - Peru
http://cachorroyayo.blogspot.com
adrenaline7
Posts: 8
Joined: Tue Jan 22, 2013 6:36 am

Re: ** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integra

Post by adrenaline7 »

Thank you very much Eduardo, I solved this here on page 30 :)
http://forums.cacti.net/viewtopic.php?f ... &start=435

Because you talked about importing templates, I think it can be related to this http://forums.cacti.net/viewtopic.php?f=14&t=49406

I can see here
http://forums.cacti.net/viewtopic.php?f ... rt#p236398
that you solved something, but how did you solved? I can't understand..
Thanks
hatari
Posts: 2
Joined: Wed Feb 13, 2013 9:53 pm

Re: ** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integra

Post by hatari »

Hello!

I have followed this guide except with Ubuntu 12.04. Everything else is the same, cacti 8.8a, nagios 3.4, latest versions of plugins, etc.

I'm pretty familiar with nagios/cacti setup but not ndo/npc.

Everything is working great except the one thing I was hoping to have work: clicking N2C in Cacti produces a 'no hosts' message. No hostgroups, no hosts.

The Cacti database's npc_* tables are being populated with all my nagios hosts / hostgroups.

Someone said that its because the dbo config is not setup to read the database properly. However I have the prefix set correctly and the database name/username are the same I'm using for cacti. I can't seem to find any errors there.

Someone also said the add_device command is in a different location now and the npc/controllers/sync.php file needs to be modified. I modified the path to add_device to the exact path: /var/www/cacti/cli/add_device.php

Still N2C shows no hosts to import. *sad*
hatari
Posts: 2
Joined: Wed Feb 13, 2013 9:53 pm

Re: ** PROCEDURE ** Cacti 0.8.8a with NPC and Nagios Integra

Post by hatari »

HOLY COW.

After a complete rebuild, following this guide to the LETTER. It still would not work I finally figured it out. The error in var/log/messages was:

Feb 15 15:34:29 nagcat ndo2db: mysql_error: 'Unknown column 'long_output' in 'field list''
Feb 15 15:34:29 nagcat ndo2db: Error: mysql_query() failed for 'INSERT INTO npc_servicestatus SET instance_id='1', service_object_id='7', etc.....................

The fix was - and this is a step MISSING from the guide:

nano /tmp/ndoutils-1.5.2/db/mysql-upgrade-1.4b8.sql

Change the nagios_ prefix to npc_

mysql -u root -p cacti < /tmp/ndoutils-1.5.2/db/mysql-upgrade-1.4b8.sql

N2C now shows hosts and everything starts populating.

FIXED. :D

Hope this helps.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests