|
|
| Author |
Message |
Floppe
Joined: 20 Apr 2005 Posts: 6
|
Posted: Sat Aug 12, 2006 10:46 am Post subject: |
|
|
I'm searching for something like this.
What I need is a script that adds data sources that uses a script (data input method) and then the graphs for the data source. |
|
| Back to top |
|
 |
abadaba Cacti User
Joined: 23 Nov 2005 Posts: 52
|
Posted: Mon Oct 09, 2006 9:30 pm Post subject: |
|
|
Ok ive been picking my brain apart for hours trying too figure out how too add 2,400 cable modems using this...What i want is too be able too add all of them on one run like
[code]php add_device.php 1 SimpleTest 10.*.*.0/10.*.*.254 2 0 [code]
Or just being able too add the whole group of IP's in one shot...And then adding the graphs too go along with them...I know i can figur ethis out after hours of hammering away...But has anyone attempted this, and can maybe share some insight?[/code] |
|
| Back to top |
|
 |
timi Cacti User
Joined: 09 Nov 2005 Posts: 129 Location: Timisoara, Romania
|
Posted: Tue Nov 14, 2006 10:35 am Post subject: |
|
|
hi, i have a problem when i add a device, in log file i get this error
11/14/2006 03:04:41 PM - CMDPHP: Poller[0] ERROR: SQL Exec Failed "update data_template_data set rrd_maximum='|query_ifSpeed|' where local_data_id=11366" the data_template_data should be data_template_rrd, how can i change this ? becouse all gigabit interface have maximum value for traffic set to 1000000000 instead of 10000000000
i'm using cacti 0.8.6h |
|
| Back to top |
|
 |
abadaba Cacti User
Joined: 23 Nov 2005 Posts: 52
|
Posted: Thu Nov 16, 2006 10:13 am Post subject: |
|
|
| When i run php add_device.php 1 test21 10.201.*.* public 1 I dont get any errors. But when i check the devices, it didnt add anything at all...What could be the problem? |
|
| Back to top |
|
 |
Exo7 Cacti User
Joined: 13 Jul 2005 Posts: 124
|
Posted: Thu Nov 16, 2006 12:30 pm Post subject: |
|
|
| Quote: | | When i run php add_device.php 1 test21 10.201.*.* public 1 I dont get any errors. But when i check the devices, it didnt add anything at all...What could be the problem? |
The script is not supposed to handle wildcard.
You should add a 0 at the end to enable the host
| Code: | Usage:
add_device.php templateid description IP snmp_community snmp_version disable
Where:
- templateid is a number (read below to get a list of templates)
- description: the name that will be displayed by Cacti in the graphs
- IP: self explanatory (can also be a FQDN)
- snmp_community: community string
- snmp_version: 1/2
- disable: 1 to add this host but to disable checks and 0 to enable it |
|
|
| Back to top |
|
 |
abadaba Cacti User
Joined: 23 Nov 2005 Posts: 52
|
Posted: Thu Nov 16, 2006 12:47 pm Post subject: |
|
|
| so i would have too add each device by hand? The problem is, i need too add now 3,200 cable modems lol |
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Thu Nov 16, 2006 12:57 pm Post subject: |
|
|
| abadaba wrote: | | so i would have too add each device by hand? The problem is, i need too add now 3,200 cable modems lol | Personally, I created a list of all needed ip addresses and built a shell script, each line with a new address. So your shell script would hold 3200 entries. Not that big of a deal ...
Reinhard |
|
| Back to top |
|
 |
abadaba Cacti User
Joined: 23 Nov 2005 Posts: 52
|
Posted: Thu Nov 16, 2006 1:10 pm Post subject: |
|
|
| Yeah i seen the shell script thingy...Its just a way of getting them all by hand into the csv that would kill me lol... |
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Thu Nov 16, 2006 1:14 pm Post subject: |
|
|
By hand, why? I dumped my IP@ to some file and performed some "change all" magic to them. It's a one-liner
Reinhard
Last edited by gandalf on Thu Nov 16, 2006 1:24 pm; edited 1 time in total |
|
| Back to top |
|
 |
abadaba Cacti User
Joined: 23 Nov 2005 Posts: 52
|
Posted: Thu Nov 16, 2006 1:23 pm Post subject: |
|
|
| you did this within the CMTS? |
|
| Back to top |
|
 |
gandalf Developer
Joined: 02 Dec 2004 Posts: 12295 Location: Muenster, Germany
|
Posted: Thu Nov 16, 2006 1:25 pm Post subject: |
|
|
The dump was done on our "company wide configuration management database"
Reinhard |
|
| Back to top |
|
 |
abadaba Cacti User
Joined: 23 Nov 2005 Posts: 52
|
Posted: Sun Nov 19, 2006 10:06 pm Post subject: |
|
|
| Ive figured out how too dump all of the IP's in the CMTS. Now ive got that bash script, and it really cornfuses the mess outaa me. Im really not good at scripting at all. So does anyone have an idea of how it works? A lil simple how too would go a long way for me. = } |
|
| Back to top |
|
 |
