Is there any easy way to add a large number of routers and other devices to be monitored. I can't possibly see myself adding all of these devices (including their interfaces) by hand. Ideas??
New user here, sorry for the basic question... To keep my many other questions at bay, besides on the raxnet website are there any more detailed FAQ or documentation or tutorials on different parts of cacti?
THANKS!
Add a LARGE number of routers (cpu, traffic, etc..)
Moderators: Developers, Moderators
Here is what I used. You will need to edit some of the variables used thoughout the script to use it yourself such as
@host_ids - the host ids you want to add graphs for
@graph_templates - the graph templates to add for each interface
We used this to add graphs for each interface on over 200 cisco switches.
You will need to install the HTML::Form module from CPAN for this script (You may have to force the install, make test failed on all our servers)
You will also need to turn off builtin authentication for this to work because HTML::Form cannot store the session information cacti uses.
Let me know how it works or if you make any improvements. It's not designed to be too protable, we designed it to add graphs to cisco interfaces, nothing more, nothing less.
@host_ids - the host ids you want to add graphs for
@graph_templates - the graph templates to add for each interface
We used this to add graphs for each interface on over 200 cisco switches.
You will need to install the HTML::Form module from CPAN for this script (You may have to force the install, make test failed on all our servers)
You will also need to turn off builtin authentication for this to work because HTML::Form cannot store the session information cacti uses.
Let me know how it works or if you make any improvements. It's not designed to be too protable, we designed it to add graphs to cisco interfaces, nothing more, nothing less.
Code: Select all
#!/usr/bin/perl
################################################################################
# A script for Cacti to create a specified set of graphs for a list of hosts
# without user interaction.
#
# AUTHOR: Marc Bourgeois <marc dot bourgeois at housing dot wisc dot edu>
#
################################################################################
## Turn into Daemon to run without a terminal.. Should redirect output to log when doing this
use POSIX qw(setsid);
#chdir '/';
umask 0;
open STDIN, '/dev/null';
open STDERR, '>/dev/null';
defined(my $pid = fork);
exit if $pid;
setsid;
### Process is now daemonized
use HTML::Form;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout("3600");
$ua->credentials("your.cacti.hostname:443","Authentication Realm","username","passwrod");
# List host id's
# List of host ids to add graphs for, get these from view source on devices page
@host_ids = (532..554,584..611,613,576,578,632..633,432..465);
foreach $host_id (@host_ids)
{
print "Adding $host_id\n";
####
# Edit the host to add SNMP and graph templates
####
my $response = $ua->get("https://your.cacti.hostname/cacti/host.php?action=edit&id=$host_id");
#print $response->content;
my @forms = HTML::Form->parse($response);
#set $form to the "chk" form
foreach $curr_form (@forms)
{
$value = $curr_form->attr("name");
if ($value eq "chk"){
$form = $curr_form;
}
}
# Use HTML::Form module to set SNMP_query_id to '1' (SNMP-Interface Statistics)
$form->value( "snmp_query_id", "1");
# Click "add_dq" (Add) button of 'chk' form
$request = $form->click( "add_dq" );
# Issue the HTTP Request
$ua->request($request);
# Use HTML::Form module to set graph_template_id to '18'
$form->value("graph_template_id", "18");
# Click "add_gt" (Add) button of 'chk' form
$request = $form->click( "add_gt" );
# Issue the HTTP Request
$ua->request($request);
####
# Create the graphs for the host
####
# List of graph types to create, get from view source on graph create page
@graph_types = ( 3 );
$loop_counter = 0;
foreach $graph_type (@graph_types)
{
my $response = $ua->get("your.cacti.hostname/cacti/graphs_new.php?host_id=$host_id");
print " Adding Graph Type $graph_type\n";
my @forms = HTML::Form->parse($response);
# Set $form to the "chk" form
foreach $curr_form (@forms)
{
$value = $curr_form->attr("name");
if ($value eq "chk"){
$form = $curr_form;
}
}
# Use HTML::Form module to check all checkboxes in the "chk" Form
@inputs = $form->inputs;
foreach $input (@inputs)
{
# Check the box if it its name starts with sg (interfaces) or if it is the first graph id
# to be added ( i.e. add the graph templates (CPU Usage) the first time only, otherwise
# There will be duplicate graphs
if ( ( $input->type eq "checkbox" ) && ( ( substr($input->name,0,2) eq "sg" ) || ($loop_counter == 0) ) )
{
$input->check;
}
}
#print "Set sgg_1 (Graph Type)";
$form->value("sgg_1", $graph_type);
#print "Use HTML::Form module to Click the create button";
$request = $form->click;
#print "Issue the HTTP Request";
$graph_response = $ua->request($request);
#print "Use HTML::Form to set sg_1 (Index Type) to 'ifDescr' in unnamed form";
my @graph_forms = HTML::Form->parse($graph_response);
$graph_form = shift @graph_forms;
$graph_form->value("sg_1", "ifDescr");
#print "Use HTML::Form to Click the create button";
$graph_request = $graph_form->click;
#print " Issue the HTTP Request";
$new_response = $ua->request($graph_request);
$loop_counter++;
}
# Advance to next host and repeat
}
######
# Much of this code is forkable, but will not likely improve time of execution as the slowdown is with SELECT/INSERT
# statements in MySQL, since on most systems there is only one MySQL daemon using one processor simultaneous
# execution will not improve performance of these database queries.
#
# This script was designed as a 'run-once' to create a massive number of nearly identical graphs and for that reason
# the method of issuing HTTP requests to cacti was chosen as opposed to re-implementing existing cacti code.
######
Who is online
Users browsing this forum: No registered users and 4 guests