Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with SNMP
#1
Exclamation 
Hello.

I have a gasoline generator that has the ability to report its status via the SNMP protocol. If I use a third-party app, I can get a response from querying "1.3.6.1.2.1.1.1.0" and "1.3.6.1.4.1.28634.6.2551906584.2.8206" and it works well. When I tried to write it myself, I notice that the first request is successful but on the second one I get a "NoSuchName" error.

ps.
Windows 10 x64
RAD Studio XE6
Indy 10.6.0

Here is my simple code:

Code:
procedure TForm2.Button2Click(Sender: TObject);
var
  i: Integer;
begin
  SNMP.Host := '172.17.40.243';
  SNMP.Port := 161;
  SNMP.Community := 'public';
  SNMP.Query.Clear;
  SNMP.Query.Version := 0;

  try
    if not SNMP.Connected then
    begin
      SNMP.Connect;
      Memo1.Lines.Add('Connected');
    end
    else
      Memo1.Lines.Add('Already connected');
  except
    on E: Exception do
    begin
      Memo1.Lines.Add('Error on connect: ' + E.Message);
      Exit;
    end;
  end;

  try
    SNMP.Query.PDUType := PDUGetRequest;
    SNMP.Query.MIBAdd(Edit1.Text, '');
    if SNMP.SendQuery then
    begin
      Memo1.Lines.Add('Value received: ' + SNMP.Reply.Value[0]);
    end
    else
    begin
      Memo1.Lines.Add('Error: ' + IntToStr(SNMP.Reply.ErrorStatus));
    end;

    SNMP.Disconnect;
  except
    on E: Exception do
    begin
      Memo1.Lines.Add('Error: ' + E.Message);
    end;
  end;
end;

This also doesn't work:

Code:
procedure TForm2.Button5Click(Sender: TObject);
var
  SNMP: TIdSNMP;
  dn, PLevel, SRate: string;
  p: Extended;
begin
  SNMP := TIdSNMP.Create(nil);
  try
    SNMP.Host := '172.17.40.243';
    SNMP.Community := 'public';
    SNMP.Query.Version := 6;

    SNMP.ReceiveTimeout := 3000;
    if SNMP.QuickSend('1.3.6.1.2.1.1.1.0', SNMP.Community, SNMP.Host, dn) then
      Memo1.Lines.Add(dn);
    if SNMP.QuickSend('1.3.6.1.4.1.28634.6.2551906584.2.8206',
SNMP.Community, SNMP.Host, SRate) then
      Memo1.Lines.Add(SRate);

    Memo1.Lines.Add('');
  finally
    SNMP.Free;
  end;
end;

In the first case, I have a positive result: (oid=1.3.6.1.2.1.1.1.0)
Code:
Connected
Value received: IB-Lite

In the second case I have an error:
Code:
Connected
Error: 2 (NoSuchName)

If I use a third-party program (MIBViewer), everything works fine:
Code:
Send snmp get request to 172.17.40.243:161
.1.3.6.1.2.1.1.1.0 (not in loaded mib files) --> IB-Lite

Send snmp get request to 172.17.40.243:161
.1.3.6.1.4.1.28634.6.2551906584.2.8213.0 (not in loaded mib files) --> 261

Can anyone tell me what the problem is? I will be very grateful for the information
Reply
#2
I merged in the information that you had emailed to me privately.

In any case, one discrepancy I see is that MIBViewer is requesting "1.3.6.1.4.1.28634.6.2551906584.2.8213" but you are requesting "1.3.6.1.4.1.28634.6.2551906584.2.8206" instead.  Is that actually the case, or just a typo?

Reply
#3
(12-13-2023, 06:18 PM)rlebeau Wrote: I merged in the information that you had emailed to me privately.

In any case, one discrepancy I see is that MIBViewer is requesting "1.3.6.1.4.1.28634.6.2551906584.2.8213" but you are requesting "1.3.6.1.4.1.28634.6.2551906584.2.8206" instead.  Is that actually the case, or just a typo?

Thank you for pointing out such a nuance, although the list includes both teams.
8213 - battery voltage.
8206 - the number of hours worked.
In the 111 program, both commands are passed, and in my program, for some reason, none of them are passed, but only the main one.
Reply
#4
And so several dozen subsequent attempts did not yield anything, everything remained as it was. I didn't think of anything smarter than sending a request via UDP... Surprisingly, everything worked without problems...
Reply
#5
(12-14-2023, 05:59 AM)STest6905 Wrote: In the 111 program, both commands are passed, and in my program, for some reason, none of them are passed, but only the main one.

Have you tried using a packet sniffer, like Wireshark, to see how the SNMP packets from TIdSNMP differ from the other program's packets? Its certainly possible that TIdSNMP might have a bug that is not creating the packets correctly, but I would need to see the raw packets from a working setup and a non-working setup to verify that.

Reply
#6
(12-15-2023, 06:15 PM)rlebeau Wrote: Have you tried using a packet sniffer, like Wireshark, to see how the SNMP packets from TIdSNMP differ from the other program's packets? Its certainly possible that TIdSNMP might have a bug that is not creating the packets correctly, but I would need to see the raw packets from a working setup and a non-working setup to verify that.

Yes, I used Wireshark to look at the traffic. Here I can provide you with a sample of this protocol. There is not much data. It was from the successful send that I used the data to send over UDP.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)