This function returns a valid PDCE key. The provided OID (snmp node in dotted notation), the target machine, the snmp protocol version, and the required community (if version 1/2c) or the authentication details in terms of authentication protocol, privacy protocol, authentication password, privacy password, the security name, the securtiy level, teh security model, the context name, the context engine ID (if version 3) are used to generate a key s tring, that can directly be used in the PdceAddMeasure() or PdceMeasureSubscribe() functions. This function requires raw strings, not Base64-encoded strings.
Snmp.bdh
SnmpCreatePdceKeyEx( in sOid             : string,
                     in sMachine         : string,
                     in sVersion         : string,
                     in sCommunity       : string,
                     in sAuthProtocol    : string,
                     in sPrivProtocol    : string,
                     in sAuthPassword    : string,
                     in sPrivPassword    : string,
                     in sSecurityName    : string,
                     in sSecurityLevel   : string,
                     in sSecurityModel   : string,
                     in sContextName     : string,
                     in sContextEngineID : string ) : string; 
               	 A valid key string generated from provided data which can be used in further PDCE function calls.
| Parameter | Description | 
|---|---|
| sOid | Specifies SNMP OID in dotted notation. | 
| sMachine | Specifies target machine and port on which the smnp server is listening. | 
| sVersion | Specifies the version of the SNMP data. | 
| sCommunity | Specifies the community of the SNMP data. (version 1/2c) | 
| 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 protocol 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 securtiy 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. (verison 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;