Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Problem with set request. Net::SNMP module

by Sergeyk (Novice)
on Aug 05, 2013 at 04:29 UTC ( #1047852=perlquestion: print w/replies, xml ) Need Help??

Sergeyk has asked for the wisdom of the Perl Monks concerning the following question:

My script is supposed to do 'set' request table on the device for config backup
my @request; push(@request, ("$rand_value",INTEGER, +6)); push(@request, ("$rand_value",INTEGER, +1)); push(@request, ("$rand_value",OCTET_ST +RING,"$device_name")); push(@request, ("$rand_value",IPADDRES +S,'')); push(@request, ("$rand_value",OCTET_ST +RING,'user')); push(@request, ("$rand_value",OCTET_ST +RING,'password')); push(@request, ("$rand_value",INTEGER, +4)); my ($session, $error) = Net::SNMP->session( -hostname => $device_ip, -version => 'snmpv1', -community => $device_comunity, ); $result = $session->set_request(-varbindlist=>[@request]); if (!defined $result) { printf "ERROR: %s\n", $session->error(); $session->close(); exit 1; } $session->close();
but it does not work and the device displays a message in the log Aug 4 2013 21:08:33+03:00 device %%01SNMP/4/SNMP_SET(l)[0]:MIB node set. (SourceIP=, RequestId=376206003, ErrorStatus=7, ErrorIndex=7, hwCfgOperateRowStatus.2667=4) But request directly from the command line works
snmpset -v 1 -c private . +003 i 6 . i 1 . + s 'config.cfg' . a . + s 'user' . s 'password' . +. i 4
what am I doing wrong?

Replies are listed 'Best First'.
Re: Problem with set request. Net::SNMP module
by rjt (Curate) on Aug 05, 2013 at 10:44 UTC

    A few potential problems (Net::SNMP may take care of some of these for you):

    push(@request, ("$rand_value",INTEGER, +6)); # ^ -- Add a leading dot here

    You are missing the leading dot on your fully-qualified OID; the examples in Net::SNMP don't include it either, though, but it may be worth a try.

    You might also need a trailing .0 after $rand_value to specify the (scalar) index, unless you've accounted for that in $rand_value.

    An ErrorStatus of 7 normally corresponds to a WRONGTYPE error. My SNMP is a bit rusty, but I note you are setting up an INTEGER varbind but passing in '6'. Do you need to pack that to a 32-bit signed int? Try:

    push(@request, ($OID,INTEGER,pack('l>',6)));

    Finally, what does $session->error report? Is it the same as what you see in the log? What happens if you send separate set_request()s for each varbind—i.e., do all of them fail similarly, or is it a more specific problem?

    Sorry for the "multiple guess" answer, but it's been a while, and I have no environment capable of testing this. Hope it helps!

    use strict; use warnings; omitted for brevity.
      I found a problem. It is not associated with the module net::snmp. It is associated with the file name format in the query. Name must be in the following format: devicename.cfg
        Please I have a problem with devicename.cfg file, my script only works with only one command (example: hostname xxx), but when i want to send several commands (example: aaa localuser yyy) I get a error message, do you know how to do that?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1047852]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2020-11-27 21:24 GMT
Find Nodes?
    Voting Booth?

    No recent polls found