Adding Linux host to Cacti

Hello my dear Linux Yogi’s,

in this illustration I am going to show you how you add a Linux Host to your Cacti Monitoring System. If you have not set up your Cacti Server please read the following Article first. Read Network Monitoring with Cacti.

Lets get started. The first thing you need to do is to prepare your Linux Host you like to monitor. Run the following commands to bring your system up to date:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get autoremove

Now that the system is up to date we need to install snmp service.

sudo apt-get install snmpd

That is installed and the next step you need to make a few adjustments to the snmpd configuration file.

sudo nano /etc/snmp/snmpd.conf

The first directive you need to adjust is the following:

# Listen for connections from the local system only
agentAddress udp:127.0.0.1:161

The directive above only allows localhost connections which will not work for our purpose. Make it look like the following:

#  Listen for connections from the local system only
agentAddress  udp:192.168.14.5:161

Now the directive above allows the local network cards IP address to listen on snmp requests. Make sure you use your own IP address of the Linux host.

In the next step you should add the following directive above the view directives that are already in the snmpd.conf file.

view     all     included     .1     80

The next change has to be done to the rocommunity directive. Change it from:

rocommunity     public     default     -V systemonly

to:

rocommunity     public     default     -V     all

and lastly you should provide some system information. Adjust the following Directive with your information.

sysLocation New Mexico Office
sysContact serveradministrator@company.com

That is it. Save the file and restart the snmpd service with the following command:

sudo service snmpd restart

Lets run two test to ensure snmp it working properly. The first test will be on the Linux host itself:

sudo snmpwalk -v 1 -c public -O e 127.0.0.1

The snmpwalk command above uses the switch -v 1 to specify the snmp version and the switch -c public specifies the community string public and the switch -O e print enums numerically and the last one 127.0.0.1 it the server address it has to run against. If it is successful you should see something similar to this:

SNMPv2-MIB::sysDescr.0 = STRING: Linux 4.4.0-72-generic #1 SMP Tue May 16 05:40:24 EDT 2017 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (242211) 0:40:22.11
SNMPv2-MIB::sysContact.0 = STRING: root@localhost
SNMPv2-MIB::sysName.0 = STRING: 
SNMPv2-MIB::sysLocation.0 = STRING: Unknown
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance

Great it worked next lets test it from your Cacti Server. The command is basically the same just the IP address will be the one of the Linux Host.

sudo snmpwalk -v 1 -c public -O e 192.168.14.5

and your output should be similar to the following:

SNMPv2-MIB::sysDescr.0 = STRING: Linux 4.4.0-72-generic #1 SMP Tue May 16 05:40:24 EDT 2017 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (242211) 0:40:22.11
SNMPv2-MIB::sysContact.0 = STRING: root@localhost
SNMPv2-MIB::sysName.0 = STRING: 
SNMPv2-MIB::sysLocation.0 = STRING: Unknown
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (2) 0:00:00.02
SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance

If you receive nothing back or an error stating that it cannot communicate than you most likely have a firewall enabled on your Linux Host. If it is a Ubuntu Linux Host you can conquer this with the following command:

sudo ufw allow 161

which pokes a whole in the firewall to allow snmp traffic. Okay the Linux Host is now prepared and we ensured that it is working locally and remotely. I recommend adding a Host Template to Cacti for Linux Hosts. Open up your Web Browser and go to: http://docs.cacti.net/usertemplate:host:linux:generic

The go ahead and download and extract the file cacti087e_linux_generic-20100519-yrg.zip. After you extracted it you should have a .xml file which you will import to cacti. Go to your Cacti System in your web browser and click on the link Import Templates on the left side. Use the Browser button and point to the xml file you just extracted and then click on Import. After successful import you have a new Host Template by the name “* Linux Generic“.

Lets Create a new Device by clicking on the link “Create Device for Network” as displayed below.

001 - Create new Device
001 – Create new Device

Next click on the “Add” link in the top right hand corner underneath the logout link.

002 - Add Device
002 – Add Device

Now you should see an half way empty form like in the screenshot below.

003 - enter device details
003 – enter device details

Enter a meaningful description and the Linux Hosts IP Address. I recommend to use IP addresses to minimize the network traffic. If you use the FQDN then CACTI will utilize a DNS Server to resolve the FQDN into and IP address. The last thing you need to adjust is the Host Template. Select “* Linux Generic” and click on the button “Create

004 - information entered
004 – information entered

On the top of the page you should see something similar like what you see in the screenshot below.

005 - Device successfully added
005 – Device successfully added

In the next step you want to create the graphs by clicking on the link in the top right hand corner saying “Create Graphs for this Host“.

006 - Create Graph for this Host
006 – Create Graph for this Host

Check the boxes of the Graphs you like to see and proceed and you see something similar like in the screenshot below.

007 - Graphs successfully added
007 – Graphs successfully added

Now that all graphs has been configured you have to place them on the Graphing Tree. Click on the link “Graph Trees” in the left hand column

008 - Go to Graph Tree
008 – Go to Graph Tree

Then click on the link “Default Tree” in the right hand column.

009-Go-to-Default-Tree.
009 Go to Default Tree

and then click on the “Add” link in the right hand corner.

010 – Add Device to Tree

Change the “Tree Item Type” to “Host” and below that select the desired host and keep the defaults for the rest and click on the button “Create

011 – Adding new Device to Tree

In order to see the graphs you need to click on the big red “Graphs” link in the top left corner and elapse the Default Tree and click on the Host you like to see.

012 - Graph Tree
012 – Graph Tree

If you see Graphs place holders like in the screenshot below that either means the graph has not yet been generated or there is an error. Give it some time so between 5 – 15 minutes and check again. If you have no data in your graphs something went wrong and you have to trace your steps back.

013 - Graphs being generated
013 – Graphs being generated

This concludes this illustration. I hope you liked this article. In the next article I will show you how to add a Windows Host to Cacti. Please register and subscribe to this blog and forum and provide some feedback.

Until next time, Namaste my friends 😉