Exo7 Cacti User
Joined: 13 Jul 2005 Posts: 124
|
Posted: Mon Nov 20, 2006 6:36 am Post subject: |
|
|
for each device in your file, call the php script with the device as argument.
in Perl, it is something like this (not tested, you should modify to your conveniance. My script is far more complicated to create a lot of different graphs).
| Code: |
#!/usr/bin/perl
use strict;
my $infile = "yourfile.csv"; # format should be "ip;hostname;snmp;snmp version;template_number"
open(INFILE, "< $infile") or die "can't open $infile";
while(<INFILE>) {
next if (/^$/ || /^#/); # empty lines and commentary
chomp(); # get rid of trailing \n
my @line = split(/;/); # read the line, separator is character ';'
my $ip = $line[0];
my $hostname = $line[1];
my $snmp = $line[2];
my $snmp_v = $line[3];
my $t_number = $line[4];
system("/usr/share/cacti/site/add_device.php $t_number $hostname $ip $snmp $snmp_v 0");
}
exit 0; |
|
|
| Back to top |
|
 |
timi Cacti User
Joined: 09 Nov 2005 Posts: 129 Location: Timisoara, Romania
|
Posted: Mon Nov 20, 2006 11:18 am Post subject: |
|
|
for each device from you list something like this...
--- cut ---
$command="./add_tree.php --type node --node-type header --tree-ID $tree_id --parent-node $leaf_id --name '$name'\n";
$test=qx!$command!;
if ($test =~ /.*Added Node node-id: \((\d*)\).*/)
{ $node_id=$1; }
--- cut ---
for the node_id run add_perms for each useres in your table...
--- cut ---
$query = "select * from user_auth";
$sth=$dbh->prepare($query) || &err_msg($dbh->errstr);
$rv=$sth->execute || &err_msg($sth->errstr);
while (@idz=$sth->fetchrow_array) {
$command="./add_perms.php --user-id $idz[0] --item-type tree --item-id $node_id\n";
$test=qx!$command!;
}
--- cut ---
find out the interface you want to monitor ... and create graphs...
--- cut ---
$command="./add_graphs.php --graph-type ds --graph-template-id $id --host-id $host_id --snmp-query-id $query_id --snmp-query-type-id $query_type --snmp-field $snmp_field --list-snmp-values\n";
$test=qx!$command!;
@int=split("\n",$test);
foreach my $interface (@int){
add_graphs.php and add_tree.php here for what do you need....
}
exit; |
|
| Back to top |
|
 |
SeanW
Joined: 28 Nov 2006 Posts: 24 Location: Winnipeg, Canada
|
Posted: Tue Nov 28, 2006 9:26 am Post subject: Automating the web interface |
|
|
I'm trying to migrate from MRTG to Cacti and found this thread. I started off by writing a script that reads information out of the MRTG config file and then generates the same graphs:
| Code: |
#!/usr/bin/perl
use strict;
foreach my $file (@ARGV) {
open IN, "<$file" or next;
my $data;
while (<IN>) {
next unless (/^Target\[(.*?)[\-_]?\d*\]: (.*):(\w+)@([\w\.]*):/);
my ($name, $oid, $community, $address) = ($1, $2, $3, $4);
$data->{$name} = {} unless $data->{$name};
$data->{$name}->{community} = $community unless ($data->{$name}->{community});
$data->{$name}->{address} = $address unless ($data->{$name}->{address});
push @{$data->{$name}->{intf}}, $oid;
}
foreach my $host (keys %$data) {
my $string = sprintf("./add_device.php %d %s %s %s %d %d",
5,
$host,
$data->{$host}->{address},
$data->{$host}->{community},
2,
0);
my $out = `$string`;
$out =~ /device-id: \((\d+)\)/;
my $deviceid = $1;
print "Added as $1\n";
foreach my $intf (@{$data->{$host}->{intf}}) {
my $addgraph = sprintf("./add_graph.php --graph-type %s --graph-template-id %d --host-id %d --snmp-query-id %d --snmp-query-type-id %d --snmp-field %s --snmp-value %d",
"ds",
2,
$deviceid,
1,
14,
"ifIndex",
$intf);
my $out = `$addgraph\n`;
}
}
}
|
Maybe I did something wrong, but the data queries never got associated with the new devices, so the add_graph failed because ifIndex wasn't a valid snmp field.
So, I wrote another script to go through the web interface and add them. I then figured that while I was there I may as well create all the graphs. Here's a script that logs in, iterates through all the devices, and creates all available graphs. I cheated a bit by forcing all the devices to appear on one screen by changing my display settings.
| Code: |
#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use Data::Dumper;
my $CACTIURL = "ENTER YOUR CACTI URL HERE";
my $ADMINPASSWORD = "ADMIN PASSWORD";
my $mech = WWW::Mechanize->new();
$mech->get($CACTIURL);
$mech->set_visible("admin", $ADMINPASSWORD);
$mech->click;
$mech->follow_link(text => "Devices");
my @links = $mech->find_all_links(url_regex => qr /host.php\?action=edit&id=/);
foreach my $i (@links) {
$mech->get($i);
# Set snmp_query_id to SNMP - Interface Statistics and hit the add_dq button
eval {
$mech->select(snmp_query_id => "SNMP - Interface Statistics");
$mech->click_button(name=>"add_dq");
};
$mech->follow_link(text => "Create Graphs for this Host");
$mech->form(2);
my @inputs = $mech->current_form()->inputs();
my $submitbutton;
foreach my $input (@inputs) {
if ($input->type == "checkbox" && $input->name =~ /[sc]g_\d+/) {
$mech->tick($input->name, "on");
}
$submitbutton = $input if ($input->type == "image"); # get the last one
}
$mech->select(sgg_1 => "In/Out Bits (64-bit Counters)");
$mech->click_button(input => $submitbutton);
foreach my $input (@inputs) {
$submitbutton = $input if ($input->type == "image"); # get the last one
}
$mech->click_button(input => $submitbutton);
# final create
}
|
Sean |
|
| Back to top |
|
 |
|