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
snmpTargetObjects | GROUP | 1.3.6.1.6.3.12.1 iso(1). org(3). dod(6). internet(1). snmpV2(6). snmpModules(3). snmpTargetMIB(12). snmpTargetObjects(1) | |||||
snmpTargetSpinLock | SCALAR | read-write | TestAndIncr | 1.3.6.1.6.3.12.1.1.0 | |||
snmpTargetAddrTable | TABLE | not-accessible | SEQUENCE OF | 1.3.6.1.6.3.12.1.2 | |||
snmpTargetAddrEntry | ENTRY | not-accessible | SnmpTargetAddrEntry | 1.3.6.1.6.3.12.1.2.1 | |||
snmpTargetAddrName | TABULAR | not-accessible | SnmpAdminString ( 1..32 ) | 1.3.6.1.6.3.12.1.2.1.1 | |||
snmpTargetAddrTDomain | TABULAR | read-create | TDomain | 1.3.6.1.6.3.12.1.2.1.2 | |||
snmpTargetAddrTAddress | TABULAR | read-create | TAddress | 1.3.6.1.6.3.12.1.2.1.3 | |||
snmpTargetAddrTimeout | TABULAR | read-create | TimeInterval | 1.3.6.1.6.3.12.1.2.1.4 | |||
snmpTargetAddrRetryCount | TABULAR | read-create | Integer32 ( 0..255 ) | 1.3.6.1.6.3.12.1.2.1.5 | |||
snmpTargetAddrTagList | TABULAR | read-create | SnmpTagList | 1.3.6.1.6.3.12.1.2.1.6 | |||
snmpTargetAddrParams | TABULAR | read-create | SnmpAdminString ( 1..32 ) | 1.3.6.1.6.3.12.1.2.1.7 | |||
snmpTargetAddrStorageType | TABULAR | read-create | StorageType | 1.3.6.1.6.3.12.1.2.1.8 | |||
snmpTargetAddrRowStatus | TABULAR | read-create | RowStatus | 1.3.6.1.6.3.12.1.2.1.9 | |||
snmpTargetParamsTable | TABLE | not-accessible | SEQUENCE OF | 1.3.6.1.6.3.12.1.3 | |||
snmpTargetParamsEntry | ENTRY | not-accessible | SnmpTargetParamsEntry | 1.3.6.1.6.3.12.1.3.1 | |||
snmpTargetParamsName | TABULAR | not-accessible | SnmpAdminString ( 1..32 ) | 1.3.6.1.6.3.12.1.3.1.1 | |||
snmpTargetParamsMPModel | TABULAR | read-create | SnmpMessageProcessingModel | 1.3.6.1.6.3.12.1.3.1.2 | |||
snmpTargetParamsSecurityModel | TABULAR | read-create | SnmpSecurityModel ( 1..2147483647 ) | 1.3.6.1.6.3.12.1.3.1.3 | |||
snmpTargetParamsSecurityName | TABULAR | read-create | SnmpAdminString | 1.3.6.1.6.3.12.1.3.1.4 | |||
snmpTargetParamsSecurityLevel | TABULAR | read-create | SnmpSecurityLevel | 1.3.6.1.6.3.12.1.3.1.5 | |||
snmpTargetParamsStorageType | TABULAR | read-create | StorageType | 1.3.6.1.6.3.12.1.3.1.6 | |||
snmpTargetParamsRowStatus | TABULAR | read-create | RowStatus | 1.3.6.1.6.3.12.1.3.1.7 | |||
snmpUnavailableContexts | SCALAR | read-only | Counter32 | 1.3.6.1.6.3.12.1.4.0 | |||
snmpUnknownContexts | SCALAR | read-only | Counter32 | 1.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?
No comments:
Post a Comment