|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.adventnet.snmp.beans.SnmpTrapReceiver
Receives SNMP Traps from SNMP Agents. Generate a TrapEvent for each trap received. This class can be used with beans, applications and applets. It supports event generation as per the JDK 1.1 event model.
To use in an application, simply instantiate, specify the port, and register to receive traps. For example,
SnmpTrapReceiver receiver = new SnmpTrapReceiver();
TrapListener listener = new TrapListener() {
public void receivedTrap(TrapEvent trap) {
System.err.println("Got a trap from: "+trap.getRemoteHost());
}
};
receiver.addTrapListener(listener);
try {
receiver.setPortWithExceptionMsg(162);
}
catch(SnmpException e) {
System.err.println(e.getMessage());
}
The resources used by this class are automatically garbage collected after removing all the registered listeners. No need to close sessions, or other cleanup by the user.
Supply the applet in the constructor if using applets and may need to use SAS.
| Field Summary | |
(package private) SnmpAPI |
api
|
(package private) static java.applet.Applet |
applet
|
(package private) java.lang.String |
authPassword
|
(package private) int |
authProtocol
|
(package private) boolean |
commAuth
|
(package private) java.lang.String |
community
|
(package private) byte[] |
contextID
|
(package private) java.lang.String |
contextName
|
(package private) java.lang.String |
error
|
(package private) boolean |
isAutoInformResponseEnabled
|
(package private) boolean |
isCallbackthreadEnabled
|
(package private) boolean |
isTrapAuthEnabled
|
(package private) java.util.Vector |
listeners
|
(package private) java.lang.String[] |
localAddresses
|
(package private) com.adventnet.utils.LogInterface |
logClient
|
(package private) java.lang.String |
mibModules
|
(package private) MibOperations |
mibOps
|
(package private) ProtocolOptions |
options
|
(package private) int |
port
|
(package private) java.lang.String |
principal
|
(package private) java.lang.String |
privPassword
|
(package private) int |
privProtocol
|
(package private) int |
protocol
|
(package private) java.text.SimpleDateFormat |
sdf
|
(package private) int |
secModel
|
(package private) SnmpSession |
session
|
(package private) java.util.Vector |
targets
|
(package private) boolean |
trapFlag
|
(package private) USMUserTable |
usmTable
|
(package private) boolean |
v3Auth
|
(package private) int |
version
|
| Constructor Summary | |
SnmpTrapReceiver()
Use this constructor for applications. |
|
SnmpTrapReceiver(java.applet.Applet applet)
Use this constructor for applets. |
|
SnmpTrapReceiver(int protocol,
ProtocolOptions options)
Use this constructor for applications while using generic transportprovider. |
|
| Method Summary | |
void |
addLogClient(com.adventnet.utils.LogInterface client)
add the Log client for which the trapreceiver has to redirect the log messages |
void |
addTrapListener(TrapListener l)
Adds a listener for events from this target. |
boolean |
authenticate(SnmpPDU pdu,
java.lang.String community)
Authenticates the received Trap PDU. |
boolean |
callback(SnmpSession session,
SnmpPDU pdu,
int requestID)
this is the method that processes and forward the trap. |
void |
cleanup()
Deprecated. Replaced by stop() method. |
void |
createUserEntry(byte[] engineID,
byte secLevel)
Creates a usm user entry with the given EngineID and Security Level, in the USM Table. |
void |
debugPrint(java.lang.String debugOutput)
This is the SnmpClient method implementation that redirects the log message to standard output or to client directly if it implements LogInterface. |
protected void |
finalize()
This cleans up the common connection if no one is using |
(package private) void |
genEvent(SnmpPDU pdu)
|
java.lang.String |
getAuthPassword()
Gets authentication password. |
int |
getAuthProtocol()
Gets the Authentication Protocol. |
java.lang.String |
getCharacterEncoding()
Get the Character Encoding being used. |
java.lang.String |
getCommunity()
Gets the SNMP Community. |
java.lang.String |
getcontextID()
Deprecated. Replaced with getContextID() |
java.lang.String |
getContextID()
Gets the SNMP V3 contextID |
java.lang.String |
getContextName()
Gets the SNMP V3 Context name |
java.lang.String[] |
getLocalAddresses()
Gets the local addresses to listen on. |
java.lang.String |
getMibModules()
Gets the MIBs loaded in this applet/application - a white-space separated list of mib files. |
MibOperations |
getMibOperations()
Gets the MibOperations object reference. |
java.lang.String |
getMibPath()
Gets the search Path in which the Mib Parser will search for the MIB modules. |
int |
getPort()
Gets the local SNMP port number to listen on. |
int |
getPortWithExceptionMsg()
Gets the local SNMP port number to listen on. |
java.lang.String |
getPrincipal()
Gets Principal ie userName |
java.lang.String |
getPrivPassword()
Gets the SNMPv3 privacy password. |
int |
getReceiveBufferSize()
This method returns the buffer size of this SnmpTrapReceiver. |
int |
getSecurityModel()
Gets the SNMP V3 securityModel |
java.lang.Object |
getSecurityTable(int secModel)
Gets the SecurityModelTable as an object for a given security Model. |
java.text.SimpleDateFormat |
getSimpleDateFormat()
Gets the SimpleDateFormat for this class. |
int |
getSnmpVersion()
Gets the SNMP Version |
USMUserTable |
getUSMTable()
Gets the USMUserTable reference. |
void |
initJdbcParams(java.lang.String driverName,
java.lang.String URL,
java.lang.String userName,
java.lang.String passWord)
If you need to use database support for mibs, this method should be invoked to initialize the Jdbc Parameters. |
void |
initSecurityProvider()
Initializes the SecurityProvider by reading from the file securityProvider.config. |
(package private) void |
initSnmpStore(SnmpTrapReceiver target)
|
boolean |
isCommunityAuthEnabled()
To check whether the v1/v2 traps are authenticated with their community name and received If true, the received traps are authenticated. |
boolean |
isLoadMibsFromDatabase()
Gets the loadFromDataBase boolean |
boolean |
isOverwriteMibsInDatabase()
Gets the overwrite mibs in DataBase boolean. |
boolean |
isSetAutoInformResponse()
High level API method to check if the automatic response flag for the Inform Request is set. |
boolean |
isSupportedSecurityModel(int secModel)
Specifies if a particular security model is supported or not. |
boolean |
isTrapAuthEnable()
To Check whether traps are authenticated. |
boolean |
isV3AuthEnabled()
To check whether the v3 traps are authenticated and received If true, the received traps are authenticated. |
void |
loadMibs(java.lang.String mibs)
Load the mibs specified by white-space separated list of mibs. |
(package private) void |
logErrorMessage(java.lang.String error)
All the methods of this class (including sub classes), which needs to redirect an error message to the LogManger or to the standard console, can use this method. |
(package private) void |
logInfoMessage(java.lang.String info)
All the methods of this class (including sub classes), which needs to redirect an info message to the LogManger or to the standard console, can use this method. |
(package private) void |
openSession()
|
void |
releaseResources()
Though the resources will be cleaned up by the garbage collector, if the application is no more using the SnmpTrapReceiver bean instances, this method can be used to immediately release the resources. |
void |
removeTrapListener(TrapListener l)
Removes a listener for events from this target. |
void |
setAuthPassword(java.lang.String password)
Sets authentication password for SNMPv3 authentication. |
void |
setAuthProtocol(int protocol)
Sets the Authentication Protocol. |
void |
setAutoInformResponse(boolean flag)
High-level API method to set the automatic response flag for the Inform Request. |
void |
setCallbackthread(boolean flag)
Enable or disable if the user wants the callback to be called from a seperate thread. |
void |
setCharacterEncoding(java.lang.String enc)
Set the Character Encoding to be used. |
void |
setCommunity(java.lang.String s)
Sets the SNMP Community. |
void |
setCommunityAuthEnable(boolean commauth)
Specify whether the community name should be authenticated or not for v1/v2 traps By default the authentication is enabled |
void |
setcontextID(byte[] ctxtID)
Deprecated. Replaced with setContextID(byte[] ctxtID) |
void |
setContextID(byte[] ctxtID)
Sets the SNMP V3 contextID |
void |
setContextName(java.lang.String cName)
Sets the SNMP V3 Context name |
void |
setDebug(boolean debug)
Determines if debug output will be printed |
void |
setLoadMibsFromDatabase(boolean flag)
Defines whether to load mib from DataBase. |
void |
setLocalAddresses(java.lang.String[] addresses)
Sets the local SNMP port number to listen on. |
void |
setMibModules(java.lang.String mibs)
Sets the MIB loaded in this applet/application. |
void |
setMibPath(java.lang.String searchPath)
Sets the search path in which the Mib Parser will search for the MIB modules. |
void |
setOverwriteMibsInDatabase(boolean overWrite)
Defines whether to overwrite the MIB in the DataBase. |
void |
setPort(int i)
Sets the local SNMP port number to listen on. |
void |
setPortWithExceptionMsg(int i)
Sets the local SNMP port number to listen on and throws SnmpException in case of BindException. |
void |
setPrincipal(java.lang.String userName)
Sets the Principal or authentication user name. |
void |
setPrivPassword(java.lang.String password)
Sets the privacy password. |
void |
setReceiveBufferSize(int size)
This method sets the buffer size of this SnmpTrapReceiver. |
void |
setSecurityModel(int securityModel)
Sets the SNMP V3 SecurityModel |
void |
setSimpleDateFormat(java.text.SimpleDateFormat sdf)
Sets the SimpleDateFormat for this class. |
void |
setSnmpVersion(int version)
Sets the SNMP Version |
void |
setTrapAuthEnable(boolean isAuth)
Specify whether traps should be authenticated while receiving it. |
void |
setV3AuthEnable(boolean v3auth)
Specify whether the v3 trap should be authenticated or not. |
void |
stop()
Stops receiving traps. |
(package private) void |
updateMibs()
|
| Methods inherited from class java.lang.Object |
|
| Field Detail |
int protocol
ProtocolOptions options
com.adventnet.utils.LogInterface logClient
java.lang.String mibModules
boolean isTrapAuthEnabled
boolean v3Auth
boolean commAuth
boolean trapFlag
boolean isAutoInformResponseEnabled
java.util.Vector targets
SnmpAPI api
SnmpSession session
java.text.SimpleDateFormat sdf
MibOperations mibOps
java.util.Vector listeners
java.lang.String[] localAddresses
int port
java.lang.String community
int version
boolean isCallbackthreadEnabled
USMUserTable usmTable
int secModel
java.lang.String principal
java.lang.String contextName
byte[] contextID
java.lang.String authPassword
java.lang.String privPassword
int authProtocol
int privProtocol
static java.applet.Applet applet
java.lang.String error
| Constructor Detail |
public SnmpTrapReceiver()
Invoke setPortWithExpMesg(int) method to start receiving trap on the specified port.
stop() method can be used to stop receiving traps.
public SnmpTrapReceiver(int protocol,
ProtocolOptions options)
public SnmpTrapReceiver(java.applet.Applet applet)
Invoke setPortWithExpMesg(int) method to start receiving trap on the specified port.
stop() method can be used to stop receiving traps.
| Method Detail |
public void loadMibs(java.lang.String mibs)
throws MibException,
java.io.IOException,
java.io.FileNotFoundException
public void setMibPath(java.lang.String searchPath)
searchPath- - String specifying the search path, for multiple paths seperate the paths by the pipepublic java.lang.String getMibPath()
public void addTrapListener(TrapListener l)
public void removeTrapListener(TrapListener l)
public MibOperations getMibOperations()
public void setDebug(boolean debug)
public java.lang.String getMibModules()
public void setMibModules(java.lang.String mibs)
void updateMibs()
public boolean authenticate(SnmpPDU pdu,
java.lang.String community)
isTrapAuthEnable(),
setTrapAuthEnable()
public boolean callback(SnmpSession session,
SnmpPDU pdu,
int requestID)
public void setSimpleDateFormat(java.text.SimpleDateFormat sdf)
format - The
SimpleDateFormat used for printing
the timestamp.getSimpleDateFormat()public java.text.SimpleDateFormat getSimpleDateFormat()
setSimpleDateFormat(SimpleDateFormat)public void debugPrint(java.lang.String debugOutput)
public void addLogClient(com.adventnet.utils.LogInterface client)
id- - client id
void openSession()
throws SnmpException
public void initJdbcParams(java.lang.String driverName,
java.lang.String URL,
java.lang.String userName,
java.lang.String passWord)
URL - URL pointing to the DataBase file nameuserName - userNamepassWord - passwordpublic void setLoadMibsFromDatabase(boolean flag)
flag - booleaninitJdbcParams(java.lang.String, java.lang.String, java.lang.String, java.lang.String)public void setOverwriteMibsInDatabase(boolean overWrite)
public boolean isOverwriteMibsInDatabase()
public boolean isLoadMibsFromDatabase()
void initSnmpStore(SnmpTrapReceiver target)
protected void finalize()
throws java.lang.Throwable
public void releaseResources()
public void cleanup()
public void stop()
void genEvent(SnmpPDU pdu)
public java.lang.String[] getLocalAddresses()
public void setLocalAddresses(java.lang.String[] addresses)
public int getPort()
public void setPort(int i)
public int getPortWithExceptionMsg()
public void setPortWithExceptionMsg(int i)
throws SnmpException
public java.lang.String getCommunity()
public void setCommunity(java.lang.String s)
s - The community value to be set on this SnmpTrapReceiver.public void setCallbackthread(boolean flag)
flag - true flag enables the callbcak thread.public int getSnmpVersion()
public void setSnmpVersion(int version)
public boolean isTrapAuthEnable()
public void setV3AuthEnable(boolean v3auth)
v3auth - set this to False if v3 traps should be received without
authentication. True otherwise.public void setCommunityAuthEnable(boolean commauth)
commauth - set this to False if v1/v2 traps should be received without
authentication. True otherwise.public boolean isV3AuthEnabled()
public boolean isCommunityAuthEnabled()
public void setTrapAuthEnable(boolean isAuth)
isAuth - set this to False if traps should be received without
authentication. True otherwise.public java.lang.String getContextName()
public void setContextName(java.lang.String cName)
public java.lang.String getcontextID()
public void setcontextID(byte[] ctxtID)
public java.lang.String getContextID()
public void setContextID(byte[] ctxtID)
public int getSecurityModel()
public void setSecurityModel(int securityModel)
public java.lang.String getPrincipal()
public void setPrincipal(java.lang.String userName)
user - name.public int getAuthProtocol()
public void setAuthProtocol(int protocol)
the - number of the protocol.public java.lang.String getAuthPassword()
public void setAuthPassword(java.lang.String password)
public java.lang.String getPrivPassword()
public void setPrivPassword(java.lang.String password)
public void initSecurityProvider()
throws SnmpException
public java.lang.Object getSecurityTable(int secModel)
public boolean isSupportedSecurityModel(int secModel)
m - - The security model number which needs to be checked if it is supported.public USMUserTable getUSMTable()
public void createUserEntry(byte[] engineID,
byte secLevel)
engineID - - Engine ID of the usm user entry to be created.secLevel - - Security Level.public boolean isSetAutoInformResponse()
public void setAutoInformResponse(boolean flag)
flag - boolean value of the flag to be set.public void setCharacterEncoding(java.lang.String enc)
enc - The name of a character encoding. All the string encoding
will be done based on this encoding.public java.lang.String getCharacterEncoding()
void logErrorMessage(java.lang.String error)
void logInfoMessage(java.lang.String info)
public void setReceiveBufferSize(int size)
size - the size of the buffer.public int getReceiveBufferSize()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||