Adding a large number of devices to Cacti

There is a very nice open source snmp graphing and monitoring package avaiable called cacti. I have used it for almost a year now and have been very pleased with its functionality and ease of use.

Recently at work I had the need to graph a large number (300) of network devices and a handful of Linux servers. Being the sort of guy that would rather write scripts than manually enter 300 devices via the cacti web interface, I cobbled together some perl and php code. I had a list of network devices in a CSV file.

The format of the file is:

ID,City,State,IP Address.

If you use the scripts below you will need to edit them to fit your own device data. They are provided for illustration purposes and will most likely not work for you “out of the box”.

Update See this thread for more advanced scripts.

Process to add hosts and create graphs for each

  1. fixCSV.pl Branches.CSV branches.csv
  2. Check branches.csv for empty IP address fields and remove
  3. mkBranchSql.pl branches.csv > branches.sql
  4. branches.sql ==> DB
  5. make_host_graph.pl branches.csv > host_graph.sql
  6. host_graph.sql ==> DB
  7. make_host_snmp_query.pl branches.csv > host_snmp_query.sql
  8. host_snmp_query.sql ==> DB
  9. foreach host_id do php run_data_query.php $host_id
  10. foreach host_id do php run_host_new_graphs.php $host_id
  11. Clear Poller Cache (php rebuild_poller_cache.php)

Process to add each host to proper state in graph tree

  1. create alphabetical flat file of state abbreviations, states
  2. mkBranchStatesSql.pl states > branches-states.sql
  3. branches-states.sql ==> DB
  4. mkGraphTreeSql.pl branches.csv > graph_tree_items.sql

Autocreate thresholds

  • foreach host_id do php run_autocreate.php $host_id

Files

Perl

PHP

2 Responses to “Adding a large number of devices to Cacti”

  1. matt sey says:

    Hello!
    Your script’s helped us a lot. But we have the following problem.
    What do you mean with line 9?
    foreach host_id do php run_data_query.php $host_id
    how to execute this command?

  2. Hi,
    I’m glad I could help. Line 9 is pseudocode for a loop structure. To run the loop in bash using a text file called host_ids with each id on a line you could use:

    foreach host_id in `cat host_ids`;do php run_data_query.php $host_id;done

    An easier solution is now available in the form of several php scripts. See the Update note that I have added above.

    Thanks for reading.