com.ireasoning.protocol.snmp
Class SnmpSession
java.lang.Object
com.ireasoning.protocol.ListenerManager
com.ireasoning.protocol.Session
com.ireasoning.protocol.snmp.SnmpBaseSession
com.ireasoning.protocol.snmp.SnmpSession
- All Implemented Interfaces:
- Serializable, State
- public class SnmpSession
- extends SnmpBaseSession
This class implements a session for sending/receiving snmp message.
By default, UDP is the underlying transport layer. But TCP transport layer is
also supported.
The snmp requests are retried if time out. The default retry times is 3, but is
configurable by using setRetries(int retries)
method.
Note:
Synchronous and asynchronous methods cannot be used together in one SnmpSession object.
For example, for an SnmpSession object session, if you already use session.asyncSnmpGetRequest(...),
another call to session.snmpGetRequest(...)
may not work correctly.
- See Also:
SnmpPdu
,
snmpget.java example,
Serialized Form
Fields inherited from class com.ireasoning.protocol.Session |
_localAddr, _localPort, _state, _target, _thread, _timeout, _transportLayer, _tries, DEFAULT_TIME_OUT, TCP, UDP |
Constructor Summary |
SnmpSession(SnmpTarget target)
Creates an SnmpSession using the default UDP protocol. |
SnmpSession(SnmpTarget target,
int transportLayer)
Constructs a new SnmpSession. |
SnmpSession(SnmpTarget target,
int transportLayer,
InetAddress localAddr,
int localPort)
Constructs a new SnmpSession. |
SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version)
Creates an SnmpSession |
SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version,
int transportLayer)
Creates an SnmpSession |
Method Summary |
void |
asyncSend(SnmpPdu pdu)
Used for asynchronous communication. |
SnmpPdu |
asyncSnmpGetBulkRequest(SnmpOID[] oids,
int nonRepeaters,
int maxRepetitions)
Issues SNMP GET_BULK command asynchronously |
SnmpPdu |
asyncSnmpGetBulkRequest(String[] oids,
int nonRepeaters,
int maxRepetitions)
Issues SNMP GET_BULK command asynchronously |
SnmpPdu |
asyncSnmpGetNextRequest(SnmpOID oid)
Issues SNMP GET_NEXT command asynchronously |
SnmpPdu |
asyncSnmpGetNextRequest(SnmpOID[] oids)
Issues SNMP GET_NEXT command asynchronously |
SnmpPdu |
asyncSnmpGetNextRequest(String oid)
Issues SNMP GET_NEXT command asynchronously |
SnmpPdu |
asyncSnmpGetNextRequest(String[] oids)
Issues SNMP GET_NEXT command asynchronously |
SnmpPdu |
asyncSnmpGetRequest(SnmpOID oid)
Issues SNMP GET command asynchronously |
SnmpPdu |
asyncSnmpGetRequest(SnmpOID[] oids)
Issues SNMP GET command asynchronously |
SnmpPdu |
asyncSnmpGetRequest(String oid)
Issues SNMP GET command asynchronously |
SnmpPdu |
asyncSnmpGetRequest(String[] oids)
Issues SNMP GET command asynchronously |
ArrayList |
broadcastDiscovery(SnmpOID oid)
Sends out an SNMP broadcast message without retries. |
void |
close()
close the session |
String |
getMibVersion()
Returns the mib version associated with this session |
TransportData |
getPduData(SnmpPdu pdu)
Gets the PDU data in byte array format |
SnmpEngine |
getSnmpV3Engine()
Returns the discovered SNMPv3 engine object. |
static SnmpEngine |
getSnmpV3EngineByDiscovery(SnmpSession session)
Gets the SNMPv3 engine info thru SNMPv3 discovery. |
UsmUser |
getSnmpV3User()
Returns the SNMPv3 USM user object. |
Target |
getTarget()
Returns the SnmpTarget object
that represents properties of remote agent. |
int |
getTimeoutForAsyncRequests()
|
Properties |
getV3Params()
Returns SNMPv3 parameters in a Properties . |
int |
getVersion()
Returns the SNMP version number supported in this session |
static void |
loadMib(String mibFileName)
Loads mib file, so MIB node name can also be used besides numeric OID. |
static void |
loadMib(String mibFileName,
boolean isStrict)
Loads mib file, so MIB node name can also be used besides numeric OID. |
static void |
loadMib(String mibFileName,
boolean isStrict,
String mibVersion)
Loads mib file, so MIB node name can also be used besides numeric OID. |
static void |
loadMib(String mibFileName,
String mibVersion)
Loads mib file, so MIB node name can also be used besides numeric OID. |
static void |
loadMib2()
Loads MIB-II (RFC1213) from the built-in resource file. |
static void |
loadMibs(String[] fileNames,
boolean isStrict,
String mibVersion)
Loads multiple MIB files. |
static void |
loadMibs(String[] fileNames,
String mibVersion)
Loads multiple MIB files. |
static MibTreeNode |
parseMib(String fileName)
Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree. |
static MibTreeNode |
parseMib(String fileName,
boolean isStrict)
Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree. |
static MibTreeNode[] |
parseMibsWithoutMerge(String[] fileNames)
Parses passed MIB files strictly. |
static MibTreeNode[] |
parseMibsWithoutMerge(String[] fileNames,
boolean isStrict)
Parses passed MIB files. |
protected Object |
receiveObject()
Callback method, it gets called when a new packet is received |
SnmpPdu |
send(SnmpPdu pdu)
Sends out SnmpPdu, it blocks until response comes back. |
protected void |
sendPdu(SnmpPdu pdu,
boolean addToReqMap)
Sends out PDU |
void |
setMibVersion(String mibVersion)
Associates this SNMP session with the passed mibVersion . |
boolean |
setSnmpV3Engine(SnmpEngine engine)
Sets SNMPv3 engine, so that SNMPv3 discovery won't occur and the session will use the
passed engine object to communicate with SNMPv3 agent. |
void |
setTarget(SnmpTarget target)
Sets a new target |
void |
setTarget(Target target)
Sets a new target |
void |
setTimeout(int timeout)
Sets time out value of underlying Socket of synchronous requests. |
void |
setTimeoutForAsyncRequests(int timeout)
Set timeout value for asynchronous requests. |
static void |
setToUseJCE(boolean b)
Choose to use SUN JCE for SNMPv3 encryption |
void |
setV3Params(String userName,
String authProtocol,
int privProtocol,
byte[] authKey,
byte[] privKey,
String contextName,
byte[] contextEngineID)
Sets SNMPV3 USM user information if you know localized authentication and privacy keys. |
void |
setV3Params(String userName,
String authProtocol,
String authPassword,
int privProtocol,
String privPassword)
Sets SNMPV3 USM user information, assuming empty contextName ("") and
contextEngineID ( zero length byte array, that is, 'new byte[0]') . |
void |
setV3Params(String userName,
String authProtocol,
String authPassword,
int privProtocol,
String privPassword,
String contextName,
byte[] contextEngineID)
Sets SNMPV3 USM user information. |
void |
setV3Params(String userName,
String authProtocol,
String authPassword,
int privProtocol,
String privPassword,
String contextName,
byte[] contextEngineID,
boolean keyExpansionWithEngineID)
Sets SNMPV3 USM user information. |
void |
setV3Params(String userName,
String authProtocol,
String authPassword,
String privPassword)
Sets SNMPV3 USM user information, assuming empty contextName ("") and
contextEngineID ( zero length byte array, that is, 'new byte[0]') . |
void |
setV3Params(String userName,
String authProtocol,
String authPassword,
String privPassword,
String contextName,
byte[] contextEngineID)
Sets SNMPV3 USM user information. |
void |
setVerifyAddress(boolean verify)
|
void |
setVersion(int version)
Sets the SNMP version number supported in this session |
void |
snmpBulkGetSubtree(SnmpOID startingOID,
Listener listener)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously. |
void |
snmpBulkGetSubtree(SnmpOID startingOID,
Listener listener,
int maxRepetitions)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously. |
void |
snmpBulkGetSubtree(String startingOID,
Listener listener)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously. |
void |
snmpBulkWalk(SnmpOID startingOID,
Listener listener)
Uses SNMPV2 GET_BULK requests to query a network entity efficiently for a tree of information asynchronously. |
void |
snmpBulkWalk(String startingOID,
Listener listener)
Uses SNMPV2 GET_BULK requests to query a network entity efficiently for a tree of information asynchronously. |
SnmpPdu |
snmpGetBulkRequest(SnmpOID[] oids,
int nonRepeaters,
int maxRepetitions)
Issues SNMP GET_BULK command, it blocks until response comes back |
SnmpPdu |
snmpGetBulkRequest(String[] oids,
int nonRepeaters,
int maxRepetitions)
Issues SNMP GET_BULK command, it blocks until response comes back |
SnmpPdu |
snmpGetNextRequest(SnmpOID oid)
Issues SNMP GET command, it blocks until response comes back |
SnmpPdu |
snmpGetNextRequest(SnmpOID[] oids)
Issues SNMP GET command, it blocks until response comes back |
SnmpPdu |
snmpGetNextRequest(String oid)
Issues SNMP GET command, it blocks until response comes back |
SnmpPdu |
snmpGetNextRequest(String[] oids)
Issues SNMP GET command, it blocks until response comes back |
SnmpPdu |
snmpGetRequest(SnmpOID oid)
Issues SNMP GET command, it blocks until response comes back |
SnmpPdu |
snmpGetRequest(SnmpOID[] oids)
Issues SNMP GET command, it blocks until response comes back |
void |
snmpGetRequest(SnmpOID start,
SnmpOID end,
Listener listener)
Synchronous request to retrieve all instances between passed start
and end |
SnmpPdu |
snmpGetRequest(String oid)
Issues SNMP GET command, it blocks until response comes back |
SnmpPdu |
snmpGetRequest(String[] oids)
Issues SNMP GET command, it blocks until response comes back |
SnmpVarBind[] |
snmpGetSubtree(SnmpOID startingOID)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data. |
void |
snmpGetSubtree(SnmpOID startingOID,
Listener listener)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously. |
SnmpVarBind[] |
snmpGetSubtree(SnmpOID startingOID,
SnmpError error)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data. |
SnmpVarBind[] |
snmpGetSubtree(String startingOID)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data. |
void |
snmpGetSubtree(String startingOID,
Listener listener)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously. |
SnmpVarBind[] |
snmpGetSubtree(String startingOID,
SnmpError error)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data. |
boolean |
snmpGetTable(MibTreeNode tableNode,
SnmpTableModel model,
int maxVarBindCount)
Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data |
SnmpTableModel |
snmpGetTable(String tableName)
Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data |
SnmpTableModel |
snmpGetTable(String tableName,
int maxVarBindCount)
Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data |
boolean |
snmpGetTable(String tableName,
SnmpTableModel model)
Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data |
boolean |
snmpGetTable(String tableName,
SnmpTableModel model,
int maxVarBindCount)
Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data |
SnmpVarBind[] |
snmpGetTableColumn(SnmpOID columnOID)
Returns the values of passed table column. |
SnmpVarBind[] |
snmpGetTableColumn(String columnName)
Returns the values of passed table column. |
SnmpVarBind[] |
snmpGetTableColumn(String columnName,
SnmpError error)
Returns the values of passed table column. |
SnmpPdu |
snmpInformRequest(long sysUpTime,
SnmpOID snmpTrapOID,
SnmpVarBind[] vbs)
Sends SNMPv2c/v3 INFORM request to the remote trap receiver.
Note:
The default port for sending inform requests (162) is not the same used
for the GET, GET_NEXT, SET etc... |
SnmpPdu |
snmpSetRequest(SnmpPdu pdu)
Issues SNMP SET command, it blocks until response comes back |
SnmpPdu |
snmpSetRequest(SnmpVarBind varbind)
Issues SNMP SET command, it blocks until response comes back |
void |
snmpWalk(SnmpOID startingOID,
Listener listener)
This method does SNMP walk, starting from the startingOID, walk through
the MIBs until end of mib view is reached. |
void |
snmpWalk(String startingOID,
Listener listener)
This method does SNMP walk, starting from the startingOID, walk through
the MIBs until end of mib view is reached. |
static void |
unloadMib(String fileName)
Unloads MIB file |
void |
write(SnmpPdu pdu)
Similar to send(SnmpPdu) method, but it returns immediately and no wait for the response. |
Methods inherited from class com.ireasoning.protocol.snmp.SnmpBaseSession |
addEngine, addEngine, lookupEngine, lookupEngine, lookupEngine, lookupUsmUser, removeEngine, removeEngine, removeEngine, removeEngine, removeUsmUser |
Methods inherited from class com.ireasoning.protocol.Session |
finalize, getRetries, getState, getStateString, getTimeout, getTransportLayer, getTransportLayer, open, open, open, reopen, setRetries, setTransportLayer, setTransportLayer, startThread |
SnmpSession
public SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version)
throws IOException
- Creates an SnmpSession
- Parameters:
hostname
- host name or ip address of snmp agentport
- port number of snmp agentreadCommunity
- community name for snmp read operations, such as GET, GET_NEXT, GET_BULK, INFORM. It does not matter if this is a SNMPv3 sessionwriteCommunity
- community name for snmp write operation (SNMP SET). It does not matter if this is a SNMPv3 sessionversion
- the snmp version supported by agent, one of { SnmpConst.SNMPV1, SnmpConst.SNMPV2, SnmpConst.SNMPV3 }, whose values are {0, 1, 3}
- Throws:
IOException
- raised if can't connect to agent
IllegalArgumentException
- raised if any of passed arguments is invalid
SnmpSession
public SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version,
int transportLayer)
throws IOException
- Creates an SnmpSession
- Parameters:
hostname
- host name or ip address of snmp agentport
- port number of snmp agentreadCommunity
- community name for snmp read operations, such as GET, GET_NEXT, GET_BULK, INFORM. It does not matter if this is a SNMPv3 sessionwriteCommunity
- community name for snmp write operation (SNMP SET). It does not matter if this is a SNMPv3 sessionversion
- the snmp version supported by agent, one of { SnmpConst.SNMPV1, SnmpConst.SNMPV2, SnmpConst.SNMPV3 }, whose values are {0, 1, 3}transportLayer
- the transport layer to use. UDP is the
default. Possible values are {Session.TCP, Session.UDP}
- Throws:
IOException
- raised if can't connect to agent
IllegalArgumentException
- raised if any of passed arguments is invalid
SnmpSession
public SnmpSession(SnmpTarget target,
int transportLayer)
throws IOException
- Constructs a new SnmpSession.
- Parameters:
target
- an instance contains agent's properties, such as host name,
port number, community name, snmp version number.transportLayer
- the transport layer to use. UDP is the
default. Possible values are {Session.TCP, Session.UDP}
- Throws:
IOException
- raised if can't connect to agent
SnmpSession
public SnmpSession(SnmpTarget target,
int transportLayer,
InetAddress localAddr,
int localPort)
throws IOException
- Constructs a new SnmpSession.
- Parameters:
target
- an instance contains agent's properties, such as host name,
port number, community name, snmp version number.transportLayer
- the transport layer to use. UDP is the
default. Possible values are {Session.TCP, Session.UDP}localAddr
- the local address the socket is bound to. If the IP address is 0.0.0.0, the socket will be bound to the wildcard address, an IP address chosen by the kernel.localPort
- the local port the socket is bound to. The local port must be between 0 and 65535 inclusive.
- Throws:
IOException
- raised if can't connect to agent
SnmpSession
public SnmpSession(SnmpTarget target)
throws IOException
- Creates an SnmpSession using the default UDP protocol.
- Parameters:
target
- a object contains agent's properties, such as host name,
port number, community name.
- Throws:
IOException
- raised if can't connect to agent
setMibVersion
public void setMibVersion(String mibVersion)
- Associates this SNMP session with the passed
mibVersion
. It's only necessary
when you need to load multiple versions of one MIB.
- Parameters:
mibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
getMibVersion
public String getMibVersion()
- Returns the mib version associated with this session
loadMib
public static void loadMib(String mibFileName,
String mibVersion)
throws IOException,
ParseException
- Loads mib file, so MIB node name can also be used besides numeric OID. It's equivalent to calling
MibUtil.loadMib
method. This method is the same as loadMib(mibFileName, true)
Note: It's a static method, so a MIB only needs to be loaded once in a JVM.
- Parameters:
mibFileName
- mib file name. If this file is already loaded, nothing happensmibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.
- Throws:
IOException
- raised if mib file not found
ParseException
- raised if mib file is corrupted- See Also:
MibUtil.loadMib(java.lang.String)
,
setMibVersion(java.lang.String)
,
loadMib2()
loadMib
public static void loadMib(String mibFileName)
throws IOException,
ParseException
- Loads mib file, so MIB node name can also be used besides numeric OID. It's equivalent to calling
MibUtil.loadMib
method. This method is the same as loadMib(mibFileName, true)
Note: It's a static method, so a MIB only needs to be loaded once in a JVM.
- Parameters:
mibFileName
- mib file name. If this file is already loaded, nothing happens
- Throws:
IOException
- raised if mib file not found
ParseException
- raised if mib file is corrupted- See Also:
MibUtil.loadMib(java.lang.String)
,
setMibVersion(java.lang.String)
,
loadMib2()
loadMib
public static void loadMib(String mibFileName,
boolean isStrict,
String mibVersion)
throws IOException,
ParseException
- Loads mib file, so MIB node name can also be used besides numeric OID. It's equivalent to calling
MibUtil.loadMib
method.
Note: It's a static method, so a MIB only needs to be loaded once in a JVM.
- Parameters:
mibFileName
- mib file name. If this file is already loaded, nothing happensisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filemibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.
- Throws:
IOException
- raised if mib file not found
ParseException
- raised if mib file is corrupted- See Also:
MibUtil.loadMib(java.lang.String)
,
setMibVersion(java.lang.String)
,
loadMib2()
loadMib
public static void loadMib(String mibFileName,
boolean isStrict)
throws IOException,
ParseException
- Loads mib file, so MIB node name can also be used besides numeric OID. It's equivalent to calling
MibUtil.loadMib
method.
Note: It's a static method, so a MIB only needs to be loaded once in a JVM.
- Parameters:
mibFileName
- mib file name. If this file is already loaded, nothing happensisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log file
- Throws:
IOException
- raised if mib file not found
ParseException
- raised if mib file is corrupted- See Also:
MibUtil.loadMib(java.lang.String)
,
loadMib2()
loadMib2
public static void loadMib2()
- Loads MIB-II (RFC1213) from the built-in resource file. It's equivalent to calling
MibUtil.loadMib2
method.
Note: It's a static method, so a MIB only needs to be loaded once in a JVM.
- See Also:
MibUtil.loadMib2()
,
loadMib(java.lang.String, java.lang.String)
loadMibs
public static void loadMibs(String[] fileNames,
String mibVersion)
throws IOException,
MibParseException
- Loads multiple MIB files.
- Parameters:
fileNames
- MIB file namesmibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.
- Throws:
IOException
MibParseException
- See Also:
loadMib(java.lang.String, java.lang.String)
loadMibs
public static void loadMibs(String[] fileNames,
boolean isStrict,
String mibVersion)
throws IOException,
MibParseException
- Loads multiple MIB files.
- Parameters:
fileNames
- MIB file namesisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log filemibVersion
- If you have multiple versions of a MIB module, this parameter is
used to distinguish different versions. It doesn't have to be the same as the actual
version number, but it has to be unique among all the MIBs with the same module name.
Use null
if only no multiple versions of a mib.
- Throws:
IOException
MibParseException
- See Also:
loadMib(java.lang.String, java.lang.String)
unloadMib
public static void unloadMib(String fileName)
- Unloads MIB file
- Parameters:
fileName
- mib file to unload. If this file was not loaded, nothing happens
parseMib
public static MibTreeNode parseMib(String fileName)
throws IOException,
MibParseException
- Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree.
The parser is capable of parsing both SMIv1 (SNMPv1) and SMIv2 (SNMPv2/v3) MIBs.
- Parameters:
fileName
- file name of the MIB
- Returns:
- root node
- Throws:
IOException
MibParseException
parseMib
public static MibTreeNode parseMib(String fileName,
boolean isStrict)
throws IOException,
MibParseException
- Returns the MIB tree representation in a MibTreeNode object, which is the root of the MIB tree.
The parser is capable of parsing both SMIv1 (SNMPv1) and SMIv2 (SNMPv2/v3) MIBs.
- Parameters:
fileName
- file name of the MIBisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log file
- Returns:
- root node
- Throws:
IOException
MibParseException
parseMibsWithoutMerge
public static MibTreeNode[] parseMibsWithoutMerge(String[] fileNames)
throws IOException,
MibParseException
- Parses passed MIB files strictly.
and returns tree representation for each of the MIBs. No merge of trees is performed.
- Parameters:
fileNames
- file names of the MIBs
- Returns:
- MibTreeNode array corresponding to the passed
fileNames
- Throws:
IOException
MibParseException
parseMibsWithoutMerge
public static MibTreeNode[] parseMibsWithoutMerge(String[] fileNames,
boolean isStrict)
throws IOException,
MibParseException
- Parses passed MIB files.
and returns tree representation for each of the MIBs. No merge of trees is performed.
- Parameters:
fileNames
- file names of the MIBsisStrict
- if true, MIB is parsed strictly, any error in MIB will raise exception. Otherwise only an error message is written to log file
- Returns:
- MibTreeNode array corresponding to the passed
fileNames
- Throws:
IOException
MibParseException
sendPdu
protected void sendPdu(SnmpPdu pdu,
boolean addToReqMap)
throws IOException
- Sends out PDU
- Parameters:
pdu
- pdu to be sentaddToReqMap
- true to add this pdu to the request ID map, which is used to
correlate request and respons. It should be true in asynchronous mode, false in
synchronous mode.
- Throws:
IOException
- raised if can't send data to remote host
getPduData
public TransportData getPduData(SnmpPdu pdu)
throws SnmpEncodingException
- Gets the PDU data in byte array format
- Parameters:
pdu
- PDU object to be converted to byte array
- Returns:
- PDU data in byte array format
- Throws:
SnmpEncodingException
- raised if PDU's data is corrupted
asyncSend
public void asyncSend(SnmpPdu pdu)
throws IOException
- Used for asynchronous communication. Caller needs call
addListener(Listener) first to register a listener object, then call this
method to send out PDU, a separate thread (only one thread) will notify listener later
about received PDU. It doesn't block after calling this method.
- Parameters:
pdu
- a pdu to be sent out.
- Throws:
IOException
- if socket is not valid.- See Also:
send(SnmpPdu)
,
snmpasyncget.java example
asyncSnmpGetRequest
public SnmpPdu asyncSnmpGetRequest(String oid)
throws IOException
- Issues SNMP GET command asynchronously
- Parameters:
oid
- the SNMP OID to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"),
it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- the request PDU object
- Throws:
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
IOException
- if socket is not valid.- See Also:
- snmpasyncget.java example,
asyncSend(SnmpPdu)
,
asyncSnmpGetRequest(SnmpOID)
,
asyncSnmpGetRequest(String[])
asyncSnmpGetRequest
public SnmpPdu asyncSnmpGetRequest(SnmpOID oid)
throws IOException
- Issues SNMP GET command asynchronously
- Parameters:
oid
- the SNMP OID to be sent to the agent
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.- See Also:
- snmpasyncget.java example,
asyncSend(SnmpPdu)
,
asyncSnmpGetRequest(String)
,
asyncSnmpGetRequest(SnmpOID[])
,
asyncSnmpGetRequest(String)
asyncSnmpGetRequest
public SnmpPdu asyncSnmpGetRequest(String[] oids)
throws IOException
- Issues SNMP GET command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved- See Also:
- snmpasyncget.java example
asyncSnmpGetRequest
public SnmpPdu asyncSnmpGetRequest(SnmpOID[] oids)
throws IOException
- Issues SNMP GET command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agent in one request
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.- See Also:
asyncSnmpGetRequest(SnmpOID)
,
asyncSnmpGetRequest(String[])
,
snmpasyncget.java example
asyncSnmpGetNextRequest
public SnmpPdu asyncSnmpGetNextRequest(String oid)
throws IOException
- Issues SNMP GET_NEXT command asynchronously
- Parameters:
oid
- the SNMP OID to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved- See Also:
asyncSnmpGetNextRequest(SnmpOID)
,
asyncSnmpGetNextRequest(String[])
asyncSnmpGetNextRequest
public SnmpPdu asyncSnmpGetNextRequest(SnmpOID oid)
throws IOException
- Issues SNMP GET_NEXT command asynchronously
- Parameters:
oid
- the SNMP OID to be sent to the agent
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.- See Also:
asyncSnmpGetNextRequest(SnmpOID[])
,
asyncSnmpGetNextRequest(String)
asyncSnmpGetNextRequest
public SnmpPdu asyncSnmpGetNextRequest(String[] oids)
throws IOException
- Issues SNMP GET_NEXT command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
asyncSnmpGetNextRequest
public SnmpPdu asyncSnmpGetNextRequest(SnmpOID[] oids)
throws IOException
- Issues SNMP GET_NEXT command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agent in one request
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.- See Also:
asyncSnmpGetNextRequest(SnmpOID)
,
asyncSnmpGetNextRequest(String[])
asyncSnmpGetBulkRequest
public SnmpPdu asyncSnmpGetBulkRequest(String[] oids,
int nonRepeaters,
int maxRepetitions)
throws IOException
- Issues SNMP GET_BULK command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.nonRepeaters
- - Number of variable bindings to get one time.maxRepetitions
- - Number of repetitions for the variable bindings to get multiple times.
- Returns:
- the request PDU object
- Throws:
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
IOException
- if socket is not valid.
asyncSnmpGetBulkRequest
public SnmpPdu asyncSnmpGetBulkRequest(SnmpOID[] oids,
int nonRepeaters,
int maxRepetitions)
throws IOException
- Issues SNMP GET_BULK command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agentnonRepeaters
- - Number of variable bindings to get one time.maxRepetitions
- - Number of repetitions for the variable bindings to get multiple times.
- Returns:
- the request PDU object
- Throws:
IOException
- if socket is not valid.
write
public void write(SnmpPdu pdu)
throws IOException
- Similar to send(SnmpPdu) method, but it returns immediately and no wait for the response.
- Throws:
IOException
- if socket is not valid.- See Also:
send(SnmpPdu)
receiveObject
protected Object receiveObject()
throws IOException
- Callback method, it gets called when a new packet is received
- Overrides:
receiveObject
in class SnmpBaseSession
- Returns:
- an SnmpDataType object representing received data
- Throws:
IOException
send
public SnmpPdu send(SnmpPdu pdu)
throws IOException
- Sends out SnmpPdu, it blocks until response comes back. If you do not
care about the response,
write(SnmpPdu)
method is
a better choice.
- Parameters:
pdu
- the SnmpPdu to be sent
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException
is a subclass of IOException)- See Also:
write(SnmpPdu)
,
asyncSend(com.ireasoning.protocol.snmp.SnmpPdu)
setVerifyAddress
public void setVerifyAddress(boolean verify)
- Parameters:
verify
- if true, received PDU's source address will be checked to match the target's address.
The default behavior is not to verify.
snmpGetRequest
public SnmpPdu snmpGetRequest(String oid)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oid
- the SNMP OID to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved- See Also:
snmpGetRequest(SnmpOID)
,
snmpGetRequest(String[])
,
snmpget.java example
snmpGetRequest
public SnmpPdu snmpGetRequest(SnmpOID oid)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oid
- the SNMP OID to be sent to the agent
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetRequest(SnmpOID[])
,
snmpGetRequest(String)
,
snmpget.java example
snmpGetRequest
public SnmpPdu snmpGetRequest(String[] oids)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oids
- the SNMP OIDs to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved- See Also:
- snmpget.java example
snmpGetRequest
public SnmpPdu snmpGetRequest(SnmpOID[] oids)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oids
- the SNMP OIDs to be sent to the agent in one request
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetRequest(SnmpOID)
,
snmpGetRequest(String[])
,
snmpget.java example
snmpGetRequest
public void snmpGetRequest(SnmpOID start,
SnmpOID end,
Listener listener)
throws IOException
- Synchronous request to retrieve all instances between passed
start
and end
- Parameters:
start
- the starting oid, inclusive. null
is not allowed.end
- the ending index, exclusive. If it is null
, end-of-mib is used instead.listener
- a callback interface to be informed when a PDU is
received. The msg
passed to handleMsg method is an instance of SnmpPdu
object.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved- See Also:
Listener.handleMsg(java.lang.Object, com.ireasoning.protocol.Msg)
,
snmpget.java example
snmpGetNextRequest
public SnmpPdu snmpGetNextRequest(String oid)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oid
- the SNMP OID to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved- See Also:
snmpGetNextRequest(SnmpOID)
,
snmpGetNextRequest(String[])
,
snmpgetnext.java example
snmpGetNextRequest
public SnmpPdu snmpGetNextRequest(SnmpOID oid)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oid
- the SNMP OID to be sent to the agent
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetNextRequest(String)
,
snmpGetNextRequest(SnmpOID[])
,
snmpgetnext.java example
snmpGetNextRequest
public SnmpPdu snmpGetNextRequest(String[] oids)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oids
- the SNMP OIDs to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetNextRequest(SnmpOID[])
,
snmpGetNextRequest(String)
,
snmpgetnext.java example
snmpGetNextRequest
public SnmpPdu snmpGetNextRequest(SnmpOID[] oids)
throws IOException
- Issues SNMP GET command, it blocks until response comes back
- Parameters:
oids
- the SNMP OIDs to be sent to the agent in one request
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetNextRequest(String[])
,
snmpGetNextRequest(SnmpOID)
,
snmpgetnext.java example
snmpSetRequest
public SnmpPdu snmpSetRequest(SnmpVarBind varbind)
throws IOException
- Issues SNMP SET command, it blocks until response comes back
- Parameters:
varbind
- the variable binding of the SET request
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
snmpSetRequest
public SnmpPdu snmpSetRequest(SnmpPdu pdu)
throws IOException
- Issues SNMP SET command, it blocks until response comes back
- Parameters:
pdu
- the SNMP pdu to be sent
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
snmpGetBulkRequest
public SnmpPdu snmpGetBulkRequest(String[] oids,
int nonRepeaters,
int maxRepetitions)
throws IOException
- Issues SNMP GET_BULK command, it blocks until response comes back
- Parameters:
oids
- the SNMP OIDs to be sent to the agent. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.nonRepeaters
- - Number of variable bindings to get one time.maxRepetitions
- - Number of repetitions for the variable bindings to get multiple times.
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
- snmpgetbulk.java example
snmpGetBulkRequest
public SnmpPdu snmpGetBulkRequest(SnmpOID[] oids,
int nonRepeaters,
int maxRepetitions)
throws IOException
- Issues SNMP GET_BULK command, it blocks until response comes back
- Parameters:
oids
- the SNMP OIDs to be sent to the agentnonRepeaters
- Number of variable bindings to get one time.maxRepetitions
- Number of repetitions for the variable bindings to get multiple times.
- Returns:
- SnmpPdu the response corresponding to the request
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
- snmpgetbulk.java example
snmpWalk
public void snmpWalk(String startingOID,
Listener listener)
throws IOException
- This method does SNMP walk, starting from the startingOID, walk through
the MIBs until end of mib view is reached.
- Parameters:
startingOID
- the oid to start with. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.listener
- a callback interface to be informed when a PDU is
received. The msg
passed to handleMsg method is an instance of SnmpPdu
object.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
Listener.handleMsg(java.lang.Object, com.ireasoning.protocol.Msg)
,
snmpwalk.java example
snmpWalk
public void snmpWalk(SnmpOID startingOID,
Listener listener)
throws IOException
- This method does SNMP walk, starting from the startingOID, walk through
the MIBs until end of mib view is reached.
- Parameters:
startingOID
- the oid to start withlistener
- a callback interface to be informed when a PDU is
received. The msg
passed to handleMsg method is an instance of SnmpPdu
object.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
Listener.handleMsg(java.lang.Object, com.ireasoning.protocol.Msg)
,
snmpwalk.java example
snmpBulkWalk
public void snmpBulkWalk(String startingOID,
Listener listener)
throws IOException
- Uses SNMPV2 GET_BULK requests to query a network entity efficiently for a tree of information asynchronously.
(Note: it works only if agent support GET_BULK operation)
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpWalk(String, Listener)
,
snmpbulkwalk.java example
snmpBulkWalk
public void snmpBulkWalk(SnmpOID startingOID,
Listener listener)
throws IOException
- Uses SNMPV2 GET_BULK requests to query a network entity efficiently for a tree of information asynchronously.
(Note: it works only if agent support GET_BULK operation)
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpWalk(SnmpOID, Listener)
,
snmpbulkwalk.java example
snmpGetSubtree
public void snmpGetSubtree(String startingOID,
Listener listener)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
- Parameters:
startingOID
- the oid to start with. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.listener
- a callback interface to be informed when a PDU is
received. The msg
passed to handleMsg method is an instance of SnmpPdu
object.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
Listener.handleMsg(java.lang.Object, com.ireasoning.protocol.Msg)
,
snmpgetsubtree.java example
snmpGetSubtree
public void snmpGetSubtree(SnmpOID startingOID,
Listener listener)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
- Parameters:
startingOID
- the oid to start withlistener
- a callback interface to be informed when a PDU is received. The msg
passed to handleMsg method is an instance of SnmpPdu
object.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
Listener.handleMsg(java.lang.Object, com.ireasoning.protocol.Msg)
,
snmpgetsubtree.java example
snmpBulkGetSubtree
public void snmpBulkGetSubtree(String startingOID,
Listener listener)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
This method differs from snmpGetSubtree in that it uses GET_BULK SNMP query.
(Note: it works only if agent supports GET_BULK operation)
- Parameters:
startingOID
- the oid to start with. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.listener
- a callback interface to be informed when a PDU is received
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetSubtree(String, Listener)
,
snmpbulkgetsubtree.java example
snmpBulkGetSubtree
public void snmpBulkGetSubtree(SnmpOID startingOID,
Listener listener)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
This method differs from snmpGetSubtree in that it uses GET_BULK SNMP query.
(Note: it works only if agent support GET_BULK operation)
- Parameters:
listener
- a callback interface to be informed when a PDU is received
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetSubtree(SnmpOID, Listener)
,
snmpbulkgetsubtree.java example
snmpBulkGetSubtree
public void snmpBulkGetSubtree(SnmpOID startingOID,
Listener listener,
int maxRepetitions)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data asynchronously.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
This method differs from snmpGetSubtree in that it uses GET_BULK SNMP query.
(Note: it works only if agent support GET_BULK operation)
- Parameters:
listener
- a callback interface to be informed when a PDU is receivedmaxRepetitions
- Number of repetitions for the variable bindings to get multiple times.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
snmpGetSubtree(SnmpOID, Listener)
,
snmpbulkgetsubtree.java example
snmpGetSubtree
public SnmpVarBind[] snmpGetSubtree(String startingOID)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
- Parameters:
startingOID
- the oid to start with. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.
- Returns:
- received SnmpVarBind array. An empty array if no data received.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
- snmpgetsubtree.java example
snmpGetSubtree
public SnmpVarBind[] snmpGetSubtree(String startingOID,
SnmpError error)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
- Parameters:
startingOID
- the oid to start with. If it's a MIB node name (such as "sysUpTime", "ifAdminStatus.2"), it'll be converted to SnmpOID first if corresponding MIB file has been loaded by calling loadMib method.error
- an SnmpError object that will be used to store error info if any
- Returns:
- received SnmpVarBind array. An empty array if no data received.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolved
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
- snmpgetsubtree.java example
snmpGetSubtree
public SnmpVarBind[] snmpGetSubtree(SnmpOID startingOID)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
- Parameters:
startingOID
- the oid to start with
- Returns:
- received SnmpVarBind array. An empty array if no data received.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
- snmpgetsubtree.java example
snmpGetSubtree
public SnmpVarBind[] snmpGetSubtree(SnmpOID startingOID,
SnmpError error)
throws IOException
- The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data.
It first specifies the root of the subtree to be retrieved (it can be rooted anywhere at the head of
a table, a specific column, a mib group etc.) and then retrieve all MIB objects under that root.
- Parameters:
startingOID
- the oid to start witherror
- an SnmpError object that will be used to store error info if any. For SNMPv3, you can use
error.isAuthFailed() to check if authentication already failed.
- Returns:
- received SnmpVarBind array. An empty array if no data received.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)- See Also:
- snmpgetsubtree.java example
snmpGetTable
public boolean snmpGetTable(String tableName,
SnmpTableModel model)
throws IOException
- Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data
- Parameters:
tableName
- table name or oid, such as "ifTable", "interfaces.ifTable", ".1.3.6.1.2.1.2.2"model
- an instance of SnmpTableModel or its sub class. This instance will be filled with
the result of SNMP queries when method returns
- Returns:
- false if tableName cannot be resolved (not found in loaded MIBs); true otherwise
- Throws:
IllegalArgumentException
- if passed table name or oid cannot be resolved
IOException
- See Also:
- snmpgettable.java example,
snmpGetTableColumn(String tableName)
,
loadMib(java.lang.String, java.lang.String)
snmpGetTable
public boolean snmpGetTable(String tableName,
SnmpTableModel model,
int maxVarBindCount)
throws IOException
- Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data
- Parameters:
tableName
- table name or oid, such as "ifTable", "interfaces.ifTable", ".1.3.6.1.2.1.2.2"model
- an instance of SnmpTableModel or its sub class. This instance will be filled with
the result of SNMP queries when method returnsmaxVarBindCount
- the maximum number of variable bindings to be sent in a SNMP PDU. Default value is -1 (unlimited).
- Returns:
- false if tableName cannot be resolved (not found in loaded MIBs); true otherwise
- Throws:
IllegalArgumentException
- if passed table name or oid cannot be resolved
IOException
- See Also:
- snmpgettable.java example,
snmpGetTableColumn(String tableName)
,
loadMib(java.lang.String, java.lang.String)
snmpGetTable
public boolean snmpGetTable(MibTreeNode tableNode,
SnmpTableModel model,
int maxVarBindCount)
throws IOException
- Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data
- Parameters:
tableNode
- MIB table node objectmodel
- an instance of SnmpTableModel or its sub class. This instance will be filled with
the result of SNMP queries when method returnsmaxVarBindCount
- the maximum number of variable bindings to be sent in a SNMP PDU. Default value is -1 (unlimited).
- Returns:
- false if tableName cannot be resolved (not found in loaded MIBs); true otherwise
- Throws:
IllegalArgumentException
- if passed table name or oid cannot be resolved
IOException
- See Also:
- snmpgettable.java example,
snmpGetTableColumn(String tableName)
,
loadMib(java.lang.String, java.lang.String)
snmpGetTable
public SnmpTableModel snmpGetTable(String tableName)
throws IOException
- Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data
- Parameters:
tableName
- table name or oid, such as "ifTable", "interfaces.ifTable", ".1.3.6.1.2.1.2.2"
- Returns:
- an instance of SnmpTableModel, or null if passed tableName is not found in MIB
(Make sure loadMib method is called beforehand).
- Throws:
IllegalArgumentException
- raised if passed oid can not be translated into table name
IOException
- See Also:
- snmpgettable.java example,
snmpGetTable(String tableName, SnmpTableModel model)
,
loadMib(java.lang.String, java.lang.String)
snmpGetTable
public SnmpTableModel snmpGetTable(String tableName,
int maxVarBindCount)
throws IOException
- Gets whole MIB table and returns an SnmpTableModel object which contains retrieved data
- Parameters:
tableName
- table name or oid, such as "ifTable", "interfaces.ifTable", ".1.3.6.1.2.1.2.2"maxVarBindCount
- the maximum number of variable bindings to be sent in a SNMP PDU. Default value is -1 (unlimited).
- Returns:
- an instance of SnmpTableModel, or null if passed tableName is not found in MIB
(Make sure loadMib method is called beforehand).
- Throws:
IllegalArgumentException
- raised if passed oid can not be translated into table name
IOException
- See Also:
- snmpgettable.java example,
snmpGetTable(String tableName, SnmpTableModel model)
,
loadMib(java.lang.String, java.lang.String)
snmpGetTableColumn
public SnmpVarBind[] snmpGetTableColumn(SnmpOID columnOID)
throws IOException
- Returns the values of passed table column. For example, if passed columnOID is ".1.3.6.1.2.1.2.2.1.5" (ifSpeed),
it returns values of all instances of ifSpeed.
- Parameters:
columnOID
- column OID, such as ".1.3.6.1.2.1.2.2.1.5" (ifSpeed)
- Returns:
- the SnmpVarBind array of column's instances. Or null if passed columnName can't be translated to OID (if MIB file is
not loaded by calling loadMib method)
- Throws:
IOException
- See Also:
loadMib(java.lang.String, java.lang.String)
snmpGetTableColumn
public SnmpVarBind[] snmpGetTableColumn(String columnName)
throws IOException
- Returns the values of passed table column. For example, if passed columnName is "ifSpeed",
it returns values of all instances of ifSpeed.
- Parameters:
columnName
- column name, such as "ifSpeed"
error.isAuthFailed() to check if authentication already failed.
- Returns:
- the SnmpVarBind array of column's instances. Or null if passed columnName can't be translated to OID (if MIB file is
not loaded by calling loadMib method)
- Throws:
IOException
- See Also:
loadMib(java.lang.String, java.lang.String)
snmpGetTableColumn
public SnmpVarBind[] snmpGetTableColumn(String columnName,
SnmpError error)
throws IOException
- Returns the values of passed table column. For example, if passed columnName is "ifSpeed",
it returns values of all instances of ifSpeed.
- Parameters:
columnName
- column name, such as "ifSpeed"
- Returns:
- the SnmpVarBind array of column's instances. Or null if passed columnName can't be translated to OID (if MIB file is
not loaded by calling loadMib method)
- Throws:
IOException
- See Also:
loadMib(java.lang.String, java.lang.String)
snmpInformRequest
public SnmpPdu snmpInformRequest(long sysUpTime,
SnmpOID snmpTrapOID,
SnmpVarBind[] vbs)
throws IOException
- Sends SNMPv2c/v3 INFORM request to the remote trap receiver.
Note:
The default port for sending inform requests (162) is not the same used
for the GET, GET_NEXT, SET etc... operations (161).
So a different SnmpSession should be used for this method.
- Parameters:
sysUpTime
- sysUpTime valuesnmpTrapOID
- The SnmpOID of snmpTrapOID objectvbs
- An array of SnmpVarBind objects, other than sysUpTime and
snmpTrapOID. Use null if no vbs to be added.
- Throws:
IOException
- if time out (after retries) or socket is not valid.
TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
setTarget
public void setTarget(Target target)
- Sets a new target
- Overrides:
setTarget
in class Session
- Parameters:
target
- new target object
setTarget
public void setTarget(SnmpTarget target)
- Sets a new target
- Parameters:
target
- new target object
setTimeout
public void setTimeout(int timeout)
throws SocketException
- Sets time out value of underlying Socket of synchronous requests. Default value is 60 seconds.
setTimeoutForAsyncRequests
should
be used for asynchronous requests.
- Overrides:
setTimeout
in class Session
- Parameters:
timeout
- the specified timeout in milliseconds. A timeout of zero is interpreted as an infinite timeout.
- Throws:
SocketException
- See Also:
- java.net.Socket.setSoTimeout(int),
setTimeoutForAsyncRequests(int)
setTimeoutForAsyncRequests
public void setTimeoutForAsyncRequests(int timeout)
- Set timeout value for asynchronous requests. Default value is 60 seconds.
When time out occurs, the listener's handleMsg
method will receive a TimeoutErrorMsg
message.
- Parameters:
timeout
- the specified timeout in milliseconds. A timeout of zero is interpreted as an infinite timeout.- See Also:
setTimeout(int)
getTimeoutForAsyncRequests
public int getTimeoutForAsyncRequests()
setV3Params
public void setV3Params(String userName,
String authProtocol,
String authPassword,
String privPassword)
- Sets SNMPV3 USM user information, assuming empty contextName ("") and
contextEngineID ( zero length byte array, that is, 'new byte[0]') . If setV3Params was called before, this call will remove
old user information. authoritativeEngineID and engineTime will be obtained automatically through discovery.
Security level is determined by the passed authPassword and privPassword, if both of them are null or empty
strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv.
If both of them are non-empty strings, security level is authPriv.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}, which one to use is determined by the authentication protocol agent usesauthPassword
- authentication password. It will be used to generate localized authentication key.privPassword
- privacy protocol password. It will be used to generate localized privacy key.- Since:
- SnmpV3
- See Also:
setV3Params(String userName, String authProtocol, String authPassword, String privPassword, String contextName, byte[] contextEngineID)
setV3Params
public void setV3Params(String userName,
String authProtocol,
String authPassword,
int privProtocol,
String privPassword)
- Sets SNMPV3 USM user information, assuming empty contextName ("") and
contextEngineID ( zero length byte array, that is, 'new byte[0]') . If setV3Params was called before, this call will remove
old user information. authoritativeEngineID and engineTime will be obtained automatically through discovery.
Security level is determined by the passed authPassword and privPassword, if both of them are null or empty
strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv.
If both of them are non-empty strings, security level is authPriv.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}, which one to use is determined by the authentication protocol agent usesauthPassword
- authentication password. It will be used to generate localized authentication key.privProtocol
- privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DESprivPassword
- privacy protocol password. It will be used to generate localized privacy key.- Since:
- SnmpV3
- See Also:
setV3Params(String userName, String authProtocol, String authPassword, String privPassword, String contextName, byte[] contextEngineID)
setV3Params
public void setV3Params(String userName,
String authProtocol,
String authPassword,
String privPassword,
String contextName,
byte[] contextEngineID)
- Sets SNMPV3 USM user information. If setV3Params was called before,
this call will remove old user information. authoritativeEngineID and engineTime will be obtained automatically through discovery.
Security level is determined by the passed authPassword and privPassword, if both of them are null or empty
strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv.
If both of them are non-empty strings, security level is authPriv.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}, which one to use is determined by the authentication protocol agent usesauthPassword
- authentication password. It will be used to generate localized authentication key.privPassword
- privacy protocol password. It will be used to generate localized privacy key.contextName
- context name. Contexts are used to identify subsets of objects,
within the scope of an engine, a contextName refers to a particular subset within an engine.
If you want to change context name for a SNMP request, you can use
SnmpPdu.setContextName() to change it for that PDU.contextEngineID
- context engine ID. Don't be confused with
authoritativeEngineID.- Since:
- SnmpV3
setV3Params
public void setV3Params(String userName,
String authProtocol,
String authPassword,
int privProtocol,
String privPassword,
String contextName,
byte[] contextEngineID)
- Sets SNMPV3 USM user information. If setV3Params was called before,
this call will remove old user information. authoritativeEngineID and engineTime will be obtained automatically through discovery.
Security level is determined by the passed authPassword and privPassword, if both of them are null or empty
strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv.
If both of them are non-empty strings, security level is authPriv.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}, which one to use is determined by the authentication protocol agent usesauthPassword
- authentication password. It will be used to generate localized authentication key.privProtocol
- privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DESprivPassword
- privacy protocol password. It will be used to generate localized privacy key.contextName
- context name. Contexts are used to identify subsets of objects,
within the scope of an engine, a contextName refers to a particular subset within an engine.
If you want to change context name for a SNMP request, you can use
SnmpPdu.setContextName() to change it for that PDU.contextEngineID
- context engine ID. Don't be confused with
authoritativeEngineID.- Since:
- SnmpV3
setV3Params
public void setV3Params(String userName,
String authProtocol,
String authPassword,
int privProtocol,
String privPassword,
String contextName,
byte[] contextEngineID,
boolean keyExpansionWithEngineID)
- Sets SNMPV3 USM user information. If setV3Params was called before,
this call will remove old user information. authoritativeEngineID and engineTime will be obtained automatically through discovery.
Security level is determined by the passed authPassword and privPassword, if both of them are null or empty
strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv.
If both of them are non-empty strings, security level is authPriv.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}, which one to use is determined by the authentication protocol agent usesauthPassword
- authentication password. It will be used to generate localized authentication key.privProtocol
- privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DESprivPassword
- privacy protocol password. It will be used to generate localized privacy key.contextName
- context name. Contexts are used to identify subsets of objects,
within the scope of an engine, a contextName refers to a particular subset within an engine.
If you want to change context name for a SNMP request, you can use
SnmpPdu.setContextName() to change it for that PDU.contextEngineID
- context engine ID. Don't be confused with
authoritativeEngineID.keyExpansionWithEngineID
- For AES 192 and 256, localized key will be expanded with the value of engineID.- Since:
- SnmpV3
setV3Params
public void setV3Params(String userName,
String authProtocol,
int privProtocol,
byte[] authKey,
byte[] privKey,
String contextName,
byte[] contextEngineID)
- Sets SNMPV3 USM user information if you know localized authentication and privacy keys. If setV3Params was called before,
this call will remove old user information. authoritativeEngineID and engineTime will be obtained automatically through discovery.
Security level is determined by the passed authPassword and privPassword, if both of them are null or empty
strings, security level is noAuthNoPriv. If privPassword is null or empty string, security level is authNoPriv.
If both of them are non-empty strings, security level is authPriv.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}, which one to use is determined by the authentication protocol agent usesprivProtocol
- privacy protocol. One of {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}. Default value is SnmpConst.DESauthKey
- localized authentication keyprivKey
- localized privacy keycontextName
- context name. Contexts are used to identify subsets of objects,
within the scope of an engine, a contextName refers to a particular subset within an engine.
If you want to change context name for a SNMP request, you can use
SnmpPdu.setContextName() to change it for that PDU.contextEngineID
- context engine ID. Don't be confused with
authoritativeEngineID.- Since:
- SnmpV3
getV3Params
public Properties getV3Params()
- Returns SNMPv3 parameters in a
Properties
.
Keys in Properties
are:
userName --- user name
authProtocol --- auth protocol. Its value is one of {SnmpConst.MD5, SnmpConst.SHA, SnmpConst.SHA224, SnmpConst.SHA256, SnmpConst.SHA384, SnmpConst.SHA512}
authPassword --- auth password
privProtocol --- priv protocol. Its value is String, one of "" + {SnmpConst.DES, SnmpConst.AES, SnmpConst.AES192, SnmpConst.AES256}
privPassword --- priv password
contextName --- context name
contextEngineID --- context engineID
The values of the Properties
are all String objects.
getSnmpV3Engine
public SnmpEngine getSnmpV3Engine()
- Returns the discovered SNMPv3 engine object. Null value if this session is not an SNMPv3 session.
getSnmpV3EngineByDiscovery
public static SnmpEngine getSnmpV3EngineByDiscovery(SnmpSession session)
throws IOException
- Gets the SNMPv3 engine info thru SNMPv3 discovery.
- Parameters:
session
- SnmpSession object to be used to issue SNMPv3 requests to get get SnmpEngine info.
SNMPv3 parameters must have been configured for the session object.
- Returns:
- SnmpEngine object by sending out SNMPv3 discovery packet. It's not thread-safe.
- Throws:
IOException
getSnmpV3User
public UsmUser getSnmpV3User()
- Returns the SNMPv3 USM user object. Null value if this session is not an SNMPv3 session.
setSnmpV3Engine
public boolean setSnmpV3Engine(SnmpEngine engine)
- Sets SNMPv3 engine, so that SNMPv3 discovery won't occur and the session will use the
passed engine object to communicate with SNMPv3 agent.
setV3Params
must be invoked before this method.
- Returns:
- true if engine has been set successfully.
- See Also:
setV3Params(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
getVersion
public int getVersion()
- Returns the SNMP version number supported in this session
setVersion
public void setVersion(int version)
- Sets the SNMP version number supported in this session
- Parameters:
version
- version number, one of { SnmpConst.SNMPV1, SnmpConst.SNMPV2, SnmpConst.SNMPV3 }, whose values are
{0, 1, 3}
close
public void close()
- close the session
- Overrides:
close
in class Session
broadcastDiscovery
public ArrayList broadcastDiscovery(SnmpOID oid)
throws IOException
- Sends out an SNMP broadcast message without retries. This method will return after it times out,
whose value is set by
setTimeout
method.
For example, for a Class C network like 192.168.1.0, the broadcast address would be 192.168.1.255
if the netmask is 255.255.255.0.
- Parameters:
oid
- an OID to be sent in an SNMP GET request.
- Returns:
- an ArrayList whose elements are of type
HostValue
- Throws:
IOException
- Since:
- 4.0
- See Also:
HostValue
getTarget
public Target getTarget()
- Returns the
SnmpTarget
object
that represents properties of remote agent.
Then you can get or set properties of that agent, such as
read and write community names.
- Overrides:
getTarget
in class Session
- See Also:
SnmpTarget
setToUseJCE
public static void setToUseJCE(boolean b)
- Choose to use SUN JCE for SNMPv3 encryption
- Parameters:
b
- true to use JCE.
Copyright © 2002 iReasoning Inc. All Rights Reserved.