Search code examples
delphisnmpindy

Indy SNMP QuickSend failed


this is my code use QuickSend method to get sysDesc is OK but with Symbol Rate it always fail. I don't know, the same code actually works in another project I wrote before (I run it again and everything is fine).

     var
    mySNMP: TidSNMP;
    SymbolRate, sysDesc: string;

   begin
     mySNMP:=TidSNMP.Create(nil);
     try
      mySNMP.Host:=Trim(IpEdit.Text);
      mySNMP.Community:=Trim(CommEdit.Text);
      mySNMP.ReceiveTimeout:=1000;
      if mySNMP.QuickSend('1.3.6.1.2.1.1.1.0', mySNMP.Community, mySNMP.Host, sysDesc)
        then
        ShowMessage(sysDesc)
        else
        ShowMessage('Send Failed');
      if mySNMP.QuickSend('.1.3.6.1.4.1.6247.24.1.2.2.12.0',mySNMP.Community, mySNMP.Host,SymbolRate)
        then
        ShowMessage('Send OK')
        else
        ShowMessage('Send Failed');
     finally
      mySNMP.Free;
     end;

Solution

  • QuickSend() (and SendQuery() in general) returns False if:

    1. the socket is reset (it reports error code 10054, WSAECONNRESET).

    2. no response is received within the specified timeout.

    3. the response cannot be parsed.

    4. the response is parsed by contains an error code from the server (see the Reply.ErrorStatus property).

    The first thing I would suggest is for you to remove the leading . from the failing OID:

    if mySNMP.QuickSend('1.3.6.1.4.1.6247.24.1.2.2.12.0',mySNMP.Community, mySNMP.Host,SymbolRate)
    

    That way, it matches the query code in your earlier question, which was working:

    SNMP.QuickSend('1.3.6.1.4.1.6247.24.1.2.2.12.0',SNMP.Community,SNMP.Host,SRate);