Cacti.v7

From Thriving on the \'net

Howto Cacti

This whole section needs updating from version 0.8. The version running on our Raspberry Pi is v 1.2.2.

What is Cacti

Cacti is a complete network graphing solution designed to harness the power of RRDTool's data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with hundreds of devices.

http://cacti.net/

Extra things

Installing

yum

yum install cacti net-snmp-utils net-snmp php rrdtool php-snmp

This may run a whole bull pucky pile of stuff. Just let it do it's thing. This will have created a user called cacti that we will use later!

Setup the cacti Database

mysqladmin --user=root create cacti -p

Import the default cacti database:

mysql -uroot cacti -p< /var/www/cacti/cacti.sql

Create a MySQL username and password for Cacti.

mysql --user=root mysql -p
mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'somepassword';
mysql> flush privileges;

Edit /var/www/cacti/include/config.php and specify this MySQL user

emacs /var/www/cacti/include/config.php
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "somepassword";

Set the appropriate permissions on cacti's directories for graph/log generation.

chown -R cacti /var/www/cacti/rra/ /var/www/cacti/log/

Crontabs

DONOT add a line to your /etc/crontab file similar to:

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

I actually use this and it was wrong

*/5 * * * * su cactiuser -c "php /var/www/cacti/poller.php" > /dev/null 2>&1

The yum install has already added a cron job in /etc/cron.d

Setting up cactid

yum install cacti-cactid

Edit the config file for cactid

pico /etc/cactid.conf
DB_Host         localhost
DB_Database     cacti
DB_User         cactiuser
DB_Pass         somepassword
DB_Port         3306

Edit the configuration of Cacti so you have the path to the cactid file setup.

Edit the configuration of Cacti to using the cactid to get the data.

Setting up snmp

yum install net-snmp-utils net-snmp

If snmp is now already set my then there are a number of things that do need to be set.

/etc/init.d/snmpd start

Check that it is running

ps aux | grep snmp

Will give:

root 16042 0.0 0.4 11708 4264 ? S 16:29 0:00 /usr/sbin/snmpd -Lsd -Lf /dev/null -p /var/run/snmpd -a

OR

lsof -i :199

Will give:

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
snmpd 16042 root 9u IPv4 2541093 TCP *:smux (LISTEN)

Okay, not what is the tree of information about this network entity?

snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Will give:

IP-MIB::ipAdEntIfIndex.10.0.0.3 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.19.3 = INTEGER: 3
IP-MIB::ipAdEntIfIndex.192.168.20.3 = INTEGER: 2

Or maybe NOTHING!

If NOTHING Do the following:

emacs /etc/hosts.allow
snmpd: 127.0.0.1

or

emacs /etc/snmp/snmpd.conf

And change the following: config

com2sec notConfigUser default public
com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public
Change 192.168.0.0/24 with your networks IP range
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
view all included .1
access notConfigGroup "" any noauth exact systemview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
syslocation Linux (Version Here), Purpose Here.
syscontact Just A. Geek <you@email.whatever>
/etc/init.d/snmpd start

Okay, now let's run this command again. What do we get?

snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 2

Can we run this command a against an external server?

snmpwalk -v 1 -c public ipaddress IP-MIB::ipAdEntIfIndex

To set snmpd to start on a restart:

chkconfig --add snmpd

Firewall for snmp

 echo -n ...snmp
 $IPT -A INPUT -p TCP -i $EXTETH -s $i --destination-port 161:162 -j ACCEPT
 $IPT -A INPUT -p UDP -i $EXTETH -s $i --destination-port 161:162 -j ACCEPT

Where $IPT is the path to iptables. Where $i is an external ipaddress that you let in. Where $EXTETH is the external ethernet card.

Setting up The Web Site

Go to http://your.site/cacti/ Most likely you can not see anything. So add this file...

emacs /etc/httpd/conf.d/cacti.conf
Alias /cacti/ /var/www/cacti/
<Directory /var/www/cacti/>
       DirectoryIndex index.php
       Options -Indexes
       AllowOverride all
       order deny,allow

  1. deny from all
  2. allow from 127.0.0.1
       allow from all
OR
       deny from all
       allow from 127.0.0.1
       allow from xxx.xxx.xxx.xxx
       AddType application/x-httpd-php .php
       php_flag magic_quotes_gpc on
       php_flag track_vars on
</Directory>

php.ini

sed -ie 's/.*memory_limit.*$/memory_limit = 128M/' /etc/php.ini \
  && grep memory_limit /etc/php.ini
emacs /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php
date.timezone = Pacific/Auckland
/etc/init.d/https restart

Using yum to install was nice and straight forward. The only issue was that the rrd files did not get created.

They were created when I ran:

su cactiuser php /var/www/cacti/poller.php

Cacti, SNMP & Windows

XP

These steps were taken from http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sag_snmptopnode.mspx?mfr=true

