Cacti with plugins - Nagios and NDOUtils integration (english)
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
[root@host]# yum install rrdtool rrdtool-devel ruby-rrdtool
Mysql for store your data
[root@host]# yum install mysql-server mysql-devel
PHP
[root@host]# yum install php-mysql php-devel php php-snmp
HTTPD
[root@host]# yum install httpd
SNMP for cacti
[root@host]# yum install net-snmp net-snmp-devel net-snmp-utils
DOWNLOAD Cacti from the main site.
http://www.cacti.net
[root@host]# wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz
Untar the package
# tar zxvf cacti- cacti-0.8.8a.tar.gz
Move the resultant folder to your preferred path I used to use (FreeBSD by default)
# mv cacti-version /usr/local/share/cacti/
CONFIGURE MySQL's Root Password
# mysqladmin --user=root password cact1.123
# mysqladmin --user=root --password reload
# mysql -u root -pcact1.123
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).
mysql -u root -pcact1.123 cacti < cacti.sql
Create a Cacti User
# /usr/sbin/adduser cacti
Set Permission to folder
# chown -R cacti:apache /usr/local/share/cacti/
CONFIGURE PHP for Cacti
#vi /usr/local/share/cacti/include/config.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
START SERVICES for first time
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
[root@host]# /sbin/chkconfig --level 352 httpd on
[root@host]# /sbin/chkconfig --level 352 mysqld on
[root@host]# /sbin/chkconfig --level 352 snmpd on
CRON
# crontab –e
*/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 - - - >
vi /etc/httpd/conf.d/cacti.conf
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.
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
[root@host]# useradd -m -s /bin/bash nagios
Set a Password to Nagios user
[root@host]# passwd nagios
Create a nagcmd group
[root@host]# groupadd nagcmd
Add nagios user to the previous group
[root@host]# usermod -G nagios,nagcmd nagios
Add Apache user to the nagcmd group
[root@host]# usermod -a -G nagios,nagcmd apache
Add cacti user you created previously to the same group
[root@host]# usermod -a -G nagios,nagcmd cacti
Go to /tmp folder as a downloads repository folder
[root@host]# cd /tmp
Download Nagios
[root@host]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz
Download Nagios-Plugins
[root@host]# wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz
Untar Nagios
[root@host]# tar xvzf nagios-3.2.3.tar.gz
Untar Nagios-Plugins
[root@host]# tar xzf nagios-plugins-1.4.15.tar.gz
Go to /Nagios-3.2.3 folder (remember you are in /tmp)
[root@host]# cd nagios-3.2.3
START COMPILE Nagios
[root@host]#./configure --with-command-group=nagcmd
[root@host]# make all
[root@host]# make install
[root@host]# make install-init
[root@host]# make install-config
[root@host]# make install-commandmode
[root@host]# make all
[root@host]# make install
[root@host]# make install-init
[root@host]# make install-config
[root@host]# make install-commandmode
Edit your Nagiosadmin information
[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.
[root@host]# make install-webconf
Set Nagiosadmin’s password
[root@host]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
enter a great password
Restart|Reload Apache
enter a great password
Restart|Reload Apache
[root@host]# /etc/rc.d/init.d/httpd reload
Go to /Nagios-Plugins-3.2.3 (remember you are in /tmp)
[root@host]# cd /tmp/nagios-plugins-1.4.15/
Start compile Nagios-Plugins
[root@host]#./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@host]# make
[root@host]# make install
[root@host]# make
[root@host]# make install
Check Nagios conf, you will use this command several times (remember it)
[root@host]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Start nagios for first time
[root@host]# /etc/init.d/nagios start
http://IP/nagios/
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.
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
[root@host]#wget http://docs.cacti.net/_media/plugin:settings-v0.7-1.tgz
[root@host]#mv plugin\:settings-v0.7-1.tgz settings-v0.7-1.tgz
[root@host]#tar zxvf settings-v0.7-1.tgz
[root@host]#mv plugin\:settings-v0.7-1.tgz settings-v0.7-1.tgz
[root@host]#tar zxvf settings-v0.7-1.tgz
Monitor Plugin
[root@host]#wget http://docs.cacti.net/_media/plugin:monitor-v1.2-1.tgz
[root@host]#mv plugin\:monitor-v1.2-1.tgz monitor-v1.2-1.tgz
[root@host]#tar zxvf monitor-v1.2-1.tgz
[root@host]#mv plugin\:monitor-v1.2-1.tgz monitor-v1.2-1.tgz
[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.
[root@host]#wget http://205.196.123.83/ccuyad4sd6gg/iefyesb24ppsbwl/npc-2.0.4.tar.gz
[root@host]#tar zxvf npc-2.0.4.tar.gz
[root@host]#tar zxvf npc-2.0.4.tar.gz
NDOUTILS
Go to your downloads folder (/tmp)
[root@host]#cd /tmp
Download NDOUtils
Once you’ve downloaded ndoutils, untar the file and go to the uncompress folder.
[root@host]#wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b7/ndoutils-1.4b7.tar.gz
[root@host]#tar xvfz ndoutils-1.4b7.tar.gz|
[root@host]#cd ndoutils-1.4b7
[root@host]#tar xvfz ndoutils-1.4b7.tar.gz|
[root@host]#cd ndoutils-1.4b7
Compile NDOUtils
[root@host]#./configure
[root@host]#make
[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
[root@host]#cp src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
[root@host]#cp config/ndomod.cfg /usr/local/nagios/etc/ndomod.cfg
[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.
[root@host]#vi /usr/local/nagios/etc/ndomod.cfg
output_type=tcpsocket
#output_type=unixsocket
output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock
#output_type=unixsocket
output=127.0.0.1
#output=/usr/local/nagios/var/ndo.sock
Edit the nagios.cfg file
[root@host]#vi /usr/local/nagios/etc/nagios.cfg
Add the follow line to your file.
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
After, change 0 to 1 the statement value
After, change 0 to 1 the statement value
process_performance_data=1
Keep copying the remaining files.
[root@host]#cp src/ndo2db-3x /usr/local/nagios/bin/ndo2db
[root@host]#cp config/ndo2db.cfg /usr/local/nagios/etc/ndo2db.cfg
[root@host]#cp config/ndo2db.cfg /usr/local/nagios/etc/ndo2db.cfg
Edit the ndo2db.cfg file
The result must be as follows
[root@host]#vim /usr/local/nagios/etc/ndo2db.cfg
#socket_type=unix
socket_type=tcp
db_host=127.0.0.1
db_name=cacti
db_prefix=npc_
db_user=cacti
db_pass=***********
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
[root@host]#chmod go+r /usr/local/nagios/etc/ndo2db.cfg
[root@host]#chmod go+r /usr/local/nagios/etc/ndomod.cfg
[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 below link
[root@host]#vi /etc/init.d/ndo2db
The script is here web in the NDO Database Configuration section
[root@host]#chmod gou+x /etc/init.d/ndo2db
The script is here web in the NDO Database Configuration section
[root@host]#chmod gou+x /etc/init.d/ndo2db
Start the daemon and add to the startup process
[root@host]#/etc/init.d/ndo2db start
[root@host]#chkconfig ndo2db on
[root@host]#chkconfig ndo2db on
Reboot your box and when it start again your NDO should be working fine
[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 casehttp://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
# 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.
Enjoy it.
No comments:
Post a Comment