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
- fixCSV.pl Branches.CSV branches.csv
- Check branches.csv for empty IP address fields and remove
- mkBranchSql.pl branches.csv > branches.sql
- branches.sql ==> DB
- make_host_graph.pl branches.csv > host_graph.sql
- host_graph.sql ==> DB
- make_host_snmp_query.pl branches.csv > host_snmp_query.sql
- host_snmp_query.sql ==> DB
- foreach host_id do php run_data_query.php $host_id
- foreach host_id do php run_host_new_graphs.php $host_id
- Clear Poller Cache (php rebuild_poller_cache.php)
Process to add each host to proper state in graph tree
- create alphabetical flat file of state abbreviations, states
- mkBranchStatesSql.pl states > branches-states.sql
- branches-states.sql ==> DB
- mkGraphTreeSql.pl branches.csv > graph_tree_items.sql
Autocreate thresholds
- foreach host_id do php run_autocreate.php $host_id
Files
Perl
- make_host_graph.pl
- mkBranchStatesSql.pl
- fixCSV.pl
- make_host_snmp_query.pl
- mkGraphTreeSql.pl
- getHostID.pl
- mkBranchSql.pl
PHP
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?
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:
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.