To install the SNMP service

You must be logged on as an administrator or a member of the Administrators group in order to complete this procedure. If your computer is connected to a network, network policy settings may also prevent you from completing this procedure. Open Windows Components wizard To open the Windows Components Wizard, click Start, click Control Panel, click Add or Remove Programs, and then click Add/Remove Windows Components.

  1. In Components, click Management and Monitoring Tools (but do not select or clear its check box), and then click Details.
  2. Select the Simple Network Management Protocol check box, and click OK.
  3. Click Next.
  4. You will be asked for the original installation CD
  5. Provide this and continue.
  6. When Finished Click on Finished.
  7. Close Add Remove Programes

SNMP starts automatically after installation.

This was all I needed to do to be able to have SNMP working. I have a Linux Server running Cacti, getting the snmp data from a Windows

To get around the Windows defalt firewall I ran this at a command line.... netsh firewall add portopening all 161:162 snmp enable custom xxx.xxx.xxx.xxx/32 Where xxx.xxx.xxx.xxx/32 is the ip address of my Linux Server doing the Cacti/SNMP monitoring

Windows Server 2003 & 2008

Setting up a win 2003 server is the sam as XP except you many need to also do the following.... Control Panel -> Turn WIndows features on or off -> Configuration -> Services -> SNMP Service (Double Click) Then the Security TAB

  1. Add a Community called public with Rights of READ ONLY.
  2. Set up the IP address of the Linux box running Cacti that is going to query this win 2003/2008 server.

File:Snmp1.jpg

Plugins

http://docs.cacti.net/plugins

http://docs.cacti.net/plugin:thold http://docs.cacti.net/plugin:monitor http://docs.cacti.net/plugin:docs Down load and install the Plugin Architecture (PIA) from here http://www.cacti.net/downloads/pia/

wget http://www.cacti.net/downloads/pia/cacti-plugin-0.8.7h-PA-v3.0.tar.gz

then

tar -zvxf cacti-plugin-0.8.7h-PA-v3.0.tar.gz

Now install using the the pre-patched full files. http://docs.cacti.net/manual:087:1_installation.9_pia


Download the settings plugin first

wget http://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz

Extract

tar -zvxf cacti-plugin-arch.tar.gz

Down load the plug ins desired.

Setting up Cacti Thresholds

Customising Cacti

Trango

Setting up Custom Graphs using SMNP

For a device to be queried for MIB information via SNMP we need a .xml file in <path_cacti>/resource/snmp_queries/ Data Queries

  • This file is referenced in Data Queries under XML Path
  • You may need to create a new Data Queries.

This Data Queries will need to be set up with a Data Input Method of Get SNMP Data (Indexed) Once you have a Data Queries, you need Associated Graph Templates. Once for each section of the .XML file that is querying MIBs area.

  1. The Associated Graph/Data Templates has a Name and a Graph Template.
  2. Make sure the Graph Template is set to the correct Graph.
  3. The correct Graph may not yet be created. You may do this later and need to come back here to set this correctly.
  4. In an Associated Graph Templates there will be fields automatically inserted from the .XML file for the Data Source, you will need to insure that the right DropDown is being setup and to place a Tick in the right hand tick box.
  5. Data Templates
  6. We now need a Data Templates to correctly receive the devices data for a RRD file.

The easiest way I have found to create a Data Template is to use an existing one of a similar type. IE use an Ethernet Traffic one to build a Radio Traffic Data Template. I have found that the Data Source - Step needs to be 300 and each Data Source Item - Heartbeat to be twice that, 600. At this point the Data Template does not know what .XML file is sending the data.

Graph Templates

We now need a Graph Templates to make use of this collected data in a Graph.

Again the easiest way I have found to create a Graph Template is to use an existing one of a similar type. Two areas need to be edited.

  1. Each Graph Template Item needs to be opened and edited to make sure the Data Source is pointed at the correct Data Template, Data Source, Data Source Item (set up in the previous section)
  2. Once all of these have Graph Template Items have been setup, you will most like have extra Graph Item Inputs we only what the Data Sources that relate to the # # Graph Template Items.
  3. Go in to each Data Source, the ones we want to keep are the ones with a tick in the Associated Graph Items.
  4. We now have a Graph Templates with an associated Data Template, but no link to the .XML that knows how to get the data from the device.

New Graphs

Now we create a Graph for a Device.

  1. The Device we want to graph should have already been created under Devices.
  2. Under New Graphs choose this device.
  3. Under Data Query choose the Select a graph type: and CREATE.
  4. Graph Management
  5. Under Graph Management choose this new Graph, and Turn On Graph Debug Mode.

You will most likely get an error because the associated .rrd files does not yet exist. We need to note this file and make sure it is the same file as refrenced in the Data Sources. Check that the Supplemental Graph Template Data, Graph Item Fields Data Sources are constant with the type of Graph Template and type of Data Template as we would expect.

