14.11.10

Why Apache Commons Exec Needs the Watchdog Working as Observer?

Currently, I can’t see the requirements.

Watchdog & Observer Design Pattern

What is Observer Pattern

http://en.wikipedia.org/wiki/Observer_pattern

The observer pattern (a subset of the publish/subscribe pattern) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.

image

10.11.10

How to Create Command Prompt for Folders

HKEY_CLASSES_ROOT\Folder\shell\cmd\command

How to Create a Right Click Menu in Windows 7 for GVim or Other Green Program?

Very simple.

  • regedit
  • HKEY_CLASSES_ROOT/*/shell
  • Create a key with any name you like, e.g. “Edit with GVim”. After that, please test it with you Explorer by right click on any files. You will see a new menu item there.
  • Create a new key as “command” underneath. You must use “command” as the key.
  • Set the string value of command key: <command path> “%1”
    • e.g.: C:\Tools\vim73\gvim “%1”

That’s it.

8.11.10

Understanding Simple Network Management Protocol (SNMP) Traps

http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a0080094aa5.shtml

SNMPv1 traps are defined in RFC 1157, with these fields:

  • Enterprise—Identifies the type of managed object that generates the trap.

  • Agent address—Provides the address of the managed object that generates the trap.

  • Generic trap type—Indicates one of a number of generic trap types.

  • Specific trap code—Indicates one of a number of specific trap codes.

  • Time stamp—Provides the amount of time that has elapsed between the last network reinitialization and generation of the trap.

  • Variable bindings—The data field of the trap that contains PDU. Each variable binding associates a particular MIB object instance with its current value.

Standard generic traps are: coldStart, warmStart, linkDown, linkUp, authenticationFailure, egpNeighborLoss. For generic SNMPv1 traps, Enterprise field contains value of sysObjectID  of the device that sends trap. For vendor specific traps, Generic trap type field is set to enterpriseSpecific(6).

In SNMPv2c trap is defined as NOTIFICATION and formatted differently compared to SNMPv1. It has these parameters:

  • sysUpTime—This is the same as Time stamp in SNMPv1 trap.

  • snmpTrapOID  —Trap identification field. For generic traps, values are defined in RFC 1907, for vendor specific traps snmpTrapOID is essentially a concatenation of the SNMPv1 Enterprise parameter and two additional sub-identifiers, '0', and the SNMPv1 Specific trap code parameter.

  • VarBindList—This is a list of variable-bindings.

In order for a management system to understand a trap sent to it by an agent, the management system must know what the object identifier (OID) defines. Therefore, it must have the MIB for that trap loaded. This provides the correct OID information so that the network management system can understand the traps sent to it.

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?

How To Create a Dynamic SNMP Table By Using SNMP4J-Agent?

MOTableSubIndex

MOTableIndex

OID

MOColumn