Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Mon Apr 22, 2019 3:18 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 140 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 10  Next
Author Message
 Post subject:
PostPosted: Sat Aug 12, 2006 10:46 am 
Offline

Joined: Wed Apr 20, 2005 4:03 am
Posts: 6
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 9:30 pm 
Offline
Cacti User

Joined: Wed Nov 23, 2005 10:43 pm
Posts: 52
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]

_________________
| Cacti 0.8.6h | MySQL 5.0.22 | PHP 5.1.2
|Apache2.20 | RRDtool 1.2.13 | CentOS 4.3 | P4 3200Mhz | 2.5GB |


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 14, 2006 10:35 am 
Offline
Cacti User
User avatar

Joined: Wed Nov 09, 2005 8:35 am
Posts: 240
Location: Timisoara, Romania
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 10:13 am 
Offline
Cacti User

Joined: Wed Nov 23, 2005 10:43 pm
Posts: 52
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?

_________________
| Cacti 0.8.6h | MySQL 5.0.22 | PHP 5.1.2
|Apache2.20 | RRDtool 1.2.13 | CentOS 4.3 | P4 3200Mhz | 2.5GB |


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 12:30 pm 
Offline
Cacti User

Joined: Wed Jul 13, 2005 4:50 pm
Posts: 135
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 12:47 pm 
Offline
Cacti User

Joined: Wed Nov 23, 2005 10:43 pm
Posts: 52
so i would have too add each device by hand? The problem is, i need too add now 3,200 cable modems lol

_________________
| Cacti 0.8.6h | MySQL 5.0.22 | PHP 5.1.2
|Apache2.20 | RRDtool 1.2.13 | CentOS 4.3 | P4 3200Mhz | 2.5GB |


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 12:57 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22376
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 1:10 pm 
Offline
Cacti User

Joined: Wed Nov 23, 2005 10:43 pm
Posts: 52
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...

_________________
| Cacti 0.8.6h | MySQL 5.0.22 | PHP 5.1.2
|Apache2.20 | RRDtool 1.2.13 | CentOS 4.3 | P4 3200Mhz | 2.5GB |


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 1:14 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22376
Location: Muenster, Germany
By hand, why? I dumped my [email protected] to some file and performed some "change all" magic to them. It's a one-liner
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Last edited by gandalf on Thu Nov 16, 2006 1:24 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 1:23 pm 
Offline
Cacti User

Joined: Wed Nov 23, 2005 10:43 pm
Posts: 52
you did this within the CMTS?

_________________
| Cacti 0.8.6h | MySQL 5.0.22 | PHP 5.1.2
|Apache2.20 | RRDtool 1.2.13 | CentOS 4.3 | P4 3200Mhz | 2.5GB |


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 1:25 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22376
Location: Muenster, Germany
The dump was done on our "company wide configuration management database"
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 10:06 pm 
Offline
Cacti User

Joined: Wed Nov 23, 2005 10:43 pm
Posts: 52
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. = }

_________________
| Cacti 0.8.6h | MySQL 5.0.22 | PHP 5.1.2
|Apache2.20 | RRDtool 1.2.13 | CentOS 4.3 | P4 3200Mhz | 2.5GB |


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 6:36 am 
Offline
Cacti User

Joined: Wed Jul 13, 2005 4:50 pm
Posts: 135
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;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 11:18 am 
Offline
Cacti User
User avatar

Joined: Wed Nov 09, 2005 8:35 am
Posts: 240
Location: Timisoara, Romania
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;


Top
 Profile  
 
 Post subject: Automating the web interface
PostPosted: Tue Nov 28, 2006 9:26 am 
Offline

Joined: Tue Nov 28, 2006 9:17 am
Posts: 26
Location: Winnipeg, Canada
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 140 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6 ... 10  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group