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 "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 |