SnmpGetNextInstanceOid Function

Action

Subsequent calls of this function return the next existing instance after a successful SnmpGetFirstInstanceOid() on target machine. If no instance was found the function fails.

Include file

Snmp.bdh

Syntax

SnmpGetNextInstanceOid( in  hSnmp        : number,
                        out sInstanceOid : string,
                        in  nInstOidSize : number optional ): boolean;

Return value

  • true if successful and instance was found

  • false otherwise

Parameter Description
hSnmp Handle from SnmpOpenConnection().
sInstanceOid Returns the next instance.
nInstOidSize Size of the buffer sInstanceOid (optional).

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 :=  "SNMP:" + 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;