[mrtg] Re: Stats For Lucent PortMaster 4

Dave Mullender davem at hiway.co.uk
Mon Aug 9 14:03:25 MEST 1999


> We aquiring a Portmaster 4 and I am having trouble getting stats from
> this portmaster via mrtg.  I am using SuSE Linux 5.3 with mrtg 2.7.2   I
> tries pm3lines.pl on the portmaster, but I don't think you can used this
> script for this type of portmaster.   Any body got any suggetions....I
> could really use some help here.  From what I can see, the MIB structure
> is different on a pm4.

You can't use pm3lines it doesn't work, there is a modified version 
flying around which does work, here's a copy of the one we're using 
which is modified a little bit more (well hacked rather than modified 
methinks!), you would probably be better getting the original, but if 
you can't find it heres ours:-

#!/usr/bin/perl
# PM4Lines.pl 
# # 1999/02/22 # 1999/01/11 # 1998/08/04

# 
# Created by  carlos.cana- at eunet.pt with cfgmaker  from Tobias 
Oetiker 
# oetike- at ee.ethz.ch as skeleton 
# 
# returns: 
# #modems 
#
#isdn 
# sysName 
# sysUptime 
#
#
# if passed a second argument, then just shows totals of lines in 
use

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);
}


-----------
Dave Mullender
Hiway Communications Ltd
Tel: 01635 573320  Fax: 01635 573329

--
* To unsubscribe from the mrtg mailing list, send a message with the
  subject: unsubscribe to mrtg-request at list.ee.ethz.ch
* The mailing list archive is at http://www.ee.ethz.ch/~slist/mrtg


More information about the mrtg mailing list