Working on a script to bulk add devices to Cacti. I’ve done on in a bash script, but that will only work on a windows box. I wrote this perl script so that I should be able to run it on any Linux or Windows box as long as perl is installed.

#!/usr/bin/perl -w

$LOGFILE = "/home/hades/perl/devices";
open(LOGFILE) or die("Could not open log file.");
foreach $line (<LOGFILE>) {

($description, $ip, $template, $notes, $avail, $version, $community) = split(',',$line);

system("php /usr/share/cacti/cli/add_device.php --description=$description --ip=$ip --template=$template --notes=\"$notes\" --avail=$avail --version=$version --community=$community");

The source for the script is this text file named devices.

Router1,,5,Edge router,snmp,2,public
Switch2,,5,Core switch,snmp,,2,public
Switch3,,5,Access switch,snmp,,2,public
Switch4,,5,Access switch,snmp,2,public
Switch5,,5,Access switch,snmp,2,public

I have some more tweaking to do, but it’s basically functional.