[rrd-users] Re: CBWFQ

Cassie Bezuidenhout cassieb at ifusion.co.za
Tue Dec 2 06:16:11 MET 2003


Hi All

The attached script runs a collect from the different classes on a Cisco
Router. This information is then send to RRD and graphed. 

I would like to know if it is possible for someone to have a look at the
code and let me know if how it could be improved. 

I would also like to add more values into my collect which will Graph both
the Passed bytes and Dropped bytes.

I know the code is a bit messy but I am not what they call a full time perl
programmer.


#!/usr/local/bin/perl
# Variables

use lib qw( /usr/local/rrdtool/lib/perl ../lib/perl  );
use RRDs;

use warnings;
#use strict;

my @cb_config;
my @cb_config1;
my @arraypol;
my @arraypol1;
my @arrayconf;
my @arrayconf1;
my @arrayname;
my @arraypol3;
my @arrayobj;
my @Array1stresult;
my @array2ndresult;
my @options;
my $line;
my $name_cell;
my $config_id1_cell;
my $config_id2_cell;
my $pol_id_cell;
my $obj_id_cell;
my $database;
my $node;
my $community;
my $bandwidth;

#open, read and close config file;
open FILE_conf, "/usr/local/qos/mcq.csv" or die $!;
@cb_config = <FILE_conf>;
close FILE_conf;
open (FILE_db_index, ">/usr/local/nmis/database/cb_report/db_index"), or die
!;
foreach $line (@cb_config)
{
@cb_config1 = split(/\,/,$line);
        $node = $cb_config1[0];
        $community = $cb_config1[1];
        if ($node) {
        if ($community) {
        chomp $node;
        chomp $community;
        #call external app snmpwalk
        #walk the CBWFQ config mib
        #place result in "arrayconfig" array
        @arrayconf = `/usr/local/bin/snmpwalk $node $community
.1.3.6.1.4.1.9.9.166.1.7.1.1.1`;
        #print"@arrayconf\n";
        #call external app snmpwalk
        #walk the CBWFQ policy mib
        #place result in "arraypol" array
        @arraypol = `/usr/local/bin/snmpwalk $node $community
.1.3.6.1.4.1.9.9.166.1.5.1.1.2`;
        #print "@arraypol\n";
        #step through "arrayconf" array and set each instance to the
        foreach $line (@arrayconf)
        {
                #replace the  ""new-line" character combination with a
"new-line character".
                #this removes the trailing double-apostrophe from the result
in the
                #"array-conf" array.
                $line =~ s/\"\n/\n/g;
                #replace double-apostrophe character with a period.
                #this removes the leading double-apostrophe from the result
in the
                #"array-conf" array.
                $line =~ s/\"/./g;
                #replace all spaces with a period.
                $line =~ s/ /./g;
                #print $line;
                #create a new array, "arrayconf1", with each child variable
initialized to the value
                #of the "$line value" variable split by the period.
                @arrayconf1 = split(/\./,$line);
                #print @arrayconf1;
                #set the variable of the 13th "arrayconf1" array child
variable to the "$name_cell"
                #variable.
                $name_cell = $arrayconf1[12];
                #print $name_cell;
                #remove the "new-line character"
                chomp $name_cell;
                #set the variable of the 10th "arrayconf1" array child
variable to the "$config_id1_cell"
                #variable.
                $config_id1_cell = $arrayconf1[9];
                #print "$config_id1_cell\n";
                #step through the "arraypol" array and set each instance to
the variable "$line"
 foreach $line (@arraypol)
                {
                        #replace all spaces with a period.
                        $line =~ s/ /./g;
                        #print "$line\n";
                        #create a new array, "arraypol1", with each child
variable initialized to the value
                        #of the "$line value" variable split by the period.
                        @arraypol1 = split(/\./,$line);
                        #print "@arraypol1\n";
                        #set the variable of the 10th "arraypol1" array
child variable to the "$pol_id_cell"
                        #variable.
                        $pol_id_cell = $arraypol1[9];
                        #print "$pol_id_cell\n";
                        #set the variable of the 11th "arraypol1" array
child variable to the "$obj_id_cell"
                        #variable.
                        $obj_id_cell = $arraypol1[10];
                        #print "$obj_id_cell\n";
                        #set the variable of the 14th "arraypol1" array
child variable to the "$conf_id2_cell"
                        #variable.
                        $config_id2_cell = $arraypol1[13];
                        #print "$config_id2_cell\n";
                        #compare the value of variables "$config_id1_cell"
and "$config_id2_cell".
                        if($config_id1_cell == $config_id2_cell)
                        {
                                #if the config_ids match then add the name
to the name array, the pol_id
                                #to the pol_id array and the obj_id to the
obj_id array.
                                @arrayname = $name_cell;
                                @arraypol3 = $pol_id_cell;
                                @arrayobj = $obj_id_cell;
                                #Step through the "@arrayname" array and set
each instance to the "$name_cell"
                                #variable
                                foreach $name_cell (@arrayname)
                                {
                                        #call external app snmpget and pass
the values of the polid and objid variables. place the
                                        #result in @array1stresult.
                                        @array1stresult =
`/usr/local/bin/snmpget $node $community
.1.3.6.1.4.1.9.9.166.1.15.1.1.9.$arraypol3[0].$arrayobj[0]`;
                                        #print @array1stresult;
                                        foreach $line (@array1stresult)
                                        {
                                                #replace all spaces with a
period.
                                                $line =~ s/ /./g;
                                                #create a new array,
"array2ndresult", with each child variable initiali
zed to the value
                                                #of the "$line" variable
split by the period.
                                                @array2ndresult =
split(/\./,$line);
 #print "@array2ndresult\n";
                                                $database =
"/usr/local/nmis/database/cb_report/$node.$name_cell.rrd";

                                                print FILE_db_index
"$node.$name_cell.rrd\n";
                                                if ( not -w $database)
                                                {
`/usr/local/rrdtool/bin/rrdtool create $database -s 300
DS:ifInOctets:COUNTER:900:0:2768000 RRA:AVERAGE:0.5:1:2304 RRA:A
VERAGE:0.5:6:1536 RRA:AVERAGE:0.5:24:2268 RRA:AVERAGE:0.5:288:1890
RRA:MAX:0.5:1:2304 RRA:MAX:0.5:6:1536 RRA:MAX:0.5:24:
2268 RRA:MAX:0.5:288:1890 RRA:MIN:0.5:1:2304 RRA:MIN:0.5:6:1536
RRA:MIN:0.5:24:2268 RRA:MIN:0.5:288:1890`;
                                                }
                                                #place the 14th variable of
"array2ndresult" into an rrd database called
 "$name_cell".rrd

#if($database == 'jhb-internet.jhbchhinterlocq.rrd')
#if($database =~ 'jhb-internet.*locq.rrd')
#       {
#               $bandwidth = ($array2ndresult[13] * 2);
#       }
#else
#       {
                $bandwidth = $array2ndresult[13];
#       }
#
#                                               RRDs::update
("$database","N:$bandwidth") unless ( $bandwidth == 0 );
                                                RRDs::update
("$database","N:$bandwidth");
                                        }
                                }
                        }
                }
        };
        };
        }
}
close (FILE_db_index);

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list