Package org.metricshub.snmp.client
Class SnmpClient
java.lang.Object
org.metricshub.snmp.client.SnmpClient
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final String
-
Constructor Summary
ConstructorsConstructorDescriptionSnmpClient
(String host, int port, int version, int[] retryIntervals, String community, String authType, String authUsername, String authPassword, String privacyType, String privacyPassword, String contextName, byte[] contextID) Creates an SNMPClient instance, which connects to the specified SNMP agent with the specified credentials (depending on the version of SNMP) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Releases the resources associated to this instance (or so at least we believe...)Perform a GET operation on the specified OIDPerform a GETNEXT operation on the specified OIDgetWithDetails
(String oid) Perform a GET operation on the specified OID and return the details of the result (including the type of the value)Read the content of an SNMP tablePerform a WALK, i.e. a series of GETNEXT operations until we fall off the tree
-
Field Details
-
SNMP_PORT
public static final int SNMP_PORT- See Also:
-
SNMP_V1
public static final int SNMP_V1- See Also:
-
SNMP_V2C
public static final int SNMP_V2C- See Also:
-
SNMP_V3
public static final int SNMP_V3- See Also:
-
SNMP_AUTH_MD5
- See Also:
-
SNMP_AUTH_SHA
- See Also:
-
SNMP_AUTH_SHA256
- See Also:
-
SNMP_AUTH_SHA512
- See Also:
-
SNMP_AUTH_SHA224
- See Also:
-
SNMP_AUTH_SHA384
- See Also:
-
SNMP_PRIVACY_DES
- See Also:
-
SNMP_PRIVACY_AES
- See Also:
-
SNMP_PRIVACY_AES192
- See Also:
-
SNMP_PRIVACY_AES256
- See Also:
-
SNMP_NONE
- See Also:
-
SNMP_PRIVACY_PROTOCOLS
-
SNMP_AUTH_PROTOCOLS
-
SOCKET_TYPE
- See Also:
-
-
Constructor Details
-
SnmpClient
public SnmpClient(String host, int port, int version, int[] retryIntervals, String community, String authType, String authUsername, String authPassword, String privacyType, String privacyPassword, String contextName, byte[] contextID) throws IOException Creates an SNMPClient instance, which connects to the specified SNMP agent with the specified credentials (depending on the version of SNMP)- Parameters:
host
- The hostname/IP address of the SNMP agent we're queryingport
- The port of the SNMP agent (should be 161)version
- The version of SNMP to use (1, 2 or 3)retryIntervals
- Timeout in milliseconds after which the elementary operations will be retriedcommunity
- (SNMP v1 and v2 only) The SNMP communityauthType
- (SNMP v3 only) The authentication method: "MD5", "SHA" or ""authUsername
- (SNMP v3 only) The usernameauthPassword
- (SNMP v3 only) The password (in clear)privacyType
- (SNMP v3 only) The encryption type: "DES", "AES" or ""privacyPassword
- (SNMP v3 only) The encryption passwordcontextName
- (SNMP v3 only) The context namecontextID
- (SNMP v3 only) The context ID (??)- Throws:
IllegalArgumentException
- when specified authType, privType are invalidIllegalStateException
- when the specified properties lead to something that cannot work (i.e. privacy without authentication)IOException
- when cannot initialize the SNMP context
-
-
Method Details
-
freeResources
public void freeResources()Releases the resources associated to this instance (or so at least we believe...) -
get
Perform a GET operation on the specified OID- Parameters:
oid
- OID on which to perform a GET operation- Returns:
- Value of the specified OID
- Throws:
Exception
- in case of any problem
-
getWithDetails
Perform a GET operation on the specified OID and return the details of the result (including the type of the value)- Parameters:
oid
- OID on which to perform a GET operation- Returns:
- A string in the form of the OID, "string" and the value, separated by tabs (\t)
- Throws:
Exception
- in case of any problem
-
getNext
Perform a GETNEXT operation on the specified OID- Parameters:
oid
- OID on which to perform a GETNEXT operation- Returns:
- A string in the form of the OID, "string" and the value, separated by tabs (\t)
- Throws:
Exception
- in case of any problem
-
walk
Perform a WALK, i.e. a series of GETNEXT operations until we fall off the tree- Parameters:
oid
- Root OID of the tree- Returns:
- Result of the WALK operation, as a long String. Each pair of oid/value is separated with a linefeed (at least, for now!)
- Throws:
Exception
IllegalArgumentException
- for bad specified OIDs
-
table
Read the content of an SNMP table- Parameters:
rootOID
- Root OID of the SNMP tableselectColumnArray
- Array of numbers specifying the column numbers of the array to be read. Use "ID" for the row number.- Returns:
- A semicolon-separated list of values
- Throws:
IllegalArgumentException
- when the specified arguments are wrongException
- when the underlying SNMP API throws one
-