Hi I am using the following script to initiate an SAA session with a cisco router, I am using the snmp module from http://www.switch.ch/misc/leinen/snmp/perl/ I get the same problem with the standard SNMP module.

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>


In reply to SNMP String format by mugster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.