Class SnmpClient

java.lang.Object
org.metricshub.snmp.client.SnmpClient

public class SnmpClient extends Object
  • Field Details

  • 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 querying
      port - 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 retried
      community - (SNMP v1 and v2 only) The SNMP community
      authType - (SNMP v3 only) The authentication method: "MD5", "SHA" or ""
      authUsername - (SNMP v3 only) The username
      authPassword - (SNMP v3 only) The password (in clear)
      privacyType - (SNMP v3 only) The encryption type: "DES", "AES" or ""
      privacyPassword - (SNMP v3 only) The encryption password
      contextName - (SNMP v3 only) The context name
      contextID - (SNMP v3 only) The context ID (??)
      Throws:
      IllegalArgumentException - when specified authType, privType are invalid
      IllegalStateException - 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

      public String get(String oid) throws Exception
      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

      public String getWithDetails(String oid) throws Exception
      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

      public String getNext(String oid) throws Exception
      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

      public String walk(String oid) throws Exception
      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

      public List<List<String>> table(String rootOID, String[] selectColumnArray) throws Exception
      Read the content of an SNMP table
      Parameters:
      rootOID - Root OID of the SNMP table
      selectColumnArray - 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 wrong
      Exception - when the underlying SNMP API throws one