[SNMP4J] TRAP PDU handled by ProccesPDU and not by notify method in CommandProcessor class !!!!!!!!
wafae alami
alami.ouafae at gmail.com
Tue May 19 18:17:33 CEST 2009
HI Frank ,
Actually it's internal processed ,
I have a JMXGateway that raise notification and send them to the port 8001 ,
my application is well running in that port . I have a Trapviewer that acts
as a remote manager and listennig for traps on port 1620 . I have configured
the trap taget destination in the application to (127.0.0.1/1620) :
My agent is :
=============================================================================
/*_############################################################################
_##
_## SNMP4J-AgentJMX - JMXTestAgent.java
_##
_## Copyright (C) 2006-2007 Frank Fock (SNMP4J.org)
_##
_## This program is free software; you can redistribute it and/or modify
_## it under the terms of the GNU General Public License version 2 as
_## published by the Free Software Foundation.
_##
_## This program is distributed in the hope that it will be useful,
_## but WITHOUT ANY WARRANTY; without even the implied warranty of
_## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
_## GNU General Public License for more details.
_##
_## You should have received a copy of the GNU General Public License
_## along with this program; if not, write to the Free Software
_## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
_## MA 02110-1301 USA
_##
_##########################################################################*/
package org.snmp4j.agent.mo.jmx.example;
import java.io.*;
import org.snmp4j.*;
import org.snmp4j.agent.*;
import org.snmp4j.agent.mo.*;
import org.snmp4j.agent.mo.snmp.*;
import org.snmp4j.mp.*;
import org.snmp4j.security.*;
import org.snmp4j.smi.*;
import org.snmp4j.transport.*;
import org.snmp4j.agent.io.ImportModes;
import org.snmp4j.util.ThreadPool;
import org.snmp4j.log.LogFactory;
import org.snmp4j.agent.security.MutableVACM;
import org.snmp4j.agent.mo.jmx.mibs.A5350Mib;
import static org.snmp4j.agent.mo.jmx.mibs.A5350Mib.*;
import org.snmp4j.agent.mo.jmx.mibs.A5350MibInst;
import org.snmp4j.agent.mo.jmx.mibs.JvmManagementMib;
import org.snmp4j.log.LogAdapter;
import org.snmp4j.log.JavaLogFactory;
/**
* The <code>JMXTestAgent</code> is a sample SNMP agent implementation of
all
* features (MIB implementations) provided by the SNMP4J-AgentJMX framework.
* For demonstration purposes, the agent implements the JVM-MANAGEMENT-MIB
as
* far as this can be done without violating the SNMP standard. There are
flaws
* in that MIB module that violate the SNMP standard which have been
implemented
* in a standard conforming way.
*
* @author Frank Fock
* @version 1.0
*/
public class JMXTestAgent extends BaseAgent {
// initialize Log4J logging
static {
LogFactory.setLogFactory(new JavaLogFactory());
}
private static final LogAdapter logger
=LogFactory.getLogger(JMXTestAgent.class);
protected String address;
private static A5350Mib a5350Mib;
/**
* Creates the test agent with a file to read and store the boot counter
and
* a file to read and store its configuration.
*
* @param bootCounterFile
* a file containing the boot counter in serialized form (as expected
by
* BaseAgent).
* @param configFile
* a configuration file with serialized management information.
* @throws IOException
* if the boot counter or config file cannot be read properly.
*/
public JMXTestAgent(File bootCounterFile, File configFile) throws
IOException {
super(bootCounterFile, configFile,
new CommandProcessor(new
OctetString(MPv3.createLocalEngineID())));
// Alternatively: OctetString.fromHexString("00:00:00:00:00:00:02",
':');
//
agent.setThreadPool(ThreadPool.create("RequestPool", 4));
}
protected void registerManagedObjects() {
}
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB)
{
targetMIB.addDefaultTDomains();
targetMIB.addTargetAddress(new OctetString("notification"),
TransportDomains.transportDomainUdpIpv4,
*new OctetString(new UdpAddress("
127.0.0.1/1620").getValue()), *
200, 1,
new OctetString("notify"),
new OctetString("v2c"),
StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v2c"),
MessageProcessingModel.MPv2c,
SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("public"),
SecurityLevel.NOAUTH_NOPRIV,
StorageType.permanent);
notificationMIB.addNotifyEntry(new OctetString("default"),
new OctetString("notify"),
SnmpNotificationMIB.SnmpNotifyTypeEnum.trap,
StorageType.permanent);
}
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString("public"),
new OctetString("v1v2group"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("public"),
new OctetString("v1v2group"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("SHADES"),
new OctetString("v3group"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("TEST"),
new OctetString("v3test"),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("SHA"),
new OctetString("v3restricted"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v1v2group"), new OctetString(),
SecurityModel.SECURITY_MODEL_ANY,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v3group"), new OctetString(),
SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.AUTH_PRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v3restricted"), new OctetString(),
SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.AUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("restrictedReadView"),
new OctetString("restrictedWriteView"),
new OctetString("restrictedNotifyView"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v3test"), new OctetString(),
SecurityModel.SECURITY_MODEL_USM,
SecurityLevel.AUTH_PRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("testReadView"),
new OctetString("testWriteView"),
new OctetString("testNotifyView"),
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullNotifyView"), new
OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedReadView"),
new OID("1.3.6.1.2"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedWriteView"),
new OID("1.3.6.1.2.1"),
new OctetString(),
VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("restrictedNotifyView"),
new OID("1.3.6.1.2"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("testReadView"),
new OID("1.3.6.1.2"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("testReadView"),
new OID("1.3.6.1.2.1.1"),
new OctetString(), VacmMIB.vacmViewExcluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("testWriteView"),
new OID("1.3.6.1.2.1"),
new OctetString(),
VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("testNotifyView"),
new OID("1.3.6.1.2"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
}
protected void addUsmUser(USM usm) {
UsmUser user = new UsmUser(new OctetString("SHADES"),
AuthSHA.ID,
new OctetString("SHADESAuthPassword"),
PrivDES.ID,
new OctetString("SHADESPrivPassword"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
user = new UsmUser(new OctetString("TEST"),
AuthSHA.ID,
new OctetString("maplesyrup"),
PrivDES.ID,
new OctetString("maplesyrup"));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
user = new UsmUser(new OctetString("SHA"),
AuthSHA.ID,
new OctetString("SHAAuthPassword"),
null,
null);
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
}
protected void initTransportMappings() throws IOException {
transportMappings = new TransportMapping[1];
Address addr = GenericAddress.parse(address);
TransportMapping tm =
TransportMappings.getInstance().createTransportMapping(addr);
transportMappings[0] = tm;
}
public static void main(String[] args) throws IOException {
String address;
if (args.length > 0) {
address = args[0];
}
else {
address = "0.0.0.0/161";
}
JMXTestAgent testAgent1 =
new JMXTestAgent(new File("SNMP4JJMXTestAgentBC.cfg"),new
File("SNMP4JJMXTestAgentConfig.cfg"));
testAgent1.address = address;
testAgent1.init();
testAgent1.loadConfig(ImportModes.UPDATE_CREATE);
testAgent1.addShutdownHook();
testAgent1.finishInit();
testAgent1.run();
}
protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered...
}
protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] {
new OctetString("public"), // community name
new OctetString("public"), // security name
getAgent().getContextEngineID(), // local engine ID
new OctetString(), // default context name
new OctetString(), // transport tag
new Integer32(StorageType.nonVolatile), // storage type
new Integer32(RowStatus.active) // row status
};
MOTableRow row =
communityMIB.getSnmpCommunityEntry().createRow(
new OctetString("public2public").toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
// snmpCommunityMIB.setSourceAddressFiltering(true);
}
protected void registerSnmpMIBs() {
super.registerSnmpMIBs();
try {
a5350Mib =new A5350MibInst(super.agent.getNotificationOriginator());
a5350Mib.registerMOs(server,null);
}
catch (DuplicateRegistrationException ex) {
logger.error("Unable to register A5350-module-MIB", ex);
}
}
}
=============================================================================
Thanks for your kinds support .
Ouafae .
2009/5/19 Frank Fock <fock at agentpp.com>
> Hi Ouafae,
>
> As written earlier on this subject I suspect
> a misconfiguration. Have you a stack trace,
> of the call on the processPDU method?
>
> My question is: Does the packet is internally
> processed or does it come from the wire?
>
> Best regards,
> Frank
>
> wafae alami wrote:
>
>> Hi frank ;
>>
>> I'm using a Snmp4J agent to listen for some JMX notifications raised by an
>> MbeanServer the main goal of my application is to map those notifications to
>> SNMP Traps and send them to a remote manager , when receiving the JMX
>> notification , the handleNotification method of the JMXNotificationSupport
>> class is well invoqued but :
>>
>> public void handleNotification(Notification notification, Object
>> handback) {
>> System.out.println("---------- I 'm in notification Handler");
>> MBeanNotificationInfo info = notificationInfos.get(handback);
>> if (info != null) {
>> System.out.println("----------- INFO IS NOT NULL");
>> System.out.println("----------- notification.getUserData():
>> "+notification.getUserData());
>> System.out.println("----------- info.getNotificationPayload:
>> "+info.getNotificationPayload( notification.getUserData()));
>> VariableBinding[] vbs =
>> info.getNotificationPayload(notification.getUserData());
>> for(int i=0;i<vbs.length;i++){
>> System.out.println("---------- vbs
>> :"+vbs[i].getOid().toString());
>> }
>> notificationOriginator.notify(info.getContext(), (OID)handback,
>> vbs);
>> System.out.println("----------- AFTER notificationOriginator
>> notify");
>> }
>> }
>>
>>
>> The Result is :
>> ----------- I 'm in notification Handler
>> ----------- INFO IS NOT NULL
>> ----------- notification.getUserData(): null
>> ----------- info.getNotificationPayload:
>> [Lorg.snmp4j.smi.VariableBinding;@1fae1cd
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.1.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.2.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.3.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.4.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.7.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.5.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.6.0
>> ---------- vbs :1.3.6.1.4.1.637.71.6.6.8.0
>>
>> The CommandProcessor is called also , and the ProcessPDU method is
>> invoqued instead of the notify one , !!
>> obviously there is no handler for the TRAP PDU and the following message
>> is displayed :
>>
>> INFO: No PDU handler found for request
>> CommandResponderEvent[transportMapping=org.snmp4j.transport.DefaultUdpTransportMapping at 1c2cbeepeerAddress
>> =155.132.215.56/60413 <http://155.132.215.56/60413>, processed=true,
>> pdu=[TRAP[requestID=189, errorStatus=Success(0), errorIndex=0,
>> VBS[1.3.6.1.2.1.1.3.0 = 2:55:01.34; 1.3.6.1.6.3.1.1.4.1.0 =
>> 1.3.6.1.4.1.637.71.6.1.2; 1.3.6.1.4.1.637.71.6.6.1.0 = 464 days,
>> 17:39:07.12; 1.3.6.1.4.1.637.71.6.6.2.0 = 16; 1.3.6.1.4.1.637.71.6.6.3.0 =
>> 0; 1.3.6.1.4.1.637.71.6.6.4.0 = Restarting failed autoStart instance;
>> 1.3.6.1.4.1.637.71.6.6.5.0 = mcad7p38; 1.3.6.1.4.1.637.71.6.6.6.0 =
>> MySqlCluster__mysql_mcad7p38; 1.3.6.1.4.1.637.71.6.6.7.0 = MySql;
>> 1.3.6.1.4.1.637.71.6.6.8.0 = 6; 1.3.6.1.4.1.2162.10.3.1.3.3 = 2009/05/19
>> 14:39:50: Code 16 (Notif) Comp = 'MySql', Inst =
>> 'MySqlCluster__mysql_mcad7p38', on host mcad7p38: Restarting failed
>> autoStart instance]]], securityName=public, securityModel=2,
>> securityLevel=1]
>>
>>
>>
>> Best Regards
>> Ouafae ,
>>
>
> --
> AGENT++
> http://www.agentpp.com
> http://www.snmp4j.com
> http://www.mibexplorer.com
> http://www.mibdesigner.com
>
>
--
Ouafae ALAMI (Promotion INPT 2007)
Ingénieur de Convergence a Alcatel-Lucent
Projet Ims Application Server.
More information about the SNMP4J
mailing list