3.11.10

Trap in SNMP4j-Agent

SNMP Trap is something very interesting. The Agent is responsible for sending trap/notification, while the client works in the daemon mode to receive trap messages.

Who is the server? Well, server is not a concept in SNMP v1 and v2. People call them agents.

How Trap is Implemented in SNMP4J Agent?

That is a good question. Just take a look at BaseAgent. Here is some excerpt from SNMP4J Agent 1.4.1.

134   /**
135 * Initialize transport mappings, message dispatcher, basic MIB modules,
136 * proxy forwarder, VACM and USM security, and custom MIB modules and objects
137 * provided by sub-classes.
138 *
139 * @throws IOException
140 * if initialization fails because transport initialization fails.
141 */
142 public void init() throws IOException {
143 agentState = STATE_INIT_STARTED;
144 initTransportMappings();
145 initMessageDispatcher();
146 server.addContext(new OctetString());
147 snmpv2MIB = new SNMPv2MIB(sysDescr, sysOID, sysServices);
148
149 // register Snmp counters for updates
150 dispatcher.addCounterListener(snmpv2MIB);
151 agent.addCounterListener(snmpv2MIB);
152 snmpFrameworkMIB =
153 new SnmpFrameworkMIB((USM)
154 mpv3.getSecurityModel(SecurityModel.SECURITY_MODEL_USM),
155 dispatcher.getTransportMappings());
156 usmMIB = new UsmMIB(usm, SecurityProtocols.getInstance());
157 usm.addUsmUserListener(usmMIB);
158
159 vacmMIB = new VacmMIB(new MOServer[] { server });
160 snmpTargetMIB = new SnmpTargetMIB(dispatcher);
161 snmpNotificationMIB = new SnmpNotificationMIB();
162 snmpCommunityMIB = new SnmpCommunityMIB(snmpTargetMIB);
163 initConfigMIB();
164 snmpProxyMIB = new SnmpProxyMIB();
165 notificationOriginator =
166 new NotificationOriginatorImpl(session, vacmMIB,
167 snmpv2MIB.getSysUpTime(),
168 snmpTargetMIB, snmpNotificationMIB);

169 snmpv2MIB.setNotificationOriginator(agent);
170
171 setupDefaultProxyForwarder();
172 // add USM users
173 addUsmUser(usm);
174 // add SNMPv1/v2c community to SNMPv3 security name mappings
175 addCommunities(snmpCommunityMIB);
176 addViews(vacmMIB);
177 addNotificationTargets(snmpTargetMIB, snmpNotificationMIB);
178
179 registerSnmpMIBs();
180 }


At line 161, an SnmpNotificationMIB instance is created. From line 165 to 168, a NotificationOriginator is created by using NotificationOriginatorImpl. Line 169 sets up the notification originator for SNMPv2 MIB object, while line 177 calls the abstract method, addNotificationTargets() to add more things into the target MIB and notification MIB.


addNotificationTargets()?


If you are using BaseAgent just like I do now, overriding addNotificationTargets() method could be a very good access point for your trap targets.This method is abstract in BaseAgent, and you must override them, although you can just put it as empty in your derived class.


Target MIB?


The method addNotificationTargets() uses two parameters: Target MIB and Notification MIB.


Target MIB is an instance of SnmpTargetMIB class. It is initialized at line 160 above with a dispatcher, which is an instance of MessageDispatcherImpl, initialized by initMessageDispatcher().


From the SNMP protocol’s point of view, SnmpTargetMIB takes care of SNMP Target Objects in SNMP-TARGET-MIB, which is a version 2 MIB.


OID Base









snmpTargetObjects
1.3.6.1.6.3.12.1

iso(1). org(3). dod(6). internet(1). snmpV2(6). snmpModules(3). snmpTargetMIB(12). snmpTargetObjects(1)


Details










































































































































































































snmpTargetObjectsGROUP1.3.6.1.6.3.12.1
iso(1). org(3). dod(6). internet(1). snmpV2(6). snmpModules(3). snmpTargetMIB(12). snmpTargetObjects(1)
  snmpTargetSpinLockSCALARread-writeTestAndIncr1.3.6.1.6.3.12.1.1.0
  snmpTargetAddrTableTABLEnot-accessibleSEQUENCE OF1.3.6.1.6.3.12.1.2
    snmpTargetAddrEntryENTRYnot-accessibleSnmpTargetAddrEntry1.3.6.1.6.3.12.1.2.1
      snmpTargetAddrNameTABULARnot-accessibleSnmpAdminString ( 1..32 )1.3.6.1.6.3.12.1.2.1.1
      snmpTargetAddrTDomainTABULARread-createTDomain1.3.6.1.6.3.12.1.2.1.2
      snmpTargetAddrTAddressTABULARread-createTAddress1.3.6.1.6.3.12.1.2.1.3
      snmpTargetAddrTimeoutTABULARread-createTimeInterval1.3.6.1.6.3.12.1.2.1.4
      snmpTargetAddrRetryCountTABULARread-createInteger32 ( 0..255 )1.3.6.1.6.3.12.1.2.1.5
      snmpTargetAddrTagListTABULARread-createSnmpTagList1.3.6.1.6.3.12.1.2.1.6
      snmpTargetAddrParamsTABULARread-createSnmpAdminString ( 1..32 )1.3.6.1.6.3.12.1.2.1.7
      snmpTargetAddrStorageTypeTABULARread-createStorageType1.3.6.1.6.3.12.1.2.1.8
      snmpTargetAddrRowStatusTABULARread-createRowStatus1.3.6.1.6.3.12.1.2.1.9
  snmpTargetParamsTableTABLEnot-accessibleSEQUENCE OF1.3.6.1.6.3.12.1.3
    snmpTargetParamsEntryENTRYnot-accessibleSnmpTargetParamsEntry1.3.6.1.6.3.12.1.3.1
      snmpTargetParamsNameTABULARnot-accessibleSnmpAdminString ( 1..32 )1.3.6.1.6.3.12.1.3.1.1
      snmpTargetParamsMPModelTABULARread-createSnmpMessageProcessingModel1.3.6.1.6.3.12.1.3.1.2
      snmpTargetParamsSecurityModelTABULARread-createSnmpSecurityModel ( 1..2147483647 )1.3.6.1.6.3.12.1.3.1.3
      snmpTargetParamsSecurityNameTABULARread-createSnmpAdminString1.3.6.1.6.3.12.1.3.1.4
      snmpTargetParamsSecurityLevelTABULARread-createSnmpSecurityLevel1.3.6.1.6.3.12.1.3.1.5
      snmpTargetParamsStorageTypeTABULARread-createStorageType1.3.6.1.6.3.12.1.3.1.6
      snmpTargetParamsRowStatusTABULARread-createRowStatus1.3.6.1.6.3.12.1.3.1.7
  snmpUnavailableContextsSCALARread-onlyCounter321.3.6.1.6.3.12.1.4.0
  snmpUnknownContextsSCALARread-onlyCounter321.3.6.1.6.3.12.1.5.0

What can I do with SNMP4J Agent?


You might probably don’t care about SNMP Target MIB. All you need could only by how to use SNMP4J Agent. Good.


Although the Java API documentation for SNMP4J Agent is very useless, they provided meaningful naming, as well as, and more importantly, source code. That is way we like open-source, right?


 


Notification MIB?

No comments: