This object is used to send SNMP requests to a remote device.

Initialize4 or Initialize2 must be called prior to any other members.

CoreAsp.SnmpRqst uses a three step process:

  1. Calls Initialize4 or Initialize2 to initialize the object against a particular device.
  2. Sets optional parameters such as timeout value, port, etc.
  3. Performs any number of Get, GetNext, GetMultiple or Set operations against a device. Those operations return an ComSnmpResponse object that contains the status of the operation and the value either directly (use Failed/GetValue/GetOid) or as a list of SNMP variable binding returned as XML data (use GetPayload).
Important: Beginning with WhatsUp Gold 24.0.1, users attempting to use the SNMP API should use the Initialize4 method.

Method

Description

Returns

Initialize4( sAddress, nSnmpVersion, sCommunity, sUsername, sContext, nAuthProto, sAuthPwd, nPrivProto, sPrivPwd)

Initializes the SnmpRqst object for the device with the device ID specified in specified parameters.

  • sAddress. The IP address of the device to connect SNMP.
  • nSnmpVersion. 1, 2, 3.
  • sCommunity. plaintext community name for v1 or v2.
  • sUsername. SNMP v3 username.
  • sContext. SNMP v3 context.
  • nAuthProto. SNMP v3 auth protocol.
  • sAuthPwd. SNMP v3 auth password.
  • nPrivProto. SNMP v3 priv protocol.
  • sPrivPwd. SNMP v3 priv password.

ComResult object

Initialize2( sDeviceAddress, nCredentialID )

Initializes the SnmpRqst object by creating a connection to a device using the IP address of a device and a credential stored in WhatsUp Gold. This method can be used to initialize SnmpRqst for a device that is not configured in WhatsUp Gold as long as the credentials for the device are configured in the credential library.

  • sDeviceAddress. The address or hostname of the device to be queried.
  • nCredentialID. A positive integer corresponding to the credential ID of a credential configured in WhatsUp Gold.

ComResult object

SetTimeoutMs( nTimeoutInMilliSec)

Sets the timeout value in milliseconds. If not specified, the timeout defaults to 2000 milliseconds.

  • nTimeoutInMilliSec. A positive integer representing the number of milliseconds after which unresolved requests should be terminated.
    Note: This method returns a value if the method fails and requires an object variable to capture this value. For example: varComResult = SnmpRqst.SetTimeoutMs(5000); where varComResult is a ComResult object.

ComResult object

SetNumRetries( nNumberRetries)

Sets the number of times to retry a request that has timed out. If not specified, failed requests are retried one time.

  • nNumberRetries. A positive integer representing the number of times to retry timed out requests.

To send only one SNMP packet per request, set nNumberRetries to 0 (zero).

ComResult object

SetPort( nPort)

Sets the TCP/IP port to be used by SnmpRqst. If not specified, port 161 is used.

  • nPort. A positive integer between 1 and 65535 corresponding to the port to be used.

ComResult object

Get( sOid)

Issues an SNMP Get command to retrieve the value of the specified object.

  • sOid. A string containing a valid OID.

ComSnmpResponse object

GetNext( sOid)

Issues an SNMP GetNext command to retrieve the value of the object that follows the specified object in lexicographic order.

  • sOid. A string containing a valid OID.

ComSnmpResponse object

GetMultiple( sListOfOids)

Issues an SNMP Get command for each of the objects specified. GetMultiple sends all commands in a single SNMP protocol data unit, so it is more efficient than issuing multiple Get commands independently.

  • sListOfOids. A comma-separated list of valid OIDs.

ComSnmpResponse object

Set( sOid, sType, sValue)

Issues an SNMP Set command to set an OID value on a device.

  • sOid. A string containing a valid OID for the object for which you want to set the value.
  • sType. A single character corresponding to the type of value to set.

    i = integer

    u = unsigned integer

    s = string

    x = hexadecimal string

    d = decimal string

    n = NULL object

    o = object ID

    t = timeticks

    a = IPv4 address

    b = bits

  • sValue. A string containing the value to set.

ComSnmpResponse object

Note: The Set function will not work unless the MIB object and the community string for the device have the Read Write access right.

Here is an example function to automatically set the Initalize4 parameters based on the SNMP credential associated with the device:

' *****************

' * ConnectSNMP *

' *****************

Sub ConnectSNMP()

Dim bCredential : bCredential = 0

'Get SNMP Credential Data

Dim sFirstCommunity : sFirstCommunity = Context.GetProperty("CredSnmpV1:ReadCommunity")

Dim sSecondCommunity : sSecondCommunity = Context.GetProperty("CredSnmpV2:ReadCommunity")

Dim sUsername : sUsername = Context.GetProperty("CredSnmpV3:Username")

Dim sContext : sContext = Context.GetProperty("CredSnmpV3:Context")

Dim sAuthPwd : sAuthPwd = Context.GetProperty("CredSnmpV3:AuthPassword")

Dim sPrivPwd : sPrivPwd = Context.GetProperty("CredSnmpV3:EncryptPassword")

Dim nAuthProto : nAuthProto = 0

Dim nPrivProto : nPrivProto = 0

'initialize snmp cred version

Dim nSnmpVersion : nSnmpVersion = 1

Dim sCommunity : sCommunity = sFirstCommunity

' determine snmp cred version

If Len(sFirstCommunity) = 0 Then

If Len(sSecondCommunity) > 0 Then

nSnmpVersion = 2

sCommunity = sSecondCommunity

Else

If Len(sUsername) > 0 Then

nSnmpVersion = 3

Else

Context.LogMessage "There are no SNMP credentials assigned to this device"

bCredential = 1

End If

End If

End If

If bCredential = 0 Then

Dim rc, sOID, sOIDCore, sOIDtoLoop, sInstance

'Initialize and Test SNMP Connection

Set rc = oSnmp.Initialize4(sAddress,nSnmpVersion,sCommunity,sUsername,sContext,nAuthProto,sAuthPwd,nPrivProto,sPrivPwd)

If rc.Failed Then

sErrorMsg = rc.GetErrorMsg

bSNMPResult = 1

bFail = 1

End If

End If

End Sub