com.agentpp.explorer.script.external
Interface Snmp


public interface Snmp

This interface describes the methods available in the "snmp" context of the MIB Explorer scripting programming interface. The Snmp context provides services to create SNMP request, load PDUs, modify their Variable Bindings, send SNMP requests and notifications synchronously and inspect SNMP responses. The context has several internal members which can be accessed through this interface:

  • Current Target - The target to be used for subsequent requests.
  • Default Target - The target set for MIB Explorer.
  • Request PDU - The PDU to be used for subsequent SNMP operations.
  • Response PDU - The PDU received from the last request operation.
  • PDU directory - The directory the search for PDU files, if their file name is relative.
  • Since:
    1.5
    Version:
    2.0

    Method Summary
     void createEmptyRequestPdu()
              Sets the request PDU to an empty GET PDU with no variable bindings.
     PDU duplicate(PDU pdu)
              Returns a duplicate of the given PDU for the current target.
     java.lang.String getCurrentTarget()
              Returns the current target as a String.
     java.lang.String getDefaultTarget()
              Returns the target (currently) configured for MIB Explorer.
     java.lang.Integer getErrorIndex()
              Get the error index of the failed variable binding from the response PDU.
     java.lang.Integer getErrorStatus()
              Get the error status of the response PDU.
     java.lang.String getErrorStatusText()
              Get the response PDU's error status textual description.
     java.lang.String getPduDirectory()
              Returns the directory where MIB Explorer has stored a PDU last.
     PDU getRequestPdu()
              Returns the current request PDU.
     VariableBinding getRequestVariable(java.lang.String objectName)
              Gets the variable binding of the current request PDU whose OID matches the OID given.
     PDU getResponsePdu()
              Get the response PDU of the last request.
     java.lang.String getScriptName()
              Gets the name of the script.
     java.lang.Integer getSnmpVersion()
              Gets the SNMP version of the current target.
     java.util.List getTable(java.util.List columnOIDs, java.lang.String lowerBoundIndex, java.lang.String upperBoundIndex)
              Gets synchronously SNMP tabular data from one or more tables.
     java.util.List getTable(java.util.List columnOIDs, java.lang.String lowerBoundIndex, java.lang.String upperBoundIndex, int maxRepetitions)
              Gets synchronously SNMP tabular data from one or more tables.
     java.util.Vector getTargets()
              Gets all targets configured for MIB Explorer.
     boolean isTarget(java.lang.String target)
              Checks whether a String represents a target.
     java.lang.Integer send()
              Send the current request PDU.
     boolean setCurrentTarget(java.lang.String targetString)
              Sets the target to be used for subsequent SNMP operations.
     void setCurrentTargetsAddress(java.lang.String address)
              Sets the target UDP address of the current target which is represented as "a.b.c.d:port" or "a.b.c.d/port".
     void setPduDirectory(java.lang.String path)
              Sets the directory to search for PDUs.
     void setRequestPdu(PDU pdu)
              Sets the PDU to be used for subsequent requests.
     java.lang.Boolean setRequestPdu(java.lang.String pduPath)
              Sets the PDU to be used for subsequent requests by giving the file name of a MIB Explorer PDU file.
     void setRequestType(java.lang.String requestType)
              Set the request type of the current request PDU.
     

    Method Detail

    getCurrentTarget

    java.lang.String getCurrentTarget()
    Returns the current target as a String. Unless the current target has been explicitly set by setCurrentTarget, the target returned will be the default target, that is the MIB Explorer target. The current target is the target that will be used for sending SNMP messages with send.

    Returns:
    a String representing the current target.

    setCurrentTarget

    boolean setCurrentTarget(java.lang.String targetString)
    Sets the target to be used for subsequent SNMP operations.

    Parameters:
    targetString - a String identifying a target.
    Returns:
    true if the target could be found and set.
    Since:
    2.0

    setCurrentTargetsAddress

    void setCurrentTargetsAddress(java.lang.String address)
    Sets the target UDP address of the current target which is represented as "a.b.c.d:port" or "a.b.c.d/port". If a port is not specified, 161 will be assumed.

    Parameters:
    address - an UDP address string, for example "127.0.0.1:161".

    getDefaultTarget

    java.lang.String getDefaultTarget()
    Returns the target (currently) configured for MIB Explorer.

    Returns:
    a String representing the default target.

    getTargets

    java.util.Vector getTargets()
    Gets all targets configured for MIB Explorer.

    Returns:
    a Vector with String representations of all available targets.

    isTarget

    boolean isTarget(java.lang.String target)
    Checks whether a String represents a target.

    Parameters:
    target - a String.
    Returns:
    true if the given target String represents one of the available targets, false otherwise.

    getRequestVariable

    VariableBinding getRequestVariable(java.lang.String objectName)
    Gets the variable binding of the current request PDU whose OID matches the OID given.

    Parameters:
    objectName - a String representing an OID (object identifier) as dotted string. The first subidentifier may be an object name from a loaded MIB module.
    Returns:
    a VariableBinding instance.

    setPduDirectory

    void setPduDirectory(java.lang.String path)
    Sets the directory to search for PDUs. If a PDU path is relative, this directory will become those path's prefix.

    Parameters:
    path - a String representing an absolut path to a directory.

    getPduDirectory

    java.lang.String getPduDirectory()
    Returns the directory where MIB Explorer has stored a PDU last.

    Returns:
    a String representing an absolut path to a directory.

    setRequestPdu

    java.lang.Boolean setRequestPdu(java.lang.String pduPath)
    Sets the PDU to be used for subsequent requests by giving the file name of a MIB Explorer PDU file.

    Parameters:
    pduPath - a String denoting the relative or absolut path of a MIB Explorer PDU file. If pduPath is relative it will be appended to the PDU directory set via setPduDirectory (this is the last used MIB Explorer PDU directory by default).
    Returns:
    true when the PDU could be found and loaded, false otherwise.

    setRequestPdu

    void setRequestPdu(PDU pdu)
    Sets the PDU to be used for subsequent requests.

    Parameters:
    pdu - a PDU instance.

    getRequestPdu

    PDU getRequestPdu()
    Returns the current request PDU.

    Returns:
    an instance of PDU.

    createEmptyRequestPdu

    void createEmptyRequestPdu()
    Sets the request PDU to an empty GET PDU with no variable bindings. In order to add variable bindings, use PDU.appendVariable. In order to set a different type for the PDU, use setRequestType.


    setRequestType

    void setRequestType(java.lang.String requestType)
    Set the request type of the current request PDU. By default a GET request will be sent.

    Parameters:
    requestType - a String with one of the following values (without quotes): "GET", "GETNEXT", "GETBULK", "SET", "TRAP", "INFORM".

    send

    java.lang.Integer send()
    Send the current request PDU. Before a PDU can be sent, the request PDU as to be set by setRequestPDU or

    Returns:
    an Integer representing the SNMP error status of the operation:
  • -1 timeout
  • 0 no error
  • 1 pdu encoding too big
  • 2 no such VB name, see error index
  • 3 bad VB
  • 4 VB is read only, see error index
  • 5 general VB error, see error index
  • 6 no access to MIBs data
  • 7 requested type was incorrect
  • 8 request PDU has inccorect length
  • 9 request PDU has wrong encoding
  • 10 request PDU has wrong value
  • 11 unable to create object specified
  • 12 inconsistent value in request
  • 13 resources unavailable
  • 14 unable to commit
  • 15 unable to undo
  • 16 authentication failure
  • 17 MIB object not writeable
  • 18 inconsistent naming used

  • getTable

    java.util.List getTable(java.util.List columnOIDs,
                            java.lang.String lowerBoundIndex,
                            java.lang.String upperBoundIndex)
    Gets synchronously SNMP tabular data from one or more tables. The data is returned row-by-row as a list of TableRow instances. Each instance represents a row (or an error condition). The OIDs of the columnar objects have to be specified for which instances should be retrieved. You can use Utils.createVector() to create an empty list and then add the column OID strings to it. The OID strings may contain object names (e.g. "ifType") that are resolved to OIDs automatically (if the name is know to MIB explorer).

    With a lower bound index and an upper bound index, the result set can be narrowed to improve performance.

    Parameters:
    columnOIDs - a List (Vector) of column OIDs (without index part!).
    lowerBoundIndex - a lower bound index value or null or an empty string if no lower bound should be specified.
    upperBoundIndex - String an upper bound index value or null or an empty string if no upper bound should be specified.
    Returns:
    List a list of TableEvent objects. If tableEvent.getStatus() returns 0, you can access the rows index get calling getIndex() and the VariableBindings by getColumns().
    Since:
    2.0

    getTable

    java.util.List getTable(java.util.List columnOIDs,
                            java.lang.String lowerBoundIndex,
                            java.lang.String upperBoundIndex,
                            int maxRepetitions)
    Gets synchronously SNMP tabular data from one or more tables. The data is returned row-by-row as a list of TableRow instances. Each instance represents a row (or an error condition). The OIDs of the columnar objects have to be specified for which instances should be retrieved. You can use Utils.createVector() to create an empty list and then add the column OID strings to it. The OID strings may contain object names (e.g. "ifType") that are resolved to OIDs automatically (if the name is know to MIB explorer).

    With a lower bound index and an upper bound index, the result set can be narrowed to improve performance.

    Parameters:
    columnOIDs - a List (Vector) of column OIDs (without index part!).
    lowerBoundIndex - a lower bound index value or null or an empty string if no lower bound should be specified.
    upperBoundIndex - String an upper bound index value or null or an empty string if no upper bound should be specified.
    maxRepetitions - the maximum number of rows to be retrieved per (internal) GETBULK request. For SNMPv1 this value is alwas one, because GETNEXT is used.
    Returns:
    List a list of TableEvent objects. If tableEvent.getStatus() returns 0, you can access the rows index get calling getIndex() and the VariableBindings by getColumns().
    Since:
    2.0

    getErrorStatus

    java.lang.Integer getErrorStatus()
    Get the error status of the response PDU.

    Returns:
    an Integer value representing the SNMP error status of the response PDU.
    See Also:
    send

    getErrorStatusText

    java.lang.String getErrorStatusText()
    Get the response PDU's error status textual description.

    Returns:
    a String representing the SNMP error status of the response PDU.
    See Also:
    send

    getErrorIndex

    java.lang.Integer getErrorIndex()
    Get the error index of the failed variable binding from the response PDU.

    Returns:
    an Integer representing the index (starting from one) of the failed variable binding. Zero is returned if no error ocurred, null if the request timed out.

    getResponsePdu

    PDU getResponsePdu()
    Get the response PDU of the last request. This will return null if the last request timed out or was a TRAP.

    Returns:
    a PDU instance or null if there has not been any response received yet.

    duplicate

    PDU duplicate(PDU pdu)
    Returns a duplicate of the given PDU for the current target. Thus, only the variable bindings, maximum repetitions, and number of non-repeaters of the original PDU are copied. All other parameters, for example the SNMPv3 context, are taken from the current target settings.

    Parameters:
    pdu - the PDU to duplicate.
    Returns:
    a copy of pdu for the current target.

    getSnmpVersion

    java.lang.Integer getSnmpVersion()
    Gets the SNMP version of the current target.

    Returns:
    an Integer with one of the following values:
  • 1 - SNMPv1
  • 2 - SNMPv2c
  • 3 - SNMPv3

  • getScriptName

    java.lang.String getScriptName()
    Gets the name of the script.

    Returns:
    the script's name.

    Copyright 2003-2011, Frank Fock, All Rights Reserved. http://www.mibexplorer.com