michaelW has asked for the wisdom of the Perl Monks concerning the following question:
Excerpt: When the object decodes the GetResponse-PDU that is returned in response to a SNMP message, certain values are translated into a more "human readable" form. By default the following translations occur: * OCTET STRINGs and Opaques containing non-printable ASCII characters are converted into a hexadecimal representation prefixed with "0x". NOTE: The following ASCII control characters are considered to be printable by the module: NUL(0x00), HT(0x09), LF(0x0A), FF(0x0C), and CR(0x0D). * TimeTicks integer values are converted to a time format. * NULL values return the string "NULL" instead of an empty string. * noSuchObject exception values return the string "noSuchObject" instead of an empty string. If translation is not enabled, the SNMP error-status field is set to 128 which is equal to the exported definition NOSUCHOBJECT (see "EXPORTS"). * noSuchInstance exception values return the string "noSuchInstance" instead of an empty string. If translation is not enabled, the SNMP error-status field is set to 129 which is equal to the exported definition NOSUCHINSTANCE (see "EXPORTS"). * endOfMibView exception values return the string "endOfMibView" instead of an empty string. If translation is not enabled, the SNMP error-status field is set to 130 which is equal to the exported definition ENDOFMIBVIEW (see "EXPORTS"). * Counter64, Counter, Gauge, and TimeTick values that have been incorrectly encoded as signed negative values are returned as unsigned values.$MAIN::a = 1; $stuff='c:\scripts\ipListPart3.txt'; open STUFF, $stuff or die "Cannot open $stuff for read :$!"; while (<STUFF>) { chomp $_; $MAIN::host = $_; my $out="c:/scripts/out.txt"; open OUT, ">>$out" or die "Cannot open $out for write :$!"; printf OUT ("\n$MAIN::host\n"); $MAIN::counter = 0; $stuff1='c:\scripts\mibs1a.txt'; open STUFF1, $stuff1 or die "Cannot open $stuff1 for read :$!"; while (<STUFF1>){ chomp $_; $MAIN::oid = $_; my $out="c:/scripts/out.txt"; open OUT, ">>$out" or die "Cannot open $out for write :$!"; @MAIN::names = ("adminStatus","operStatus","autoNeg","adminSpeed","adm +inDuplex" ,"operSpeed","operDuplex","taggingType","vids","discardTagged", "discardUntagged","defaultVid","stg1Enable","stg1State","stg1Faststart +"); printf OUT ("$MAIN::names[$MAIN::counter]\t"); $MAIN::counter++; for ($MAIN::a = 1; $MAIN::a <= 48; $MAIN::a++){ &subOne; } sub subOne { $_ = $MAIN::oid; $_ =~ s/port/$MAIN::a/; use Net::SNMP; my ($session, $error) = Net::SNMP->session( -hostname => shift || $MAIN::host, -community => shift || 'public', -port => shift || 161, -timeout => shift || 5 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } my $DesignatedRoot = $_; my $result = $session->get_request( -varbindlist => [$DesignatedRoot] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } my $out="c:/scripts/out.txt"; open OUT, ">>$out" or die "Cannot open $out for write :$!"; $a = ($result->{$DesignatedRoot}); $a =~ s/\n/0x000a/; printf OUT $a; #printf OUT ($result->{$DesignatedRoot}); printf OUT ("\t"); if ($MAIN::a == 48) { printf OUT ("\n"); } $session->close; } } } exit 0;
2006-07-31 Retitled by Corion, as per Monastery guidelines
Original title: 'SNMP'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Disable the printing of printable and control characters with Net::SNMP (was: SNMP)
by rodion (Chaplain) on Jul 31, 2006 at 12:31 UTC | |
by michaelW (Initiate) on Aug 03, 2006 at 16:06 UTC |