This function opens a new connection to a target machine with access to SNMP data for the provided MIB. It returns a handle required by all other BDL SNMP extension functions. It supports both SNMPv1/2c and SNMP3.
Snmp.bdh
SnmpOpenConnectionEx( in sMachine : string, in sMib : string, in sVersion : string, in sCommunity : string optional, in sAuthProtocol : string optional, in sPrivProtocol : string optional, in sAuthPassword : string optional, in sPrivPassword : string optional, in sSecurityName : string optional, in sSecurityLevel : string optional, in sSecurityModel : string optional, in sContextName : string optional, in sContextEngineID : string optional ): number;
Handle for open connection (0 on failure)
Parameter | Description |
---|---|
sMachine | Specifies target machine and port on which the smnp server is listening. |
sMib | Specifies the name of the MIB. |
sVersion | Specifies the version of the SNMP data. |
sCommunity | Specifies the community of the SNMP data. |
sAuthProtocol | Specifies the Authentication protocol of the SNMP data. (Version 3) |
sPrivProtocol | Specifies the Privacy Protocol of the SNMP data. (Version 3) |
sAuthPassword | Specifies the Authentication Password of the SNMP data. (Version 3) |
sPrivPassword | Specifies the Privacy Password of the SNMP data. (Version 3) |
sSecurityName | Specifies the Security Name of the SNMP data. (Version 3) |
sSecurityLevel | Specifies the Security Level of the SNMP data. (Version 3) |
sSecurityModel | Specifies the Security Model of the SNMP data. (Version 3) |
sContextName | Specifies the Context Name of the SNMP data. (Version 3) |
sContextEngineID | Specifies the Context Engine ID of the SNMP data. (Version 3) |
benchmark Collect use "pdce.bdh" use "snmp.bdh" var measureMachine : string; measureMachineServer : string; measureMachinePort : string; const MEASURE_VERSION := "V3"; MEASURE_NAME := "System/Services"; MEASURE_MIB := "SNMPv2-MIB"; MEASURE_OID_NAME := "system.sysServices"; MEASURE_PRIVPWD := "pwd12345678"; MEASURE_AUTHPWD := "pwd12345678"; MEASURE_SECURITY_LEVEL := "3"; MEASURE_SECURITY_MODEL := "3"; MEASURE_SECURITY_NAME := "testuser"; MEASURE_CONTEXT_NAME := ""; MEASURE_CONTEXT_ENGINE_ID := ""; MEASURE_AUTH_PROTOCOL := "MD5"; MEASURE_PRIV_PROTOCOL := "DES"; var nInterval : number; hClient1 : number; hMeasure1 : number; sKey1 : string(1024); dcluser user Collect transactions NoTRT_TStartup : begin; NoTRT_TCollect : 5; NoTRT_TEnd : end; dclfunc function PdceGetSnmpKey(sKey : string; sMachine : string; sMib : string; sAuthProtocol : string; sPrivProtocol : string; sAuthPassword : string; sPrivPassword : string; sSecurityName : string; sSecurityLevel : string; sSecurityModel : string; sContextName : string; sContextEngineID : string; sVersion : string; sOidName : string; nInstance : number optional) : boolean var sMibOid : string(1024); sInstanceOid : string(1024); sValue : string(1024); sOid,sOid_old : string(1024); hSnmp : number; // SNMP connection handle sKey_old : string(1024); begin hSnmp := SnmpOpenConnectionEx(sMachine, sMib, sVersion, "", sAuthProtocol, sPrivProtocol, sAuthPassword, sPrivPassword, sSecurityName, sSecurityLevel, sSecurityModel, sContextName, sContextEngineID); if ( hSnmp <> 0 ) then if not SnmpGetMibOid(hSnmp, sOidName, sMibOid) then RepMessage("SnmpGetMibOid failed: "+sMibOid,SEVERITY_ERROR); end; Print("OID for " + sOidName + " : " + sMibOid); SnmpGetFirstInstanceOid(hSnmp, sMibOid, sInstanceOid); //old version Print("InstanceOid: " + sInstanceOid); sOid_old := sMibOid + "." + sInstanceOid; Print("Old Oid: " + sOid_old); sOid := SnmpGetValueOid(hSnmp, MEASURE_OID_NAME, "72", MEASURE_OID_NAME); Print("OID with first instance: " + sOid); if Stricmp(sOid,sOid_old) <> 0 then RepMessage("SnmpGetValueOid failed: "+sOid,SEVERITY_ERROR); end; if SnmpGetValue(hSnmp, sOid, sValue) then Print("Value: " + sValue); end; sKey := SnmpCreatePdceKeyEx(sOid, measureMachine, sVersion, "", sAuthProtocol, sPrivProtocol, sAuthPassword, sPrivPassword, sSecurityName, sSecurityLevel, sSecurityModel, sContextName, sContextEngineID); print(sKey); // manually added - no next interface available if SnmpGetNextInstanceOid(hSnmp, sInstanceOid) then print(sInstanceOid); else RepMessage("SnmpGetNextInstanceOid didn't find a next instance. "+sInstanceOid,SEVERITY_WARNING); end; PdceGetSnmpKey := true; SnmpCloseConnection( hSnmp ) end; PdceGetSnmpKey := false; end PdceGetSnmpKey; dcltrans transaction NoTRT_TStartup begin AttributeGetString("SNMPTestServer", measureMachineServer); AttributeGetString("SNMPTestServerPort", measureMachinePort); measureMachine := measureMachineServer+":"+measureMachinePort; print(measureMachine); PdceGetSnmpKey( sKey1, measureMachine, MEASURE_MIB, MEASURE_AUTH_PROTOCOL, MEASURE_PRIV_PROTOCOL, MEASURE_AUTHPWD, MEASURE_PRIVPWD, MEASURE_SECURITY_NAME, MEASURE_SECURITY_LEVEL, MEASURE_SECURITY_MODEL, MEASURE_CONTEXT_NAME, MEASURE_CONTEXT_ENGINE_ID, MEASURE_VERSION, MEASURE_OID_NAME); PdceStartUp(); PdceRegisterClient(hClient1, nInterval); PdceAddMeasure(hClient1, MEASURE_NAME, sKey1, hMeasure1); Wait(float(2*nInterval)); end NoTRT_TStartup; transaction NoTRT_TCollect var fLastValue, fSum, fMin, fMax, fAvg, fStDev : float; uTimeStamp, uStatus : number; begin PdceGetMeasureValue(hMeasure1, MEASURE_NAME); if (GetWorkloadModel() <> WORKLOAD_MONITORING) then Wait(float(nInterval)); end; if PdceMeasureQueryValue(hMeasure1, fLastValue, fSum, fMin, fMax, fAvg, fStDev, uTimeStamp, uStatus) then Print("Query value: " + String(fLastValue) ); end; end NoTRT_TCollect; transaction NoTRT_TEnd begin PdceMeasureUnSubscribe(hMeasure1); PdceClientUnRegister(hClient1); PdceCleanUp(); end NoTRT_TEnd;