Re: SNMP indy examples ?

Giganews Newsgroups
Subject: Re: SNMP indy examples ?
Posted by:  Warren Postma (wp__…@___tekran.com)
Date: Tue, 27 Jan 2004

Alan hebo wrote:
> where can i get examples on how to use indy snmp to get and put on different
> devices ?
>
> Alan Hebo
>
Here's some sample code: Drop on an IdSNMP1, three TEdits, and a TMemo
for output, and a button, and then add this OnClick code:

procedure TForm1.Button1Click(Sender: TObject);
var
  Ok:Boolean;
  t,Counter:Integer;
  Value:String;
begin
  Counter := 0;
  //IdSNMP1.Active := true;
  IdSNMP1.Community := Edit2.Text;
  IdSNMP1.Host := Edit1.Text;  {ie 'localhost'}
  IdSNMP1.Query.Host := Edit2.Text;
  IdSNMP1.Query.Community := Edit2.Text; {ie 'public'}
  IdSNMP1.Query.Clear;
  IdSNMP1.Query.PDUType := PDUGetRequest;
  IdSNMP1.Query.MIBAdd(Edit3.Text,''); {ie '1.3.6.1.2.1.1.1.0' }
  IdSNMP1.Active := true;
  while Counter < 3 do begin
      Ok := IdSNMP1.SendQuery;
      if Ok then begin

Memo1.Lines.Add('ValueCount='+INTTOSTR(IdSNMP1.Reply.ValueCount));
          for t := 0 to IdSNMP1.Reply.ValueCount-1 do begin
            Memo1.Lines.Add('Value['+IntToStr(t)+']='
+IdSNMP1.Reply.Value[t] );
          end;
          (*if IdSNMP1.SendQuery.MIBOID.Count >0 then begin
            Memo1.Lines.Add('--MIBOID:');
            Memo1.Lines.AddStrings(IdSNMP1.Query.MIBOID);
          end;
          if IdSNMP1.Query.MIBValue.Count >0 then begin
            Memo1.Lines.Add('--MIBVALUE:');
            Memo1.Lines.AddStrings(IdSNMP1.Query.MIBValue);
          end;*)
          break;
        end else begin
          Memo1.Lines.Add('Retrying.');
          Inc(Counter);
        end;
  end;
  if not Ok then begin
      Memo1.Lines.Add('UDP responses lost or there is no SNMP server
responding at that address.');
  end;
end;

Replies

None

In response to

SNMP indy examples ? posted by Alan hebo on Sat, 17 Jan 2004