CoreAsp.SnmpRqst
- Last Updated: December 11, 2024
- 2 minute read
- WhatsUp Gold
- Version 2024
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:
- Calls
Initialize4orInitialize2to initialize the object against a particular device. - Sets optional parameters such as timeout value, port, etc.
- Performs any number of
Get,GetNext,GetMultipleorSetoperations against a device. Those operations return anComSnmpResponseobject that contains the status of the operation and the value either directly (useFailed/GetValue/GetOid) or as a list of SNMP variable binding returned as XML data (useGetPayload).
Initialize4 method. Method |
Description |
Returns |
|---|---|---|
|
Initialize4( |
Initializes the
|
ComResult object |
|
Initialize2( |
Initializes the
|
ComResult object |
|
SetTimeoutMs( |
Sets the timeout value in milliseconds. If not specified, the timeout defaults to 2000 milliseconds.
|
ComResult object |
|
SetNumRetries( |
Sets the number of times to retry a request that has timed out. If not specified, failed requests are retried one time.
To send only one SNMP packet per request, set
|
ComResult object |
|
SetPort( |
Sets the TCP/IP port to be used by
|
ComResult object |
|
Get( |
Issues an SNMP Get command to retrieve the value of the specified object.
|
ComSnmpResponse object |
|
GetNext( |
Issues an SNMP GetNext command to retrieve the value of the object that follows the specified object in lexicographic order.
|
ComSnmpResponse object |
|
GetMultiple( |
Issues an SNMP Get command for each of the objects specified.
|
ComSnmpResponse object |
|
Set( |
Issues an SNMP Set command to set an OID value on a device.
|
ComSnmpResponse object |
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 |