SnmpGetValueOid Function

Action

This function uses a provided SNMP node and searches all instances of it until its value matches the desired value. Then this instance is used for the second SNMP node query and the valid OID (in dotted notation) for this node is returned. If some error occurs or no match is found an empty string is returned.

Include file

Snmp.bdh

Syntax

SnmpGetValueOid( in hSnmp          : number,
                 in sKeyOidName    : string,
                 in sKeyMatchValue : string,
                 in sParamName     : string ): string;

Return value

SNMP OID including instance for provided SNMP node in sValueOidName. Values for all instances for sKeyOidName are compared with provided sKeyMatchValue, and if a match is found, that instance is added to the OID of sValueOidName and returned. Otherwise an empty string is returned.

Parameter Description
hSnmp Handle from SnmpOpenConnection().
sKeyOidName Name of SNMP node in dotted notation.
sKeyMatchValue String that is used for comparison with values for instances of sKeyOidNames.
sParamName Name of SNMP node in dotted notation.

Example

benchmark Collect 

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

const
  MEASURE_MACHINE   := "machinename:161";    // machine + port
  MEASURE_COMMUNITY := "public";
  MEASURE_VERSION   := "V1";
  MEASURE_MIB       := "BEA-WEBLOGIC-MIB";
  MEASURE_OID_NAME1 := "bea.wls.webServerTable.webServerEntry.webServerLogFileFlushSecs";
  MEASURE_NAME01    := "webServer/LogFileFlushSeconds";
  MEASURE_OID_NAME2 := "bea.wls.webServerTable.webServerEntry.webServerName";
  MEASURE_OID_VALUE2:= "PIA"; 

var
  nInterval         : number;
  hClient01         : number;
  hMeasure01        : 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);
    bFoundInstance : boolean;
    hSnmp          : number;

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

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

      sOid := SnmpGetValueOid(hSnmp, MEASURE_OID_NAME2, MEASURE_OID_VALUE2, MEASURE_OID_NAME1);

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

       sKey := SnmpCreatePdceKey(sOid, sMachine, sCommunity, sVersion);

       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_NAME1);

     PdceStartUp();
     PdceRegisterClient(hClient01, nInterval);
     PdceAddMeasure(hClient01, MEASURE_NAME01, sKey1, hMeasure01);

     Wait(float(2*nInterval));
  end NoTRT_TStartup;

   transaction NoTRT_TCollect
  var
    fLastValue, fSum, fMin, fMax, fAvg, fStDev : float;
    uTimeStamp, uStatus                        : number;
  begin
    PdceGetMeasureValue(hMeasure01, MEASURE_NAME01);
     
    if (GetWorkloadModel() <> WORKLOAD_MONITORING) then
      Wait(float(nInterval));
    end;

     if PdceMeasureQueryValue(hMeasure01, fLastValue, fSum, fMin, fMax, fAvg, fStDev, uTimeStamp, uStatus) then
      Print("Query value: " + String(fLastValue) );
    end;

   end NoTRT_TCollect;

   transaction NoTRT_TEnd
   begin
    PdceMeasureUnSubscribe(hMeasure01);
    PdceClientUnRegister(hClient01);
    PdceCleanUp();
  end NoTRT_TEnd;