CoreAsp.SnmpRqst
- Last Updated: May 21, 2026
- 4 minute read
- WhatsUp Gold
- Version 2026
此对象可将 SNMP 请求发送到远程设备。
在调用其他任何成员之前,必须先调用 Initialize4 或 Initialize2。
CoreAsp.SnmpRqst 使用的程序有三个步骤:
- 调用
Initialize4或Initialize2,以针对特定设备初始化该对象。 - 设定选用参数,例如超时值、端口......等等。
- 对设备执行任何次数的
Get、GetNext、GetMultiple或Set操作。这些操作会直接返回含有操作状态与值的ComSnmpResponse对象 (使用Failed/GetValue/GetOid),或以 XML 数据形式返回 SNMP 变量系结列表 (使用GetPayload)。
Initialize4 方法。 方法 |
描述 |
返回 |
|---|---|---|
|
Initialize4( |
根据指定参数中的设备 ID,为该设备初始化
|
ComResult 对象 |
|
Initialize2( |
通过使用设备的 IP 地址以及存储在 WhatsUp Gold 中的凭据创建到设备的连接,从而初始化
|
ComResult 对象 |
|
SetTimeoutMs( |
以毫秒数设定超时值。未指定时,默认超时值是 2000 毫秒。
|
ComResult 对象 |
|
SetNumRetries( |
设定超时请求的重试次数。未指定时,失败的请求会重试一次。
若要让每个请求只发送一个 SNMP 数据包,请将 |
ComResult 对象 |
|
SetPort( |
设定要由
|
ComResult 对象 |
|
Get( |
发出 SNMP Get 命令,检索指定对象的值。
|
|
|
GetNext( |
发出 SNMP GetNext 命令,依字典顺序检索指定对象后面的对象值。
|
|
|
GetMultiple( |
为指定的每个对象发出 SNMP Get 命令。
|
|
|
Set( |
发出 SNMP Set 命令,在设备上设定 OID 值。
|
以下示例函数将根据与设备关联的 SNMP 凭据自动设置 Initialize4 参数:
|
' ***************** ' * 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 "未为此设备分配 SNMP 凭据" 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 |