SnmpCreatePdceKey Function

Action

This function returns a valid PDCE key. The provided OID (snmp node in dotted notation), the target machine, the required community and the snmp protocol version are used to generate a key string, that can directly be used in the PdceAddMeasure() or PdceMeasureSubscribe() functions. For this function, sCommunity and sVersion have to be encoded in Base64.

Include file

Snmp.bdh

Syntax

SnmpCreatePdceKey( in sOid       : string,
                   in sMachine   : string,
                   in sCommunity : string,
                   in sVersion   : string ) : string;

Return value

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.
sCommunity Specifies the community of the SNMP data.
sVersion Specifies the version of the SNMP data.

Example

benchmark Collect

 use "pdce.bdh"
 use "snmp.bdh" 

const
  MEASURE_COMMUNITY   := "public";
  MEASURE_VERSION     := "V1";
  MEASURE_NAME        := "System/Services";
  MEASURE_MACHINE     := "machineName:161";
  MEASURE_MIB         := "RFC1213-MIB";
  MEASURE_OID_NAME    := "system.sysServices";

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;
                          sCommunity : string;
                          sVersion   : string;
                          sOidName   : string;
                          nInstance  : number optional) : boolean        

var
    sMibOid        : string(1024);
    sInstanceOid   : string(1024);
    sValue         : string(1024);
    sOid           : string(1024);
    hSnmp          : number;        // SNMP connection handle  
begin

    hSnmp := SnmpOpenConnection(sMachine, sMib, sCommunity, sVersion);

    if ( hSnmp <> 0 ) then
                  SnmpGetMibOid(hSnmp, sOidName, sMibOid);

                  Print("OID for " + sOidName + " : " + sMibOid);

                  SnmpGetFirstInstanceOid(hSnmp, sMibOid, sInstanceOid);
                  while SnmpGetNextInstanceOid(hSnmp, sInstanceOid) do
                     sOid := sMibOid + "." + sInstanceOid;
                  end;  
                   
                  Print("OID with first instance: " + sOid);

                  if SnmpGetValue(hSnmp, sOid, sValue) then
                    Print("Value: " + sValue);
                  end;

                  sKey := SnmpCreatePdceKey(sOid, MEASURE_MACHINE, SNMP_COMMUNITY_PUBLIC, SNMP_VERSION_1);
                  PdceGetSnmpKey := true;

                  SnmpCloseConnection( hSnmp )
           end;                        

             PdceGetSnmpKey := false;

end PdceGetSnmpKey;

dcltrans
  transaction NoTRT_TStartup
  begin
       PdceGetSnmpKey( sKey1, MEASURE_Machine, MEASURE_MIB, MEASURE_COMMUNITY, 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;