(PM) FW: MRTG and NT

Mark Radabaugh (mark@amplex.net)
Tue, 21 Jul 1998 08:45:19 -0400

I keep getting requests for the NT MRTG config files...

This is the configuration that I use to monitor the number of modems in
use:

Note that this requires you to have PERL for NT and MRTG installed on your
system.

I call this line in a batch file every 5 minutes: perl.exe c:\mrtg\mrtg
mrtg.cfg

I am using Arcana Scheduler http://arcanadev.com/ to run the batch files.
It seems
like a decent program and the cost is fairly low.

The contents of mrtg.cfg is:

#
# Usage example on .cfg file:
#
WorkDir: d:\wwwroot
#change this to where you want the html files placed
#
Target[dial]: `perl c:\mrtg\PM3Lines.pl public@PM3-1`
#change this to where you put pm3lines.pl and to
#point to your PM-3 community
#
WithPeak[dial]: wym
#more options - all covered in MRTG docs.
#
Directory[dial]: data
#this is combined with the Workdir in the first
#line to determine where the data files will be
#placed - in my case d:\wwwroot\data\dial.html
#
#change the [dial] in all lines to be the name
#of the html file that you want the results in.
#
Options[dial]: growright, absolute, gauge, noinfo
#see the MRTG documentation for the options list
#
MaxBytes[dial]: 24
#set this for the number of modems in your machine
#
AbsMax[dial]: 24
#same here
#
Title[dial]: Woodville Internet : MODEMS/ISDN
Unscaled[dial]: dwmy
YLegend[dial]: Interfaces
Colours[dial]: GOLDENROD#D2A13B,BLUE1#0000ff,DARK
GREEN#006600,VIOLET#ff00ff
XSize[dial]: 340
YSize[dial]: 100
ShortLegend[dial]: if's
Legend1[dial]: Modems
Legend2[dial]: ISDN
Legend3[dial]: Maximal 5 Minute Modems
Legend4[dial]: Maximal 5 Minute ISDN
LegendI[dial]:   modems:
LegendO[dial]:   ISDN:
PageTop[dial]: <H1>Woodville Internet</H1>
<TABLE>
<TR><TD>System:</TD><TD>PM3-1 Terminal Server</TD></TR>
<TR><TD>Maintainer:</TD><TD>mark@woodville.net</TD><TD></TD></TR>
<TR><TD>Interface:</TD><TD>MODEMS/ISDN</TD></TR>
<TR><TD>IP:</TD><TD>Woodville Internet (209.57.124.14)</TD></TR>
<TR><TD>Max Interfaces:</TD>
<TD>24 Asyncs / 24 ISDN</TD></TR>
</TABLE>

and here is the PM3lines.pl file, you don't need to change anything in this
file:

#!/usr/bin/perl

# PM3Lines.pl
#

#
# Created by Carlos.Canau@EUnet.pt with cfgmaker from Tobias Oetiker
# <oetiker@ee.ethz.ch> as skeleton
#
# returns:
# #modems used
# #isdn lines used
# sysName
# sysUptime
#

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',
'PM3UP' => '1.3.6.1.4.1.307.3.2.1.1.1.13',
);

my($community,$router) = split /\@/, $ARGV[0];
die <<USAGE unless $community && $router;

USAGE: PM3Lines.pl 'community'\@'portmaster'

EXAMPLE: PM3Lines.pl public\@dial0

USAGE

my($sysName,$sysUptime,$interfaces) =
snmpget($router,$community,
'sysName', 'sysUptime', 'ifNumber');
my @PM3UP = snmpgettable($router,$community, 'PM3UP');

my($value, $modems) = (0,0);

while (scalar @PM3UP){
$value = shift @PM3UP;
if ($value) {
$modems++;
}
}

my($isdn) = ($interfaces - 1); # ethernet
$isdn -= 1; # D-channel ???
$isdn -= $modems;
if ($isdn < 0) {
$isdn = 0;
}

printf "$modems\n";
printf "$isdn\n";
printf "$sysUptime\n";
printf "$sysName\n";

exit(0);

sub
get{
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,@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);
}

That should do it. You may need to remove some of my comment lines from
the file.
You can see the results at http://www.woodville.net/data/dial.html if you
want.

I didn't write any of the code for this - All of it is in the MRTG
documentation and sample files.

Note that you will get warnings the first two times you run the program -
they are harmless.

Mark Radabaugh
mark@amplex.net

-
To unsubscribe, email 'majordomo@livingston.com' with
'unsubscribe portmaster-users' in the body of the message.
Searchable list archive: <URL:http://www.livingston.com/Tech/archive/>