hello Bob I ran your sub-agent on my system and I only needed to add this at the top:
use NetSNMP::ASN qw(ASN_OCTET_STR ASN_INTEGER); I was getting this in the snmpd logs: "May 31 07:35:24 xone snmpd[5680]: unknown var value type: 0 " agent was complaining about not knowing what ASN_OCTET_STRING was :) you should be ok now.... Joao On Sun, 2010-05-30 at 15:39 +0000, [email protected] wrote: > I have been having trouble getting the perl mib agent examples going. Does > not seem to register the OID. Below I include a) test-mib.pl, b) > snmpd.conf, c) output from 'snmpd' cmd, d) output from good 'snmpget' and f) > failed 'snmpget' on new OID. > > Any suggestions? > > Thanks, > Bob Cole > =========================================== > > > > test-mib.pl: > =========================================== > use NetSNMP::OID (':all'); > use NetSNMP::agent (':all'); > > > sub myhandler { > my ($handler, $registration_info, $request_info, $requests) = @_; > my $request; > > for($request = $requests; $request; $request = $request->next()) { > my $oid = $request->getOID(); > if ($request_info->getMode() == MODE_GET) { > # ... generally, you would calculate value from oid > if ($oid == new > NetSNMP::OID(".1.3.6.1.4.1.8072.9999.9999.7375.1.0")) { > $request->setValue(ASN_OCTET_STR, "hello world!"); > } > } elsif ($request_info->getMode() == MODE_GETNEXT) { > # ... generally, you would calculate value from oid > if ($oid < new > NetSNMP::OID(".1.3.6.1.4.1.8072.9999.9999.7375.1.0")) { > > $request->setOID(".1.3.6.1.4.1.8072.9999.9999.7375.1.0"); > $request->setValue(ASN_OCTET_STR, "hello world!"); > } > } > #elsif ($request_info->getMode() == MODE_SET_RESERVE1) { > # if ($oid != new > NetSNMP::OID(".1.3.6.1.4.1.8072.9999.9999.7375.1.0")) { > # do error checking here > # $request->setError($request_info, > SNMP_ERR_NOSUCHNAME); > # } > #} elsif ($request_info->getMode() == MODE_SET_ACTION) { > # ... (or use the value) > # $value = $request->getValue(); > #} > } > } > > > # > # Associate the handler with a particular OID tree > # > my $rootOID = ".1.3.6.1.4.1.8072.9999.9999.7375"; > my $regoid = new NetSNMP::OID($rootOID); > $agent->register("Bob Net-SNMP Agen", $regoid, \&myhandler); > > print STDERR "Loaded the Bob example perl snmpagent handler\n"; > > =========================================== > > > snmpd.conf: > =========================================== > ########################################################################### > # > # snmpd.conf > # > # - created by the snmpconf configuration program > # > ########################################################################### > # SECTION: System Information Setup > # > # This section defines some of the information reported in > # the "system" mib group in the mibII tree. > > # syslocation: The [typically physical] location of the system. > # Note that setting this value here means that when trying to > # perform an snmp SET operation to the sysLocation.0 variable will make > # the agent return the "notWritable" error code. IE, including > # this token in the snmpd.conf file will disable write access to > # the variable. > # arguments: location_string > > syslocation rgc_laptop > > # syscontact: The contact information for the administrator > # Note that setting this value here means that when trying to > # perform an snmp SET operation to the sysContact.0 variable will make > # the agent return the "notWritable" error code. IE, including > # this token in the snmpd.conf file will disable write access to > # the variable. > # arguments: contact_string > > syscontact [email protected] > # sysservices: The proper value for the sysServices object. > # arguments: sysservices_number > > sysservices 0 > > > > > ########################################################################### > # SECTION: Access Control Setup > # > # This section defines who is allowed to talk to your running > # snmp agent. > > # rwuser: a SNMPv3 read-write user > # arguments: user [noauth|auth|priv] [restriction_oid] > > rwuser localhost noauth > > # rouser: a SNMPv3 read-only user > # arguments: user [noauth|auth|priv] [restriction_oid] > > rouser localhost noauth > > # rocommunity: a SNMPv1/SNMPv2c read-only access community name > # arguments: community [default|hostname|network/bits] [oid] > > rocommunity public > > # rwcommunity: a SNMPv1/SNMPv2c read-write access community name > # arguments: community [default|hostname|network/bits] [oid] > > rwcommunity public > > > ##### > # > # Embedded perl MIB support here > # > ##### > > #perl print "\nStarting up the snmpd agent!\n\n"; > > perl do "/home/rgc/IETF/DEVELOPMENT/TEST/test-mib.pl"; > > > =========================================== > > 'snmpd -DPERL' output: > =========================================== > > snmpd -DPERL > No log handling enabled - turning on stderr logging > registered debug token PERL, 1 > Loaded the Bob example perl snmpagent handler > r...@chapman:~/.snmp# NET-SNMP version 5.5 > > r...@chapman:~/.snmp# unknown var value type: 0 > > =========================================== > > > 'snmpget -v 2c -c public 127.0.0.1 sysUpTime.0' output: > =========================================== > > snmpget -v 2c -c public 127.0.0.1 sysUpTime.0 > DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (1929) 0:00:19.29 > > =========================================== > > > 'snmpget -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999.7375.1.0' > output: > =========================================== > > snmpget -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.8072.9999.9999.7375.1.0 > NET-SNMP-MIB::netSnmpPlaypen.7375.1.0 = No Such Instance currently exists at > this OID > > =========================================== > > ------------------------------------------------------------------------------ > > _______________________________________________ > Net-snmp-users mailing list > [email protected] > Please see the following page to unsubscribe or change other options: > https://lists.sourceforge.net/lists/listinfo/net-snmp-users ------------------------------------------------------------------------------ _______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users
