| 1 |
#!/usr/local/bin/perl5 |
| 2 |
# -*- mode: Perl -*- |
| 3 |
################################################################## |
| 4 |
# Config file creator |
| 5 |
################################################################## |
| 6 |
# Created by Laurie Gellatly <[email protected]> |
| 7 |
# based on mrtg cfgmaker by Tobias Oetiker <[email protected]> |
| 8 |
# this produces a config file for one router, by pulling info |
| 9 |
# off the router via snmp and then writing files ready for |
| 10 |
# snmpCollect to use (via xnmcollect) and later ovlg calls |
| 11 |
################################################################# |
| 12 |
# |
| 13 |
# Distributed under the GNU copyleft |
| 14 |
# |
| 15 |
# $Id: cfgmakerov,v 1.1.1.1 2002/02/26 10:16:36 oetiker Exp $ |
| 16 |
# |
| 17 |
use SNMP_Session "0.58"; |
| 18 |
use BER "0.57"; |
| 19 |
use Socket; |
| 20 |
use strict; |
| 21 |
use vars '$DEBUG'; |
| 22 |
my $DEBUG = 0; |
| 23 |
my $webdir = "/var/opt/ns-fasttrack/docs/mrtg/"; |
| 24 |
|
| 25 |
%snmpget::OIDS = ( 'sysDescr' => '1.3.6.1.2.1.1.1.0', |
| 26 |
'sysContact' => '1.3.6.1.2.1.1.4.0', |
| 27 |
'sysName' => '1.3.6.1.2.1.1.5.0', |
| 28 |
'sysLocation' => '1.3.6.1.2.1.1.6.0', |
| 29 |
'sysUptime' => '1.3.6.1.2.1.1.3.0', |
| 30 |
'ifNumber' => '1.3.6.1.2.1.2.1.0', |
| 31 |
################################### |
| 32 |
# add the ifNumber .... |
| 33 |
'ifDescr' => '1.3.6.1.2.1.2.2.1.2', |
| 34 |
'ifType' => '1.3.6.1.2.1.2.2.1.3', |
| 35 |
'ifIndex' => '1.3.6.1.2.1.2.2.1.1', |
| 36 |
'ifSpeed' => '1.3.6.1.2.1.2.2.1.5', |
| 37 |
'ifOperStatus' => '1.3.6.1.2.1.2.2.1.8', |
| 38 |
'ifAdminStatus' => '1.3.6.1.2.1.2.2.1.7', |
| 39 |
# up 1, down 2, testing 3 |
| 40 |
'ipAdEntAddr' => '1.3.6.1.2.1.4.20.1.1', |
| 41 |
'ipAdEntIfIndex' => '1.3.6.1.2.1.4.20.1.2', |
| 42 |
'sysObjectID' => '1.3.6.1.2.1.1.2.0', |
| 43 |
'CiscolocIfDescr' => '1.3.6.1.4.1.9.2.2.1.1.28', |
| 44 |
'ifAlias' => '1.3.6.1.2.1.31.1.1.1.18', |
| 45 |
'ifName' => '1.3.6.1.2.1.31.1.1.1.1' |
| 46 |
); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
sub main { |
| 52 |
|
| 53 |
|
| 54 |
my(%ifType_d)=('1'=>'Other', |
| 55 |
'2'=>'regular1822', |
| 56 |
'3'=>'hdh1822', |
| 57 |
'4'=>'ddnX25', |
| 58 |
'5'=>'rfc877x25', |
| 59 |
'6'=>'ethernetCsmacd', |
| 60 |
'7'=>'iso88023Csmacd', |
| 61 |
'8'=>'iso88024TokenBus', |
| 62 |
'9'=>'iso88025TokenRing', |
| 63 |
'10'=>'iso88026Man', |
| 64 |
'11'=>'starLan', |
| 65 |
'12'=>'proteon10Mbit', |
| 66 |
'13'=>'proteon80Mbit', |
| 67 |
'14'=>'hyperchannel', |
| 68 |
'15'=>'fddi', |
| 69 |
'16'=>'lapb', |
| 70 |
'17'=>'sdlc', |
| 71 |
'18'=>'ds1', |
| 72 |
'19'=>'e1', |
| 73 |
'20'=>'basicISDN', |
| 74 |
'21'=>'primaryISDN', |
| 75 |
'22'=>'propPointToPointSerial', |
| 76 |
'23'=>'ppp', |
| 77 |
'24'=>'softwareLoopback', |
| 78 |
'25'=>'eon', |
| 79 |
'26'=>'ethernet-3Mbit', |
| 80 |
'27'=>'nsip', |
| 81 |
'28'=>'slip', |
| 82 |
'29'=>'ultra', |
| 83 |
'30'=>'ds3', |
| 84 |
'31'=>'sip', |
| 85 |
'32'=>'frame-relay', |
| 86 |
'33'=>'rs232', |
| 87 |
'34'=>'para', |
| 88 |
'35'=>'arcnet', |
| 89 |
'36'=>'arcnetPlus', |
| 90 |
'37'=>'atm', |
| 91 |
'38'=>'miox25', |
| 92 |
'39'=>'sonet', |
| 93 |
'40'=>'x25ple', |
| 94 |
'41'=>'iso88022llc', |
| 95 |
'42'=>'localTalk', |
| 96 |
'43'=>'smdsDxi', |
| 97 |
'44'=>'frameRelayService', |
| 98 |
'45'=>'v35', |
| 99 |
'46'=>'hssi', |
| 100 |
'47'=>'hippi', |
| 101 |
'48'=>'modem', |
| 102 |
'49'=>'aal5', |
| 103 |
'50'=>'sonetPath', |
| 104 |
'51'=>'sonetVT', |
| 105 |
'52'=>'smdsIcip', |
| 106 |
'53'=>'propVirtual', |
| 107 |
'54'=>'propMultiplexor', |
| 108 |
'55'=>'100BaseVG' |
| 109 |
); |
| 110 |
|
| 111 |
my($vendor)=0; |
| 112 |
|
| 113 |
my($router) = $ARGV[0]; |
| 114 |
die <<USAGE unless $router; |
| 115 |
|
| 116 |
USAGE: cfgmakerov 'router' |
| 117 |
|
| 118 |
|
| 119 |
EXAMPLE: cfgmakerov ezwf7.ethz.ch >>mrtg.cfg |
| 120 |
|
| 121 |
|
| 122 |
USAGE |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
my($sysDescr,$sysContact,$sysName,$sysLocation,$ifNumber,$sysObjectID) = |
| 127 |
snmpget($router, |
| 128 |
'sysDescr','sysContact','sysName', 'sysLocation', 'ifNumber', 'sysObjectID'); |
| 129 |
|
| 130 |
### The next three lines can be deleted once Someone gives this box a name |
| 131 |
if ($router eq '10.26.254.1') { |
| 132 |
$sysName = 'nrgiga'; |
| 133 |
} |
| 134 |
if ($sysName eq "") { |
| 135 |
$sysName = $router; |
| 136 |
} |
| 137 |
my($sysNameL) = $sysName; |
| 138 |
$sysNameL =~ tr/[A-Z]/[a-z]/; |
| 139 |
|
| 140 |
$sysDescr =~ s/\r/<BR>/g; # Change returns to <BR> |
| 141 |
my($ciscobox) = ($sysObjectID =~ /cisco/); |
| 142 |
my($portmaster) = ($sysObjectID =~ /livingston/); |
| 143 |
$vendor = ($ciscobox || $portmaster) ; |
| 144 |
my($ifInErrors) = '1.3.6.1.2.1.2.2.1.14'; |
| 145 |
my($ifOutErrors) = '1.3.6.1.2.1.2.2.1.20'; |
| 146 |
|
| 147 |
### Create the directory if it does not exist |
| 148 |
|
| 149 |
mkdir("$webdir$sysNameL",0777); |
| 150 |
|
| 151 |
print <<ECHO; |
| 152 |
|
| 153 |
WorkDir: $webdir$sysNameL |
| 154 |
IconDir: ../ |
| 155 |
###################################################################### |
| 156 |
# Description: $sysDescr |
| 157 |
# Contact: $sysContact |
| 158 |
# System Name: $sysName |
| 159 |
# Location: $sysLocation |
| 160 |
#..................................................................... |
| 161 |
ECHO |
| 162 |
if ( $ciscobox ) { |
| 163 |
print <<ECHO; |
| 164 |
# Router CPU load % |
| 165 |
Target[$sysNameL.cpu]: `perl ovcvtfile $router 0 2` |
| 166 |
MaxBytes[$sysNameL.cpu]: 100 |
| 167 |
Title[$sysNameL.cpu]: CPU LOAD |
| 168 |
PageTop[$sysNameL.cpu]: <H1>CPU Load %</H1> |
| 169 |
ShortLegend[$sysNameL.cpu]: % |
| 170 |
XSize[$sysNameL.cpu]: 380 |
| 171 |
YSize[$sysNameL.cpu]: 100 |
| 172 |
YLegend[$sysNameL.cpu]: CPU Utilization |
| 173 |
Legend1[$sysNameL.cpu]: CPU Utilization in % (Load) |
| 174 |
Legend2[$sysNameL.cpu]: CPU Utilization in % (Load) |
| 175 |
Legend3[$sysNameL.cpu]: |
| 176 |
Legend4[$sysNameL.cpu]: |
| 177 |
LegendI[$sysNameL.cpu]: |
| 178 |
LegendO[$sysNameL.cpu]: Usage: |
| 179 |
Options[$sysNameL.cpu]: growright, gauge |
| 180 |
#--------------------------------------------------------------- |
| 181 |
ECHO |
| 182 |
} |
| 183 |
|
| 184 |
my @ipadent = snmpgettable($router, 'ipAdEntAddr'); |
| 185 |
print STDERR "Got Addresses\n" if $DEBUG; |
| 186 |
my @ipadentif = snmpgettable($router, 'ipAdEntIfIndex'); |
| 187 |
print STDERR "Got IfTable\n" if $DEBUG; |
| 188 |
|
| 189 |
my(%ipaddr, %iphost,$index); |
| 190 |
while (scalar @ipadentif){ |
| 191 |
$index = shift @ipadentif; |
| 192 |
$ipaddr{$index} = shift @ipadent; |
| 193 |
$iphost{$index} = |
| 194 |
gethostbyaddr(pack('C4',split(/\./,$ipaddr{$index})), AF_INET); |
| 195 |
if ($iphost{$index} eq ''){ |
| 196 |
$iphost{$index} = $ipaddr{$index}; |
| 197 |
} |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
my(@ifdescr) = snmpgettable($router, 'ifDescr'); |
| 202 |
print STDERR "Got IfDescr\n" if $DEBUG; |
| 203 |
my(@iftype) = snmpgettable($router, 'ifType'); |
| 204 |
print STDERR "Got IfType\n" if $DEBUG; |
| 205 |
my(@ifspeed) = snmpgettable($router, 'ifSpeed'); |
| 206 |
print STDERR "Got IfSpeed\n" if $DEBUG; |
| 207 |
my(@ifadminstatus) = snmpgettable($router, 'ifAdminStatus'); |
| 208 |
print STDERR "Got IfStatus\n" if $DEBUG; |
| 209 |
my(@ifoperstatus) = snmpgettable($router, 'ifOperStatus'); |
| 210 |
print STDERR "Got IfOperStatus\n" if $DEBUG; |
| 211 |
my(@ifindex) = snmpgettable($router, 'ifIndex'); |
| 212 |
print STDERR "Got IfIndex\n" if $DEBUG; |
| 213 |
my(@ifname) = snmpgettable($router, 'ifName'); |
| 214 |
print STDERR "Got IfName\n" if $DEBUG; |
| 215 |
|
| 216 |
my(%sifdesc,%siftype,%sifspeed,%sifadminstatus,%sifoperstatus,%sciscodescr,%sifname); |
| 217 |
|
| 218 |
### May need the cisco IOS version number so we know which oid to use |
| 219 |
### to get the cisco description. |
| 220 |
### |
| 221 |
### - mjd 2/5/98 (Mike Diehn) ([email protected]) |
| 222 |
### |
| 223 |
my ($cisco_ver, $cisco_descr_oid, @ciscodescr); |
| 224 |
if ( $ciscobox ) { |
| 225 |
($cisco_ver) = ($sysDescr =~ /Version\s+([\d.]+)/); |
| 226 |
$cisco_descr_oid = ($cisco_ver ge "11.3") ? "ifAlias" : "CiscolocIfDescr"; |
| 227 |
} |
| 228 |
|
| 229 |
while (scalar @ifindex) { |
| 230 |
|
| 231 |
# as these arrays get filled from the bottom, |
| 232 |
# we need to empty them from the botom as well ... |
| 233 |
# fifo |
| 234 |
|
| 235 |
$index = shift @ifindex; |
| 236 |
$sifdesc{$index} = shift @ifdescr; |
| 237 |
$sifname{$index} = shift @ifname; |
| 238 |
$siftype{$index} = shift @iftype; |
| 239 |
$sifspeed{$index} = shift @ifspeed; |
| 240 |
$sifadminstatus{$index} = shift @ifadminstatus; |
| 241 |
$sifoperstatus{$index} = shift @ifoperstatus; |
| 242 |
|
| 243 |
if ($portmaster) { |
| 244 |
# Trying to extract extra info livingston |
| 245 |
# We can only approximate speeds |
| 246 |
# |
| 247 |
# so we think that ppp can do 76800 bit/s, and slip 38400. |
| 248 |
# (actualy, slip is a bit faster, but usualy users with newer modems |
| 249 |
# use ppp). Alternatively, you can set async speed to 115200 or |
| 250 |
# 230400 (the maximum speed supported by portmaster). |
| 251 |
# |
| 252 |
# But if the interface is ptpW (sync), max speed is 128000 |
| 253 |
# change it to your needs. On various Portmasters there are |
| 254 |
# various numbers of sync interfaces, so modify it. |
| 255 |
# |
| 256 |
# The most commonly used PM-2ER has only one sync. |
| 257 |
# |
| 258 |
# Paul Makeev ([email protected]) |
| 259 |
# |
| 260 |
|
| 261 |
if ($siftype{$index} eq 'ppp') { |
| 262 |
if ($sifdesc{$index} eq 'ptpW1') { |
| 263 |
$sifspeed{$index} = 128000; |
| 264 |
} else { |
| 265 |
$sifspeed{$index} = 76800; |
| 266 |
} |
| 267 |
} elsif ($siftype{$index} eq 'slip') { |
| 268 |
$sifspeed{$index} = 38400; |
| 269 |
} elsif ($siftype{$index} eq 'ethernetCsmacd') { |
| 270 |
$sifspeed{$index} = 10000000; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
### Move this section south so we know what type of |
| 275 |
### circuit we're looking at before we retrieve |
| 276 |
### the cisco interface alias. |
| 277 |
### |
| 278 |
### This whole cicso thing should be re-written, but since |
| 279 |
### this script doesn't need to run quickly... |
| 280 |
### |
| 281 |
### - mjd 2/5/98 |
| 282 |
### |
| 283 |
# Get the user configurable interface description entered in the config |
| 284 |
# if it's a cisco-box |
| 285 |
# |
| 286 |
if ($ciscobox) { |
| 287 |
|
| 288 |
my ($enoid, @descr); |
| 289 |
|
| 290 |
$enoid = $snmpget::OIDS{"$cisco_descr_oid"} . "." . $index; |
| 291 |
|
| 292 |
if ( $cisco_ver ge "11.2" or $siftype{$index} ne 'frame-relay' ) { |
| 293 |
|
| 294 |
### This is either not a frame-relay sub-interface or |
| 295 |
### this router is running IOS 11.2+ and interface |
| 296 |
### type won't matter. In either of these cases, it's |
| 297 |
### ok to try getting the ifAlias or ciscoLocIfDesc. |
| 298 |
### |
| 299 |
@descr = snmpget($router, $enoid); |
| 300 |
|
| 301 |
} else { |
| 302 |
|
| 303 |
### This is a frame-relay sub-interface *and* the router |
| 304 |
### is running an IOS older than 11.2. Therefore, we can |
| 305 |
### get neither ifAlias nor ciscoLocIfDesc. Do something |
| 306 |
### useful. |
| 307 |
### |
| 308 |
@descr = ("Cisco PVCs descriptions require IOS 11.2+."); |
| 309 |
|
| 310 |
} # end if else |
| 311 |
|
| 312 |
### Put whatever I got into the array we'll use later to append the result |
| 313 |
### of this operation onto the results from the ifDescr fetch. |
| 314 |
### |
| 315 |
push @ciscodescr, shift @descr; |
| 316 |
|
| 317 |
} # end if ($ciscobox) |
| 318 |
|
| 319 |
# especially since cisco does not return a if |
| 320 |
# descr for each interface it has ... |
| 321 |
## JB 2/8/97 - sometimes IOS inserts E1 controllers in the standard-MIB |
| 322 |
## interface table, but not in the local interface table. This puts the |
| 323 |
## local interface description table out-of-sync. the following |
| 324 |
## modification skips over E1 cards as interfaces. |
| 325 |
# |
| 326 |
### I suspect that the mod I made above, to use the ifAlias |
| 327 |
### oid if possible, may cause problems here. If it seems |
| 328 |
### that your descriptions are out of sync, try commenting |
| 329 |
### out the "if ( condition )" and it's closing right brace |
| 330 |
### so that the "shift @ciscodescr" get executed for *all* |
| 331 |
### iterations of this loop. |
| 332 |
### |
| 333 |
### - mjd 2/5/95 |
| 334 |
### |
| 335 |
if ($ciscobox && $siftype{$index} ne 'ds1') { |
| 336 |
$sciscodescr{$index} = "<BR>" . (shift @ciscodescr) if @ciscodescr; |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
foreach $index ( sort { $a <=> $b } keys %sifdesc) { |
| 341 |
my $c; |
| 342 |
my $speed = int($sifspeed{$index} / 8); # bits to byte |
| 343 |
# LJG Change to report in Bits |
| 344 |
# my $speed_str=&fmi($speed); |
| 345 |
my $speed_str=&fmi($sifspeed{$index}); |
| 346 |
my $name="$sysNameL.$index"; |
| 347 |
my $namerr="$sysNameL.$index.err"; |
| 348 |
|
| 349 |
if (($sifadminstatus{$index} ne "up") |
| 350 |
# this check added by Josh - don't query E1-stack controllers |
| 351 |
|| ($siftype{$index} eq 'ds1') |
| 352 |
|| ($siftype{$index} eq 'softwareLoopback') |
| 353 |
|| ($speed == 0 ) |
| 354 |
# LJG Change to report all in Bits |
| 355 |
# || ($speed > 400 * 10**6) #speeds of 400 MByte/s are not realistic |
| 356 |
|| ($speed > 3200 * 10**6) #speeds of 400 MByte/s are not realistic |
| 357 |
|| ($sifoperstatus{$index} eq 'down') |
| 358 |
|| (($sifdesc{$index}=~ /Dialer/) && ($ciscobox))) { |
| 359 |
print <<ECHO; |
| 360 |
######## |
| 361 |
######## This Interface is one of the following |
| 362 |
######## - administratively not UP |
| 363 |
######## - it is in test mode |
| 364 |
######## - it is a softwareLoopback interface |
| 365 |
######## - has a unrealistic speed setting |
| 366 |
######## It is commented out for this reason. |
| 367 |
######## |
| 368 |
ECHO |
| 369 |
$c="# "; |
| 370 |
}else { |
| 371 |
$c = ''; |
| 372 |
} |
| 373 |
|
| 374 |
print <<ECHO; |
| 375 |
${c} |
| 376 |
${c}Target[$name]: `perl ovcvtfile $router $index 1` |
| 377 |
${c}MaxBytes[$name]: $speed |
| 378 |
${c}Title[$name]: $sysName ($iphost{$index}): $sifdesc{$index} $sifname{$index} |
| 379 |
${c}Options[$name]: growright, gauge, bits |
| 380 |
${c}PageTop[$name]: <H1>Traffic Analysis for $sifdesc{$index} |
| 381 |
${c} $sciscodescr{$index}</H1> |
| 382 |
${c} <TABLE> |
| 383 |
${c} <TR><TD>System:</TD><TD>$sysName in $sysLocation</TD></TR> |
| 384 |
${c} <TR><TD>Maintainer:</TD><TD>$sysContact</TD></TR> |
| 385 |
${c} <TR><TD>Interface:</TD><TD>$sifdesc{$index} ($index - $sifname{$index})</TD></TR> |
| 386 |
${c} <TR><TD>IP:</TD><TD>$iphost{$index} ($ipaddr{$index})</TD></TR> |
| 387 |
${c} <TR><TD>Max Speed:</TD> |
| 388 |
${c} <TD>$speed_str ($siftype{$index})</TD></TR> |
| 389 |
${c} </TABLE> |
| 390 |
${c} |
| 391 |
#--------------------------------------------------------------- |
| 392 |
|
| 393 |
# In and Out Error Counts |
| 394 |
${c} |
| 395 |
${c}Target[$namerr]: `perl ovcvtfile $router $index 0` |
| 396 |
${c}MaxBytes[$namerr]: 2147483600 |
| 397 |
${c}Title[$namerr]: $sysName ($iphost{$index}): $sifdesc{$index} $sifname{$index} I/O Errors |
| 398 |
${c}Options[$namerr]: growright, gauge |
| 399 |
${c}PageTop[$namerr]: <H1>I/O Error Analysis for $sifdesc{$index} |
| 400 |
${c} $sciscodescr{$index}</H1> |
| 401 |
${c}YLegend[$namerr]: Errors/Period |
| 402 |
${c}Legend1[$namerr]: Inward Errors |
| 403 |
${c}Legend2[$namerr]: Outward Errors |
| 404 |
${c}Legend3[$namerr]: |
| 405 |
${c}Legend4[$namerr]: |
| 406 |
${c}LegendI[$namerr]: In : |
| 407 |
${c}LegendO[$namerr]: Out : |
| 408 |
${c} |
| 409 |
#--------------------------------------------------------------- |
| 410 |
|
| 411 |
ECHO |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
main; |
| 416 |
exit(0); |
| 417 |
|
| 418 |
sub snmpget{ |
| 419 |
my($host,@vars) = @_; |
| 420 |
my(@enoid, $var,$response, $bindings, $binding, $value, $inoid,$outoid, |
| 421 |
$upoid,$oid,@retvals,$t1,$t2,@resp,$tempo); |
| 422 |
my($hackcisco); |
| 423 |
foreach $var (@vars) { |
| 424 |
die "Unknown SNMP var $var\n" |
| 425 |
unless $snmpget::OIDS{$var} || $var =~ /^\d+[\.\d+]*\.\d+$/; |
| 426 |
if ($var =~ /^\d+[\.\d+]*\.\d+/) { |
| 427 |
$value = $value.$var." "; |
| 428 |
$hackcisco = 1; |
| 429 |
} else { |
| 430 |
$value = $value.$snmpget::OIDS{$var}." "; |
| 431 |
$hackcisco = 0; |
| 432 |
} |
| 433 |
} |
| 434 |
open(SNMPG, "snmpget $host $value |"); |
| 435 |
# print STDERR $value; |
| 436 |
while ($tempo =<SNMPG>){ |
| 437 |
# print STDERR $tempo; |
| 438 |
($t1, $t2, $tempo ) = split /:/ , $tempo, 3; |
| 439 |
if (!$tempo){ |
| 440 |
if ($t2){ |
| 441 |
$t1 = $t1 .":".$t2; |
| 442 |
} |
| 443 |
$tempo = pop(@retvals)." ".$t1 ; |
| 444 |
} |
| 445 |
$tempo=~s/\t/ /g; |
| 446 |
$tempo=~s/\n/ /g; |
| 447 |
$tempo=~s/^\s+//; |
| 448 |
$tempo=~s/\s+$//; |
| 449 |
push @retvals, $tempo; |
| 450 |
} |
| 451 |
# print STDERR @retvals; |
| 452 |
close (SNMPG); |
| 453 |
return (@retvals); |
| 454 |
} |
| 455 |
|
| 456 |
sub snmpgettable{ |
| 457 |
my($host,$var) = @_; |
| 458 |
my($next_oid,$enoid,$orig_oid, |
| 459 |
$response, $bindings, $binding, $t1, $t2,$outoid, |
| 460 |
$upoid,$oid,@table,$tempo); |
| 461 |
die "Unknown SNMP var $var\n" |
| 462 |
unless $snmpget::OIDS{$var}; |
| 463 |
|
| 464 |
$orig_oid = $snmpget::OIDS{$var}." "; |
| 465 |
$enoid=$orig_oid; |
| 466 |
open(SNMPG, "snmpwalk $host $orig_oid |"); |
| 467 |
# print STDERR $orig_oid; |
| 468 |
while ($tempo =<SNMPG>){ |
| 469 |
# print STDERR $tempo; |
| 470 |
($t1, $t2, $tempo ) = split /:/ , $tempo ,3; |
| 471 |
if (!$tempo){ |
| 472 |
if ($t2){ |
| 473 |
$t1 = $t1 .":".$t2; |
| 474 |
} |
| 475 |
$tempo = pop(@table)." ".$t1 ; |
| 476 |
} |
| 477 |
$tempo=~s/\t/ /g; |
| 478 |
$tempo=~s/\n/ /g; |
| 479 |
$tempo=~s/^\s+//; |
| 480 |
$tempo=~s/\s+$//; |
| 481 |
push @table, $tempo; |
| 482 |
|
| 483 |
} |
| 484 |
close (SNMPG); |
| 485 |
return (@table); |
| 486 |
} |
| 487 |
|
| 488 |
sub fmi { |
| 489 |
my($number) = $_[0]; |
| 490 |
my(@short); |
| 491 |
# LJG Change to report in Bits |
| 492 |
# @short = ("Bytes/s","kBytes/s","MBytes/s","GBytes/s"); |
| 493 |
@short = ("Bits/s","kBits/s","MBits/s","GBits/s"); |
| 494 |
my $digits=length("".$number); |
| 495 |
my $divm=0; |
| 496 |
while ($digits-$divm*3 > 3) { $divm++; } |
| 497 |
my $divnum = $number/10**($divm*3); |
| 498 |
return sprintf("%1.1f %s",$divnum,$short[$divm]); |
| 499 |
} |
| 500 |
|
| 501 |
|