unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Menus, httpsend, strutils, snmpsend;

type

  { TForm1 }

  TForm1 = class(TForm)
    aiMeasureMemo: TMemo;
    aiGroupBox: TGroupBox;
    aiNameMemo: TMemo;
    aiValueMemo: TMemo;
    connectButton: TButton;
    diCountMemo: TMemo;
    diGroupBox: TGroupBox;
    diNameMemo: TMemo;
    diValueMemo: TMemo;
    Image1: TImage;
    ipTextBox: TEdit;
    portTextBox: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Memo1: TMemo;
    Memo5: TMemo;
    Memo9: TMemo;
    passwordTextBox: TEdit;
    statusLabel: TLabel;
    tiGroupBox: TGroupBox;
    tiNameMemo: TMemo;
    tiValueMemo: TMemo;
    procedure connectButtonClick(Sender: TObject);
    function getSnmpData(oid: string): string;
    procedure connect();
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.connectButtonClick(Sender: TObject);
begin
  connect();
end;

function TForm1.getSnmpData(oid: string): string;
var
  snmpResult: string;
begin
  if SNMPDenkoviGet(oid, passwordTextBox.Text, ipTextBox.Text,'9595', snmpResult) then
  begin
    Result := snmpResult;
  end
  else
  begin
    Result := 'NULL';
  end;
end;

procedure TForm1.connect();
var
  i: integer;
  error: integer;
  res: string;
  thisString: string;
  temp_oid: string;
begin
  error := 0;
  temp_oid := '1.3.6.1.4.1.42505.7.2.1.1.2.%d';
  diNameMemo.Clear();
  diNameMemo.Lines.AddText('Name'#13#10#13#10);
  for i := 0 to 15 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      diNameMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.1.1.7.%d';
  diValueMemo.Clear();
  diValueMemo.Lines.AddText('Value'#13#10#13#10);
  for i := 0 to 15 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      diValueMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.1.1.3.%d';
  diCountMemo.Clear();
  diCountMemo.Lines.AddText('Count'#13#10#13#10);
  for i := 0 to 15 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      diCountMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.2.1.2.%d';
  aiNameMemo.Clear();
  aiNameMemo.Lines.AddText('Name'#13#10#13#10);
  for i := 0 to 7 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      aiNameMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.2.1.6.%d';
  aiValueMemo.Clear();
  aiValueMemo.Lines.AddText('Value'#13#10#13#10);
  for i := 0 to 7 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      aiValueMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.2.1.10.%d';
  aiMeasureMemo.Clear();
  aiMeasureMemo.Lines.AddText('Measure'#13#10#13#10);
  for i := 0 to 7 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      aiMeasureMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.3.1.2.%d';
  tiNameMemo.Clear();
  tiNameMemo.Lines.AddText('Name'#13#10#13#10);
  for i := 0 to 7 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      tiNameMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  temp_oid := '1.3.6.1.4.1.42505.7.2.3.1.7.%d';
  tiValueMemo.Clear();
  tiValueMemo.Lines.AddText('Value'#13#10#13#10);
  for i := 0 to 7 do
  begin
    thisString := Format(temp_oid, [i]);
    res := getSnmpData(thisString);
    if (res <> 'NULL') then
    begin
      tiValueMemo.Lines.AddText(res);
      connectButton.Caption := 'Refresh';
      statusLabel.Caption := 'Connection Established.';
    end
    else
    begin
      error := error + 1;
      Break;
    end;
  end;

  if error = 8 then
  begin
    connectButton.Caption := 'Connect';
    statusLabel.Caption := 'Failed to Connect. Check IP/Password or Internet Connection.';
  end
  else if error <> 0 then
  begin
    connectButton.Caption := 'Connect';
    statusLabel.Caption := 'Some fields failed to load.';
  end;
end;

end.
