gescheit / fastsnmp

Fast SNMP poller
MIT License
19 stars 7 forks source link

Support for SNMP traps (v2 at least) #23

Open mitchell-es opened 1 year ago

mitchell-es commented 1 year ago

Support for SNMP v2 traps would be nice. I actually have it working and could provide a pull request but it's such a small change I'm not sure it's worth it a pull request. Simply adding ASN_SNMP_TRAP2 to the list of packet types works. SNMP v1 traps have such an oddball format and are so rarely used I'm not sure adding support for them is worth the effort. It isn't for me.

diff --git a/fastsnmp/snmp_parser.pyx b/fastsnmp/snmp_parser.pyx
index 2420cc3..a6060f0 100644
--- a/fastsnmp/snmp_parser.pyx
+++ b/fastsnmp/snmp_parser.pyx
@@ -640,7 +640,7 @@ cdef tuple sequence_decode_c(const unsigned char *stream, const size_t stream_le
             objects.append(object_str)
         elif tag == ASN_U_NULL:
             objects.append(None)
-        elif tag == ASN_U_SEQUENCE or tag == ASN_SNMP_RESPONSE or tag == ASN_SNMP_GETBULK:
+        elif tag == ASN_U_SEQUENCE or tag == ASN_SNMP_RESPONSE or tag == ASN_SNMP_GETBULK or tag == ASN_SNMP_TRAP2:
             tmp_list_val, ex = sequence_decode_c(stream_char, length)
             if tmp_list_val is not None:
                 objects.append(tmp_list_val)