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

hi all i new to perl and snmp so this prob only a simple thing but itrying to set 4 different values in the mib but all that is ever set is the sysname value could somebody please help as this is starting to drive me even m ore nuts than i already am.!
use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use Socket; use Net::SNMP; #Net::snmp 5.1 my $snmp_version = '2c'; my $snmp_port = 161; my $host = ***.***.***.*; #passed from form my $community = *****; #passed from form my ( $snmp_session, $snmp_error ) = Net::session( -hostname => $snmp_host, -community => $snmp_community, -version => $snmp_version, -port => $snmp_port, -debug => 0 ); my $newname = param('Device Name'); my $newdescription = param('Description'); my $newlocation = param('location'); my $newcontact = param('Contact'); my $sysname = '1.3.6.1.2.1.1.5.0'; my $sysDescr= '1.3.6.1.2.1.1.1.0'; my $sysContact= '1.3.6.1.2.1.1.4.0'; my $sysLocation = '1.3.6.1.2.1.1.6.0'; my $result = $snmp_session->set_request(-varbindlist => [$sysN +ame, OCTET_STRING, $newname, $sysDescr, + OCTET_STRING, $newdescription, $sysLocati +on, OCTET_STRING, $newlocation, $sysContac +t, OCTET_STRING, $newcontact]); $result or warn "error: @{[$snmp_session->error]}\n";
where the snmp_session is correctly set up(as i had queried the data already)and all the params are correctly passed from the form.

Replies are listed 'Best First'.
Re: multiple set_requests snmp/perl
by Limbic~Region (Chancellor) on Mar 03, 2004 at 17:39 UTC
    tommycahir,
    Per our conversation in the CB, you indicated you are using Net::SNMP. After reading the docs I can't see a problem even though there aren't any examples with multiple sets in one statement. To be on the safe side - try this:
    my @list = ( [$sysName, OCTET_STRING, $newname], [$sysDescr, OCTET_STRING, $newdescription], [$sysContact, OCTET_STRING, $newcontact] ); for my $item ( @list ) { my $result = $snmp_session->set_request( -varbindlist => $item ); warn "error: @{[$snmp_session->error]}\n" if ! $result; }
    Cheers - L~R
      i tried that code L~R but as before it only sets the first value.. anybody help me before i crack up ere.
        tommycahir,
        Well that's sort of a good sign. It means that there was nothing wrong with your original code and the problem must be elsewhere. I am not sure if $result has any meaningful information but it may be worthwhile to print $result each time through the loop. Additionally, have you checked out the snmpset script that came with Net::SNMP? The only other thing I can suggest is turn the SNMP logging for the server you are setting on way up and tail the log.

        Cheers - L~R

Re: multiple set_requests snmp/perl
by NetWallah (Canon) on Mar 03, 2004 at 19:38 UTC
    I'd say its time to sniff the wire to see if the outgoing packet(s) look OK, and how the target machine is responding to the set.

    "Experience is a wonderful thing. It enables you to recognize a mistake when you make it again."
      tanx for all the help guys got the operation going it was a config issue with the snmpconf as i had mistakinly set the vaklues in the snmpoconf script which stopped me from writing to them..
      ****note to self must read instructions*****