Hi all, I'm a newbie with AgentX. I need to extend snmpd with a new custom MIB module. I have NET-SNMP version 5.5 on Redhat, I would implement perl API, using NetSNMP::agent. Hereby, the steps I've done:
- /etc/snmp/snmpd.conf #sec.name source community com2sec notConfigUser default public #groupName securityModel securityName group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser #name incl/excl subtree mask(optional) view all included .1 #group context sec.model sec.level prefix read write notif access notConfigGroup "" any noauth exact all all none master agentx - MIB module My custom MIB is related to an active alarms table for fault management. It must be queryable from an external management station. The MIB file (ACM-LOGWATCH-MIB) is located in /usr/share/snmp/mibs directory. Here the subset for Table: acmLogWatchTable OBJECT-TYPE SYNTAX SEQUENCE OF acmLogWatchEntry MAX-ACCESS read-only STATUS current DESCRIPTION "Table of objects" ::= { acmLogWatch 10 } acmLogWatchEntry OBJECT-TYPE SYNTAX acmLogWatchEntry MAX-ACCESS read-only STATUS current DESCRIPTION "" INDEX { acmLogWatchIndex } ::= { acmLogWatchTable 1 } acmLogWatchEntry ::= SEQUENCE { acmLogWatchIndex Integer32, acmLogWatchSpecificProblem DisplayString, acmLogWatchProbableCause DisplayString, } acmLogWatchIndex OBJECT-TYPE SYNTAX INTEGER ACCESS read-only STATUS mandatory DESCRIPTION "A unique value for each active alarm" ::= { acmLogWatchEntry 1 } acmLogWatchSpecificProblem OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-write STATUS current DESCRIPTION "the specific problem of the alarm" ::= { acmLogWatchEntry 2 } acmLogWatchProbableCause OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-write STATUS current DESCRIPTION "the probable cause of the alarm" ::= { acmLogWatchEntry 3 } snmpset is used to set OID's Values. - perl code: use NetSNMP::agent (':all'); use NetSNMP::ASN (':all'); use NetSNMP::OID(':all'); my $default_SP = "SP 1"; my $default_PC = "PC 1"; 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.193.37.10.11.64.10.1.2.0")) { $request->setValue(ASN_OCTET_STR, $default_SP); } if ($oid == new NetSNMP::OID(".1.3.6.1.4.1.193.37.10.11.64.10.1.3.0")) { $request->setValue(ASN_OCTET_STR, $default_PC); } } elsif ($request_info->getMode() == MODE_GETNEXT) { # ... generally, you would calculate value from oid if ( $oid < new NetSNMP::OID(".1.3.6.1.4.1.193.37.10.11.64.10.1.2.0")) { $request->setOID(".1.3.6.1.4.1.193.37.10.11.64.10.1.2.0"); $request->setValue(ASN_OCTET_STR, $default_SP); $request->setOID(".1.3.6.1.4.1.193.37.10.11.64.10.1.3.0"); $request->setValue(ASN_OCTET_STR, $default_PC); } } elsif ($request_info->getMode() == MODE_SET_RESERVE1) { if ( ( $oid != new NetSNMP::OID(".1.3.6.1.4.1.193.37.10.11.64.10.1.2.0")) and ( $oid != new NetSNMP::OID(".1.3.6.1.4.1.193.37.10.11.64.10.1.3.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(); } } } my $agent = new NetSNMP::agent( # makes the agent read a my_agent_name.conf file 'Name' => "my_agent_name", 'AgentX' => 1 ); $agent->register("my_agent_name", ".1.3.6.1.4.1.193.37.10.11.64.10", \&myhandler); my $running = 1; while($running) { $agent->agent_check_and_process(1); } $agent->shutdown(); Results: # snmpget -v2c -c public localhost .1.3.6.1.4.1.193.37.10.11.64.10.1.2.0 ACM-LOGWATCH-MIB::acmLogWatchSpecificProblem.0 = STRING: SP 1 # snmpget -v2c -c public localhost .1.3.6.1.4.1.193.37.10.11.64.10.1.3.0 ACM-LOGWATCH-MIB::acmLogWatchProbableCause.0 = STRING: PC 1 SNMPWALK doesn't show all the OID's set, but last one: # snmpwalk -v2c -c public localhost .1.3.6.1.4.1.193.37.10.11.64.10 ACM-LOGWATCH-MIB::acmLogWatchProbableCause.0 = STRING: PC 1 SNMPSET doesn't work: [root@redhatgp ACM]# snmpset -v2c -c public localhost .1.3.6.1.4.1.193.37.10.11.64.10.1.3.0 s "PC 2" ACM-LOGWATCH-MIB::acmLogWatchProbableCause.0 = STRING: PC 2 [root@redhatgp ACM]# snmpget -v2c -c public localhost .1.3.6.1.4.1.193.37.10.11.64.10.1.3.0 ACM-LOGWATCH-MIB::acmLogWatchProbableCause.0 = STRING: PC 1 Can anyone help me? Thanks Simone
_______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders