[mrtg] Problem With Current pm4lines
Pyuesh Daya
pyueshd at na.co.za
Thu May 18 17:56:29 MEST 2000
Hi Everybody
Can someone please tell what is wrong with the script below, for
gathering modem & isdn stats from a PortMaster 4(Livingston)..The script
was work before we upgraded the ComOS on the PortMaster...Since then,
mrtg reports the modem usage as isdn usage and does not report
ISDN usage on the PortMaster....I got this PM4lines from this mailing
list sometime Back !! I am running ComOS 4.2
Can someone help !!
#!/usr/bin/perl
# PM4Lines.pl
# # 1999/02/22 # 1999/01/11 # 1998/08/04
use SNMP_Session;
use BER; use Socket; use strict;
%snmpget::OIDS = ( 'sysName' => '1.3.6.1.2.1.1.5.0',
'sysUptime' => '1.3.6.1.2.1.1.3.0',
'ifNumber' => '1.3.6.1.2.1.2.1.0',
'PM4UP' => '1.3.6.1.4.1.307.3.2.1.1.1.13',
'PM4ip' => '1.3.6.1.4.1.307.3.2.1.1.1.14',
);
my($community,$router) = split /\@/, $ARGV[0];
die <<FRED unless $community && $router;
USAGE: PM4Lines.pl 'community'\@'portmaster'
EXAMPLE: PM4Lines.pl public\@dial0
FRED
my($sysName,$sysUptime,$interfaces) =
snmpget($router,$community,
'sysName', 'sysUptime', 'ifNumber');
my @PM4UP = snmpgettable($router,$community, 'PM4UP');
my @PM4ip = snmpgettable($router,$community, 'PM4ip');
my($value, $modems, $ips) = (0,0,0);
my $modem0 = 0;
while (scalar @PM4UP){
$value = shift @PM4UP;
if ($value) {
if ($value ne "M0") {
$modems++;
} else {
$modem0 = 1;
}
}
}
$modems += $modem0;
while (scalar @PM4ip){
$value = shift @PM4ip;
if ($value ne "0.0.0.0") {
$ips++;
}
}
my($isdn) = $ips;
my($totcount)=0;
$isdn -= $modems;
if ($isdn < 0) {
$isdn = 0;
}
if ($ARGV[1]){ # CGA add to give total if 2nd arg given
$totcount=$isdn+$modems;
printf "$totcount\n$totcount\n"; printf "$sysUptime\n"; printf
"$sysName\n";
}
else {
printf "$modems\n";
printf "$isdn\n"; printf "$sysUptime\n"; printf "$sysName\n";
}
exit(0);
sub snmpget{
my($host,$community, @vars) = @_;
my(@enoid, $var,$response, $bindings, $binding, $value,
$inoid,$outoid,
$upoid,$oid, @retvals);
foreach $var (@vars) {
die "Unknown SNMP var $var\n"
unless $snmpget::OIDS{$var};
push @enoid, encode_oid((split /\./, $snmpget::OIDS{$var}));
}
srand();
my $session = SNMP_Session->open ($host ,
$community,
161);
if ($session->get_request_response(@enoid)) {
$response = $session->pdu_buffer;
($bindings) = $session->decode_get_response ($response);
$session->close ();
while ($bindings) {
($binding,$bindings) = decode_sequence ($bindings);
($oid,$value) = decode_by_template ($binding, "%O%@");
my $tempo = pretty_print($value);
$tempo=~s/\t/ /g;
$tempo=~s/\n/ /g;
$tempo=~s/^\s+//;
$tempo=~s/\s+$//;
push @retvals, $tempo;
}
return (@retvals);
} else {
die "No answer from $ARGV[0]. You may be using the wrong
community\n";
}
}
sub snmpgettable{
my($host,$community,$var) = @_;
my($next_oid,$enoid,$orig_oid,
$response, $bindings, $binding, $value, $inoid,$outoid,
$upoid,$oid, at table,$tempo);
die "Unknown SNMP var $var\n"
unless $snmpget::OIDS{$var};
$orig_oid = encode_oid(split /\./, $snmpget::OIDS{$var});
$enoid=$orig_oid;
srand();
my $session = SNMP_Session->open ($host ,
$community,
161);
for(;;) {
if ($session->getnext_request_response(($enoid))) {
$response = $session->pdu_buffer;
($bindings) = $session->decode_get_response ($response);
($binding,$bindings) = decode_sequence ($bindings);
($next_oid,$value) = decode_by_template ($binding, "%O%@");
# quit once we are outside the table
last unless BER::encoded_oid_prefix_p($orig_oid,$next_oid);
$tempo = pretty_print($value);
#print "$var: '$tempo'\n";
$tempo=~s/\t/ /g;
$tempo=~s/\n/ /g;
$tempo=~s/^\s+//;
$tempo=~s/\s+$//;
push @table, $tempo;
} else {
die "No answer from $ARGV[0]\n";
}
$enoid=$next_oid;
}
$session->close ();
return (@table);
}
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
More information about the mrtg
mailing list