SnmpCloseConnection Function

Action

This function closes the connection established by a call of SnmpOpenConnection().

Include file

Snmp.bdh

Syntax

SnmpCloseConnection( in hSnmp : number ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hSnmp Handle from SnmpOpenConnection().

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);
                  sOid := sMibOid + "." + sInstanceOid;

                  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;