Bulk Add Devices to cacti

It is really a hassle to add lots of devices to cacti when setting up a new monitoring server. Even using a template to make sure you consistently change the community string and device type, adding new devices to cacti gets old, fast.

Automating cacti

But there is a better way. There is a script in the cacti distribution that automates the process of adding new devices to cacti. It’s called add_device.php. It takes description, IP address, community string, and template id as input and pushes the add device button for you! Well, sort of. It DOES poll the device and attempt to snmp poll it. If it succeeds, it will add the device AND create all the graphs in that template! Pretty cool, huh?

How to Use add_device

First, create a text file, named hostlist, in the format

hostname<space>ipaddr

where each device that you want to monitor has a unique line.

Then pipe it through this script:

while read line; do
j=$(echo "$line" | cut -f1 -d" ")
k=$(echo "$line" | cut -f2 -d" ")
php /usr/share/cacti/cli/add_device.php --description=${j} --ip=${k} --community=s3cr3t --template=3;
done < hostlist

Make sure that you put in YOUR “s3cr3t” community string and that “3” is the index number of the template that you want. I had to try a couple, hitting CTRL-C when I saw the output was wrong until I chanced upon 3 for NET-snmp devices.

Now, I’ve got EVERYTHING in my network monitored. I still need to go back and install net-snmp on a couple of servers. Maybe I’ll even turn on snmp on the Windows devices…

2 thoughts on “Bulk Add Devices to cacti

  1. Could you make this more of a step by step process? Like location of where that file should go and the index numbers and what they mean etc…..? Love your site by the way.

    1. MY script is looking for the file in /usr/share/cacti/cli/add_device.php
      You can put the script wherever you like, provided you supply the proper path when you run the script!

Leave a Reply to Alex Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.