mugster has asked for the wisdom of the Perl Monks concerning the following question:
The problem is the format of the string value '9A 20 FF 09' is being reported as being invalid by the router.
If I do an snmpget and set using the HPOV tools and the values above it works fine.
Any help is greatly appreciated.
(my head now hurts from banging it against the wall)
#!/usr/bin/perl BEGIN { push @INC, '/opt/home/uknops/saa/SNMP_Session-0.94/lib'; } require 5.002; use strict; use SNMP_Session; use BER; my $host = "154.32.255.25"; my $community = "PSI-EU-RW"; my %OIDS; my @varbind = ('1.3.6.1.4.1.9.9.42.1.2.1.1.9.1', 'int', 4, '1.3.6.1.4.1.9.9.42.1.2.1.1.4.1', 'int', 1, '1.3.6.1.4.1.9.9.42.1.2.2.1.1.1', 'int', 2, '1.3.6.1.4.1.9.9.42.1.2.2.1.2.1', 'string', '9A 20 FF 09', '1.3.6.1.4.1.9.9.42.1.2.2.1.6.1', 'string', '9A 20 FF 19', '1.3.6.1.4.1.9.9.42.1.2.5.1.2.1', 'int', 1, '1.3.6.1.4.1.9.9.42.1.2.5.1.1.1', 'int', 2147483647); my ($response) = &snmpset($host, $community, @varbind); if ($response) { print "Response: $response\n"; } else { print "$host did not respond to SNMP query\n"; } exit 0; sub snmpset { my($host,$community,@varList) = @_; my(@enoid, $response, $bindings, $binding, $inoid,$outoid, $upoid,$oid,@retvals); my ($type,$value); while (@varList) { $oid = toOID(shift @varList); $type = shift @varList; $value = shift @varList; ($type eq 'string') && do { $value = encode_string($value); push @enoid, [$oid,$value]; next; }; ($type eq 'int') && do { $value = encode_int($value); push @enoid, [$oid,$value]; next; }; die "Unknown SNMP type: $type"; } srand(); my $session = SNMP_Session->open ($host , $community, 161); if ($session->set_request_response(@enoid)) { $response = $session->pdu_buffer; ($bindings) = $session->decode_get_response ($response +); $session->close (); while ($bindings) { ($binding,$bindings) = decode_sequence ($bindi +ngs); ($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 { return (-1,-1); } } sub toOID { my $var = shift; if ($var =~ /^([a-z]+[^\.]*)/i) { my $oid = $OIDS{$1}; if ($oid) { $var =~ s/$1/$oid/; } else { die "Unknown SNMP var $var\n" } } encode_oid((split /\./, $var)); }
update (broquaint): reformatted code + added <readmore>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SNMP String format
by grinder (Bishop) on Mar 11, 2003 at 13:41 UTC | |
|
Re: SNMP String format
by traveler (Parson) on Mar 11, 2003 at 15:42 UTC | |
|
Re: SNMP String format
by zengargoyle (Deacon) on Mar 11, 2003 at 19:30 UTC | |
by traveler (Parson) on Mar 11, 2003 at 21:57 UTC | |
by zengargoyle (Deacon) on Mar 11, 2003 at 22:51 UTC | |
by traveler (Parson) on Mar 11, 2003 at 23:00 UTC | |
by zengargoyle (Deacon) on Mar 11, 2003 at 23:23 UTC |