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 com.ireasoning.protocol.snmp.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 a 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
Constructor Summary |
SnmpSession(SnmpTarget target)
Creates a SnmpSession using the default UDP protocol. |
SnmpSession(SnmpTarget target,
int transportLayer)
Constructs a new SnmpSession. |
SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version)
Creates a SnmpSession |
SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version,
int transportLayer)
Creates a SnmpSession |
Method Summary |
void |
addEngine(byte[] engineID)
Adds a new SnmpEngine |
void |
addEngine(SnmpEngine engine)
Adds a new SnmpEngine |
void |
asyncSend(SnmpPdu pdu)
Used for asynchronous communication. |
void |
asyncSnmpGetBulkRequest(SnmpOID[] oids,
int nonRepeaters,
int maxRepetitions)
Issues SNMP GET_BULK command asynchronously |
void |
asyncSnmpGetBulkRequest(String[] oids,
int nonRepeaters,
int maxRepetitions)
Issues SNMP GET_BULK command asynchronously |
void |
asyncSnmpGetNextRequest(SnmpOID oid)
Issues SNMP GET_NEXT command asynchronously |
void |
asyncSnmpGetNextRequest(SnmpOID[] oids)
Issues SNMP GET_NEXT command asynchronously |
void |
asyncSnmpGetNextRequest(String oid)
Issues SNMP GET_NEXT command asynchronously |
void |
asyncSnmpGetNextRequest(String[] oids)
Issues SNMP GET_NEXT command asynchronously |
void |
asyncSnmpGetRequest(SnmpOID oid)
Issues SNMP GET command asynchronously |
void |
asyncSnmpGetRequest(SnmpOID[] oids)
Issues SNMP GET command asynchronously |
void |
asyncSnmpGetRequest(String oid)
Issues SNMP GET command asynchronously |
void |
asyncSnmpGetRequest(String[] oids)
Issues SNMP GET command asynchronously |
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 |
Target |
getTarget()
Returns the SnmpTarget object
that represents properties of remote agent. |
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. |
SnmpEngine |
lookupEngine(byte[] engineID)
Looks up SnmpEngine instance based on engineID |
SnmpEngine |
lookupEngine(String host,
int port)
Looks up SnmpEngine instance based on host name and port |
SnmpEngine |
lookupEngine(Target target)
Looks up SnmpEngine instance based on host name and port |
protected UsmUser |
lookupUsmUser(String userName,
byte[] engineID,
InetAddress address)
Looks up USM user based on passed user name and engineID. |
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 |
SnmpEngine |
removeEngine(byte[] engineID)
Removes SnmpEngine from engine table |
SnmpEngine |
removeEngine(SnmpEngine engine)
Removes SnmpEngine from engine table |
SnmpEngine |
removeEngine(String host,
int port)
Removes SnmpEngine from engine table |
SnmpEngine |
removeEngine(Target target)
Removes SnmpEngine from engine table |
void |
removeUsmUser(String userName,
byte[] engineID)
Removes a UserUser instance from internal map. |
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 . |
void |
setTimeout(int timeout)
Sets time out value of underlying Socket. |
void |
setV3Params(String userName,
String authProtocol,
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,
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 |
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. |
void |
snmpBulkGetSubtree(SnmpOID startingOID,
Listener listener,
int maxRepetitions)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data. |
void |
snmpBulkGetSubtree(String startingOID,
Listener listener)
The GetSubtree operation allows a management application to retrieve "subtrees" of MIB data. |
void |
snmpBulkWalk(SnmpOID startingOID,
Listener listener)
Uses SNMPV2 GET_BULK requests to query a network entity efficiently for a tree of information. |
void |
snmpBulkWalk(String startingOID,
Listener listener)
Uses SNMPV2 GET_BULK requests to query a network entity efficiently for a tree of information. |
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. |
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. |
SnmpTableModel |
snmpGetTable(String tableName)
Gets whole MIB table and returns a SnmpTableModel object which contains retrieved data |
SnmpTableModel |
snmpGetTable(String tableName,
int maxVarBindCount)
Gets whole MIB table and returns a SnmpTableModel object which contains retrieved data |
boolean |
snmpGetTable(String tableName,
SnmpTableModel model)
Gets whole MIB table and returns a SnmpTableModel object which contains retrieved data |
boolean |
snmpGetTable(String tableName,
SnmpTableModel model,
int maxVarBindCount)
Gets whole MIB table and returns a 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. |
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 |
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.Session |
finalize, getRetries, getState, getStateString, getTimeout, getTransportLayer, open, open, setRetries, setTarget, setTransportLayer, startThread |
SnmpSession
public SnmpSession(String hostname,
int port,
String readCommunity,
String writeCommunity,
int version)
throws IOException
- Creates a 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 agentIllegalArgumentException
- 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 a 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 agentIllegalArgumentException
- 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)
throws IOException
- Creates a 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 foundParseException
- 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 foundParseException
- 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 foundParseException
- 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 foundParseException
- 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.- 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.- 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
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
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
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
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 void 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.- 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:
- snmpasyncget.java example,
asyncSend(SnmpPdu)
,
asyncSnmpGetRequest(SnmpOID)
,
asyncSnmpGetRequest(String[])
asyncSnmpGetRequest
public void asyncSnmpGetRequest(SnmpOID oid)
throws IOException
- Issues SNMP GET command asynchronously
- Parameters:
oid
- the SNMP OID to be sent to the agent- 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:
- snmpasyncget.java example,
asyncSend(SnmpPdu)
,
asyncSnmpGetRequest(String)
,
asyncSnmpGetRequest(SnmpOID[])
,
asyncSnmpGetRequest(String)
asyncSnmpGetRequest
public void 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.- 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:
- snmpasyncget.java example
asyncSnmpGetRequest
public void asyncSnmpGetRequest(SnmpOID[] oids)
throws IOException
- Issues SNMP GET command asynchronously
- Parameters:
oids
- the SNMP OIDs to be sent to the agent in one 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:
asyncSnmpGetRequest(SnmpOID)
,
asyncSnmpGetRequest(String[])
,
snmpasyncget.java example
asyncSnmpGetNextRequest
public void 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.- 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:
asyncSnmpGetNextRequest(SnmpOID)
,
asyncSnmpGetNextRequest(String[])
asyncSnmpGetNextRequest
public void asyncSnmpGetNextRequest(SnmpOID oid)
throws IOException
- Issues SNMP GET_NEXT command asynchronously
- Parameters:
oid
- the SNMP OID to be sent to the agent- 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:
asyncSnmpGetNextRequest(SnmpOID[])
,
asyncSnmpGetNextRequest(String)
asyncSnmpGetNextRequest
public void 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.- 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
asyncSnmpGetNextRequest
public void 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- 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:
asyncSnmpGetNextRequest(SnmpOID)
,
asyncSnmpGetNextRequest(String[])
asyncSnmpGetBulkRequest
public void 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.- Throws:
IOException
- if time out (after retries) or socket is not valid.IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolvedTimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
asyncSnmpGetBulkRequest
public void 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.- Throws:
IOException
- if time out (after retries) or socket is not valid.TimeoutException
- if time out after retries (TimeoutException is a subclass of IOException)
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 com.ireasoning.protocol.snmp.SnmpBaseSession
- Returns:
- a SnmpDataType object representing received data
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)
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 resolvedTimeoutException
- 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(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 resolvedTimeoutException
- 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 resolvedTimeoutException
- 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.
(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.
(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.
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 resolvedTimeoutException
- 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.
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.
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:
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 resolvedTimeoutException
- 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.
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.
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
- Throws:
IOException
- if time out (after retries) or socket is not valid.IllegalArgumentException
- if passed MIB node name (such as "sysUpTime") cannot be resolvedTimeoutException
- 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
- 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 a 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- 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 a 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- 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 a 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- 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 a 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- 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)
- 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"- 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)
- 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)
setTimeout
public void setTimeout(int timeout)
throws SocketException
- Sets time out value of underlying Socket. Default timeout value is 60 seconds. For asynchronous requests, timeout value is set to 0.
- Overrides:
setTimeout
in class Session
- Parameters:
timeout
- the specified timeout in milliseconds. A timeout of zero is interpreted as an infinite timeout.- See Also:
- java.net.Socket.setSoTimeout(int),
java.net.DatagramSocket.setSoTimeout(int)
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.
Note: One of JVM's security property files, java.security, will be
modified to add required security provider if it's not already installed.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA}, 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.
Note: One of JVM's security property files, java.security, will be
modified to add required security provider if it's not already installed.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA}, 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, either SnmpConst.DES (DES algorithm) or SnmpConst.AES (128-bit AES algorithm). 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.
Note: One of JVM's security property files, java.security, will be
modified to add required security provider if it's not already installed.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA}, 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.
Note: One of JVM's security property files, java.security, will be
modified to add required security provider if it's not already installed.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA}, 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, either SnmpConst.DES (DES algorithm) or SnmpConst.AES (128-bit AES algorithm). 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,
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.
Note: One of JVM's security property files, java.security, will be
modified to add required security provider if it's not already installed.
- Parameters:
userName
- user nameauthProtocol
- authentication protocol, one of {SnmpConst.MD5,
SnmpConst.SHA}, which one to use is determined by the authentication protocol agent usesauthKey
- 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
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
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
lookupEngine
public SnmpEngine lookupEngine(String host,
int port)
- Looks up SnmpEngine instance based on host name and port
- Returns:
- SnmpEngine instance if found, null otherwise.
- Since:
- SnmpV3
lookupEngine
public SnmpEngine lookupEngine(Target target)
- Looks up SnmpEngine instance based on host name and port
- Returns:
- SnmpEngine instance if found, null otherwise.
- Since:
- SnmpV3
lookupEngine
public SnmpEngine lookupEngine(byte[] engineID)
- Looks up SnmpEngine instance based on engineID
- Returns:
- SnmpEngine instance if found, null otherwise.
- Since:
- SnmpV3
addEngine
public void addEngine(SnmpEngine engine)
- Adds a new SnmpEngine
- Parameters:
engine
- a instance of SnmpEngine to be added- Since:
- SnmpV3
addEngine
public void addEngine(byte[] engineID)
- Adds a new SnmpEngine
- Parameters:
engineID
- engine ID of the SnmpEngine to be added
removeEngine
public SnmpEngine removeEngine(byte[] engineID)
- Removes SnmpEngine from engine table
- Parameters:
engineID
- the engine ID of the engine to be removed- Returns:
- the SnmpEngine object removed, null if engine not found.
removeEngine
public SnmpEngine removeEngine(Target target)
- Removes SnmpEngine from engine table
- Parameters:
target
- the target object of the engine to be removed- Returns:
- the SnmpEngine object removed, null if engine not found.
removeEngine
public SnmpEngine removeEngine(String host,
int port)
- Removes SnmpEngine from engine table
- Parameters:
host
- the host name of the engine to be removedport
- the port number of the engine to be removed- Returns:
- the SnmpEngine object removed, null if engine not found.
removeEngine
public SnmpEngine removeEngine(SnmpEngine engine)
- Removes SnmpEngine from engine table
- Parameters:
engine
- the engine to be removed- Returns:
- the SnmpEngine object removed, null if engine not found.
removeUsmUser
public void removeUsmUser(String userName,
byte[] engineID)
- Removes a UserUser instance from internal map.
lookupUsmUser
protected UsmUser lookupUsmUser(String userName,
byte[] engineID,
InetAddress address)
- Looks up USM user based on passed user name and engineID. This method is invoked for SNMPv3 packets only, and
before decoder starts to decode SNMPv3 PDU.
- Parameters:
userName
- USM user name contained in the PDUengineID
- SNMPv3 engine IDaddress
- sender's IP address
Copyright © 2002 iReasoning Inc. All Rights Reserved.