📄 nmiscbwfq.pl
字号:
#!/usr/bin/perl#Class-based weighted fair queue interrogation module.#This module maps class names to policy-id, object-id pairs and#does an SNMP get on the bytes transmitted OID.#written by Andy Brauer#initial release 07/05/2002#current release 10/05/2002#current version 0.51#Updated by Stiphane Monnier Nov2003# rrd display routines added to nmiscgi.pl# example crontab line for executing every 5 mins# move this script to the nmis bin directory.# !!! manually create the <database_root>/cb_report directory for reports and files !!!# 5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/nmis/bin/nmiscbwfq.pluse FindBin;use lib qw( /usr/local/rrdtool-1.0.33/lib/perl ../lib/perl );use lib "$FindBin::Bin/../lib";use RRDs;use NMIS;use func;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 @array3rdresult;my $A3rdresult;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 $serial;my $path_snmp = '/usr/local/bin';# Variables for command line mungingmy %nvp = getArguements(@ARGV); # See if customised config file required.my $conf;if ( $nvp{file} ne "" ) { $conf = $nvp{file}; }else { $conf = "nmis.conf"; }my $configfile = "$FindBin::Bin/../conf/$conf";if ( -f $configfile ) { loadConfiguration($configfile); }else { die "Can't access configuration file $configfile.\n"; } #open, read and close config file;open FILE_conf, $NMIS::config{'<nmis_conf>'} . "/mcq.csv" or die $!;@cb_config = <FILE_conf>;close FILE_conf;open (FILE_db_index, ">$NMIS::config{database_root}/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 = `$path_snmp/snmpwalk $node -c $community .1.3.6.1.4.1.9.9.166.1.7.1.1.1`; #call external app snmpwalk #walk the CBWFQ policy mib #place result in "arraypol" array @arraypol = `$path_snmp/snmpwalk $node -c $community .1.3.6.1.4.1.9.9.166.1.5.1.1.2`; #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; #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); #set the variable of the 13th "arrayconf1" array child variable to the "$name_cell" #variable. $name_cell = $arrayconf1[13]; #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]; #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; #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); #set the variable of the 10th "arraypol1" array child variable to the "$pol_id_cell" #variable. $pol_id_cell = $arraypol1[9]; #set the variable of the 11th "arraypol1" array child variable to the "$obj_id_cell" #variable. $obj_id_cell = $arraypol1[10]; #set the variable of the 14th "arraypol1" array child variable to the "$conf_id2_cell" #variable. $config_id2_cell = $arraypol1[13]; #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 # Find the ifDescri of the interface $A3rdresult = `$path_snmp/snmpget $node -c $community .1.3.6.1.4.1.9.9.166.1.1.1.1.4.$arraypol3[0]`; $A3rdresult =~ s/ /./g; @array3rdresult = split(/\./,$A3rdresult); chomp($array3rdresult[12]); $A3rdresult = `$path_snmp/snmpget $node -c $community ifDescr.$array3rdresult[12]`; $A3rdresult =~ s/ /./g; @array3rdresult = split(/\./,$A3rdresult); chomp($array3rdresult[4]); $array3rdresult[4] =~ s/\//-/g; $serial = $array3rdresult[4]; foreach $name_cell (@arrayname) { #call external app snmpget and pass the values of the polid and objid variables. place the #result in @array1stresult. @array1stresult = `$path_snmp/snmpget $node -c $community .1.3.6.1.4.1.9.9.166.1.15.1.1.9.$arraypol3[0].$arrayobj[0]`; foreach $line (@array1stresult) { #replace all spaces with a period. $line =~ s/ /./g; @array2ndresult = split(/\./,$line); #create a new array, "array2ndresult", with each child variable initialized to the value #of the "$line" variable split by the period. $database = "$NMIS::config{database_root}/cb_report/$serial.$node.$name_cell.rrd"; print FILE_db_index "$serial.$node.$name_cell.rrd\n"; if ( not -w $database) { `/usr/bin/rrdtool create $database DS:input:COUNTER:900:U:U RRA:AVERAGE:0.5:1:2304 RRA:AVERAGE:0.5:6:1536 RRA:AVERAGE:0.5:24:2268 RRA:AVERAGE:0.5:288:1890`; } #place the 14th variable of "array2ndresult" into an rrd database called "$name_cell".rrd RRDs::update ("$database","N:$array2ndresult[13]"); } } } } }; }; }}close (FILE_db_index);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -