title: How to send SNMP v2 trap using Ararat Synapse?‏
body: <p>I've tried to modify the TrapSend.dpr sample project which I downloaded from <a href="http://synapse.ararat.cz/files/contrib/Trap.zip">http://synapse.ararat.cz/files/contrib/Trap.zip</a> to send SNMP v2 traps without success. Note: I'm able to successfully send SNMP v1 traps using the sample.</p>
  
  <p>This is the original function SendTrap in SNMPTrap.pas:</p>
  
  <pre><code>function SendTrap(Dest, Source, Enterprise, Community: string;
    Generic, Specific, Seconds: integer; MIBName, MIBValue: string; MIBtype:integer): integer;
  var
    SNMP: TTrapSNMP;
  begin
    SNMP := TTrapSNMP.Create;
    try
      SNMP.SNMPHost := Dest;
      SNMP.Trap.TrapHost := Source;
      SNMP.Trap.Enterprise := Enterprise;
      SNMP.Trap.Community := Community;
      SNMP.Trap.GenTrap := Generic;
      SNMP.Trap.SpecTrap := Specific;
      SNMP.Trap.TimeTicks := Seconds;
      SNMP.Trap.MIBAdd(MIBName,MIBValue,MIBType);
      Result := SNMP.Send;
    finally
      SNMP.Free;
    end;
  end;
  </code></pre>
  
  <p>After reading the example in <a href="http://en.it-usenet.org/thread/14303/3313/">http://en.it-usenet.org/thread/14303/3313/</a>, I modified SNMPTrap.pas to the following to send a generic linkdown SNMP v2 trap but it didn't work:</p>
  
  <pre><code>function SendTrap(Dest, Source, Enterprise, Community: string;
    Generic, Specific, Seconds: integer; MIBName, MIBValue: string; MIBtype:integer): integer;
  var
    SNMP: TTrapSNMP;
  begin
    SNMP := TTrapSNMP.Create;
    try
      SNMP.SNMPHost := Dest;
    //  SNMP.Trap.TrapHost := Source;
    //  SNMP.Trap.Enterprise := Enterprise;
      SNMP.Trap.Community := Community;
    //  SNMP.Trap.GenTrap := Generic;
    //  SNMP.Trap.SpecTrap := Specific;
     // SNMP.Trap.TimeTicks := Seconds;
  
    SNMP.Trap.Version := SNMP_V2C;
    SNMP.Trap.PDUType := PDUTrapV2;
  
     // SNMP.Trap.MIBAdd(MIBName,MIBValue,MIBType);
      SNMP.Trap.MIBAdd('1.3.6.1.2.1.1.3.0','0',ASN1_TIMETICKS);
      SNMP.Trap.MIBAdd('1.3.6.1.6.3.1.1.4.1.0','1.3.6.1.6.3.1.1.5.3',ASN1_OBJID);
      Result := SNMP.Send;
    finally
      SNMP.Free;
    end;
  end;
  </code></pre>
  
  <p>Wireshark returned the following error:</p>
  
  <pre><code>No.     Time           Source                Destination           Protocol Length Info
    50494 2016.821366000 192.168.0.125         192.168.0.10          SNMP     117    snmpV2-trap
  
  Frame 50494: 117 bytes on wire (936 bits), 117 bytes captured (936 bits) on interface 0
  Ethernet II, Src: IntelCor_0b:d9:b8 (00:24:d7:0b:d9:b8), Dst: Hewlett-_48:5c:54 (00:23:7d:48:5c:54)
  Internet Protocol Version 4, Src: 192.168.0.125 (192.168.0.125), Dst: 192.168.0.10 (192.168.0.10)
  User Datagram Protocol, Src Port: 63309 (63309), Dst Port: snmptrap (162)
  Simple Network Management Protocol
      version: v2c (1)
      community: public
      data: snmpV2-trap (7)
          snmpV2-trap
              BER Error: Wrong field in sequence  expected class:UNIVERSAL(0) tag:2(INTEGER) but found class:UNIVERSAL(0) tag:6
                  [Expert Info (Warn/Malformed): BER Error: Wrong field in sequence]
                      [Message: BER Error: Wrong field in sequence]
                      [Severity level: Warn]
                      [Group: Malformed]
              BER Error: Wrong field in sequence  expected class:UNIVERSAL(0) tag:2(INTEGER) but found class:APPLICATION(1) tag:0
                  [Expert Info (Warn/Malformed): BER Error: Wrong field in sequence]
                      [Message: BER Error: Wrong field in sequence]
                      [Severity level: Warn]
                      [Group: Malformed]
              error-index: 0
              BER Error: Wrong field in sequence  expected class:UNIVERSAL(0) tag:16(SEQUENCE) but found class:UNIVERSAL(0) tag:2
                  [Expert Info (Warn/Malformed): BER Error: Wrong field in sequence]
                      [Message: BER Error: Wrong field in sequence]
                      [Severity level: Warn]
                      [Group: Malformed]
              BER Error: This field lies beyond the end of the known sequence definition.
                  [Expert Info (Warn/Malformed): BER Error: Unknown field in Sequence]
                      [Message: BER Error: Unknown field in Sequence]
                      [Severity level: Warn]
                      [Group: Malformed]
              BER Error: This field lies beyond the end of the known sequence definition.
                  [Expert Info (Warn/Malformed): BER Error: Unknown field in Sequence]
                      [Message: BER Error: Unknown field in Sequence]
                      [Severity level: Warn]
                      [Group: Malformed]
  </code></pre>
  
  <p>For comparison, I've included a correctly formed v2 SNMP trap (which I sent using ireasoning's trap sender).</p>
  
  <pre><code>No.     Time           Source                Destination           Protocol Length Info
       54 7.697996000    192.168.0.125         192.168.0.10          SNMP     111    snmpV2-trap SNMPv2-MIB::sysUpTime.0 SNMPv2-MIB::snmpTrapOID.0
  
  Frame 54: 111 bytes on wire (888 bits), 111 bytes captured (888 bits) on interface 0
  Ethernet II, Src: IntelCor_0b:d9:b8 (00:24:d7:0b:d9:b8), Dst: Hewlett-_48:5c:54 (00:23:7d:48:5c:54)
  Internet Protocol Version 4, Src: 192.168.0.125 (192.168.0.125), Dst: 192.168.0.10 (192.168.0.10)
  User Datagram Protocol, Src Port: 53423 (53423), Dst Port: snmptrap (162)
  Simple Network Management Protocol
      version: v2c (1)
      community: public
      data: snmpV2-trap (7)
          snmpV2-trap
              request-id: 75820535
              error-status: noError (0)
              error-index: 0
              variable-bindings: 2 items
                  SNMPv2-MIB::sysUpTime.0 (1.3.6.1.2.1.1.3.0): 0
                      Object Name: 1.3.6.1.2.1.1.3.0 (SNMPv2-MIB::sysUpTime.0)
                      Value (Timeticks): 0
                  SNMPv2-MIB::snmpTrapOID.0 (1.3.6.1.6.3.1.1.4.1.0): 1.3.6.1.6.3.1.1.5.3 (IF-MIB::linkDown)
                      Object Name: 1.3.6.1.6.3.1.1.4.1.0 (SNMPv2-MIB::snmpTrapOID.0)
                      Value (OID): 1.3.6.1.6.3.1.1.5.3 (IF-MIB::linkDown)
  </code></pre>