Data Sources

Under Data Sources choose this new Data Source for this Graph, and Turn On Data Source Debug Mode.

  1. Check that the step, 300 and Heartbeat, 600 are correct.
  2. Check that the Data Source Fields, Data Source Path is the same as in the Graph Management RRDTool Command readout.
  3. Check that the Custom Data, Index Type - Index Value - Output Type ID are correct.
  4. This is where the link is back to the original .XML file in the Data Queries
  5. This will take some understanding of how the .XML file at the very beginning of this page has been constructed.
  6. Working with .XML files, Data Queries, Graph Templates and Data Templates that already work you can backtrack to see if and why your new Custom Cacti are or are not working.

Setting Up Graphs

Cacti & aiContact

HowTo:Cacti-aiContact

Mail Scanner

Step 1

  1. Gain SSH access
  2. Login
  3. su
  4. Go To = pico /etc/snmp/snmpd.conf
  5. Scroll Down Till You Find = #Executables/scripts

Step 2

  1. Open "cacti server"
  2. Gain SSH access
  3. Login
  4. su
  5. Go To = pico /etc/snmp/snmpd.conf
  6. Scroll Down Till You Find = # Executables/scripts

Step 3

Look at the "Executables/scripts" information from the "cacti server" and make sure it is equal to the new site If this is not the case then add the information from the "cacti server" to the new intended site.

Then type the following code = /etc/init.d/snmpd restart Test The Following Code /var/www/html/iserver/snmp/mailscanner-inq.sh /bin/sh /var/www/html/iserver/snmp/mailscanner-outq.sh The result should be 0

Step 4

In Cacti = mail.ai.net.nz/cacti/

  1. Console go to "Newgraph"
  2. Make a Graph For = Mail Scanner & CPU Usage
  3. Create Each One Individually

(LEAVE EVERYTHING AS DEFAULTS)

Step 5

How To Add To Mailing List

  1. Graph Trees
  2. @ Processes
  3. ADD (Right Hand Side)
  4. Parent Item = Emails
  5. Tree Item Type = Graph
  6. Graph = CPU Usage & Mail Scanner Individually

Cacti Monitoring Backups

Steps for setting up Cacti to graph backups.

Cacti Prerequisites

  1. Create a new User under **User Management**
    1. The quickest way is to copy an existing one with the desired permissions and edit as needed.
      1. **New Username** no spaces and no capitals
      2. **New Full Name** FQDN that links later to the **Devices**
      3. **New Realm** local
  2. Edit the new user:
    1. **Realm Permissions** just **View Graphs**
    2. **Graph Permissions (By Device)** Add the host for this customer

Cacti Graph Settings

  1. Log on to the server needing the graphs, i.e. mail.ai.net.nz
    1. emacs /var/www/inet/configure/python.cfg
    2. In the **[rsync]** section
    3. In the **directories = ** area
    4. Add **var/log/rsync* ** to the end of the area
    5. Save and run **python /var/www/inet/python/rsync_inet_backup.py delete**
  2. Log on to the weekly backup server
    1. Check that the files for rsync exist
    2. These are at **ll /backup.server/daily/mail.ai.net.nz/var/log/rsync.***
    3. And should be something like:
      1. -rw-r--r-- 1 root root 2050 Dec 18 02:05 /backup.server/daily/mail.ai.net.nz/var/log/rsync.mail.ai.net.nz.var_spool_mail
      2. -rw-r--r-- 1 root root 228401 Dec 18 02:05 /backup.server/daily/mail.ai.net.nz/var/log/rsync.mail.ai.net.nz.var_www
  3. Now create the needed graphs
    1. Log on to http://cacti.ai.net.nz/cacti/
    2. Go to **console**
    3. Go to **New Graphs**
    4. Choose the Host, i.e. mail.ai.net.nz
    5. Under **Graph Templates**, under **Create: (Select a graph type to create)** choose **BkUp Bytes Hr**
    6. Tick **Graph Template Name**
    7. Press Enter
      1. Under **Title** add the Directory being graphed i.e. **(Home)**
      2. Under **Backup Site** add this site, mail.ai.net.nz
      3. Under **Dir being Backed** add the dir being monitored **home**
      4. Click on **create**
      5. Do this for **home, boot, etc, var/lib, var/www** and may be some **zone** areas.
    8. Do this again for **BkUp Files Hr**
  4. Place these graphs in the **Must Monitor** Graph tree under **Backups**
    1. To do this go to the left hand **Graph Management**
    2. Choose the Host you have just created for.
    3. Search on **(**, this is the best way to get to all the back up graphs
    4. Select all
    5. Under **Choose an action:** chose **Place on a Tree (Must Monitor)**
    6. Under **Destination Branch:** choose **Backups**
    7. Choose **yes**
  5. In a couple of hours these graphs will begin to appear with a line.