feat(core): add SNMP trap source for UDP trap ingestion#24514
feat(core): add SNMP trap source for UDP trap ingestion#24514RoseSecurity wants to merge 6 commits intovectordotdev:masterfrom
Conversation
Introduce a new `snmp_trap` source to receive SNMP v1 and v2c trap messages over UDP. The source parses incoming traps, extracts fields such as community string, version, trap type, OID, and varbinds, and emits structured log events. Includes documentation, changelog, and example configuration for easy adoption.
|
Thank you for your contribution! Before we can merge this PR, please sign our Contributor License Agreement. To sign, copy and post the phrase below as a new comment on this PR.
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
pront
left a comment
There was a problem hiding this comment.
Thank you @RoseSecurity!
Findings from review of PR #24514:
Standalone feature build is broken
sources-snmp_trap uses tokio_util::udp::UdpFramed, but the feature does not enable tokio-util/net.
SNMPv2c parser accepts non-trap PDUs as traps
parse_v2c_trap matches any SnmpPdu::Generic and never checks pdu_type == TrapV2, so GetRequest, Response, InformRequest, etc. can be emitted as trap events.
uptime field type is inconsistent across versions
SNMPv1 writes uptime as integer, SNMPv2c writes it as string.
- Add PduType check to only handle TrapV2 PDU types - Fix sysUpTime extraction to properly parse TimeTicks value - Add tokio-util/net feature dependency for snmp_trap source
Thanks for the review! Just took a crack at addressing those findings |
|
Hey @RoseSecurity — just checking in on the status of this PR. Are you still actively working on it, or could you use a hand getting it across the finish line? Also curious about your plans for broader RFC compliance beyond what's here today. The current implementation covers SNMPv1 (RFC 1157) and SNMPv2c (RFC 3416) trap reception — are you planning to address any of the following in this PR or follow-up work?
Happy to help push this forward if needed. |
SNMP Trap Source
Summary
This PR adds a new
snmp_trapsource that receives SNMP v1 and v2c trap messages over UDP. SNMP traps are commonly used by network devices to report events like failures, threshold violations, or status changes to a management station.Features
Vector Config Example
Output Schema
SNMPv1 Trap Output
{ "snmp_version": "1", "source_address": "192.168.1.100:161", "community": "public", "enterprise_oid": "1.3.6.1.4.1.8072.2.3.0.1", "agent_address": "192.168.1.100", "generic_trap": 6, "specific_trap": 1, "uptime": 123456, "varbinds": [ {"oid": "1.3.6.1.4.1.8072.2.3.2.1", "value": "123456"} ], "message": "SNMPv1 trap from 192.168.1.100:161 (1.3.6.1.4.1.8072.2.3.0.1): enterpriseSpecific", "timestamp": "2024-01-15T10:30:00Z" }SNMPv2c Trap Output
{ "snmp_version": "2c", "source_address": "192.168.1.100:161", "community": "public", "request_id": 12345, "trap_oid": "1.3.6.1.4.1.8072.2.3.0.1", "uptime": "123456", "varbinds": [ {"oid": "1.3.6.1.2.1.1.3.0", "value": "123456"}, {"oid": "1.3.6.1.6.3.1.1.4.1.0", "value": "1.3.6.1.4.1.8072.2.3.0.1"} ], "message": "SNMPv2c trap from 192.168.1.100:161: 1.3.6.1.4.1.8072.2.3.0.1", "timestamp": "2024-01-15T10:30:00Z" }Test Plan
Prerequisites
snmptrapcommand (from net-snmp package)--features sources-snmp_trapManual Testing Steps
Build Vector with SNMP trap support:
Create test configuration (
test_snmp.yaml):Start Vector:
Send SNMPv2c test trap (in another terminal):
snmptrap -v 2c -c public 127.0.0.1:1162 '' \ 1.3.6.1.4.1.8072.2.3.0.1 \ 1.3.6.1.4.1.8072.2.3.2.1 i 123456Send SNMPv1 test trap:
snmptrap -v 1 -c public 127.0.0.1:1162 \ 1.3.6.1.4.1.8072.2.3.0.1 \ 127.0.0.1 6 1 '' \ 1.3.6.1.4.1.8072.2.3.2.1 i 123456Verify output: Confirm JSON output appears in Vector's console with all expected fields.
Automated Tests
Run the unit tests:
cargo test --features sources-snmp_trap snmpExpected: All 7 tests pass:
generate_config- Config generation workstest_udp_socket_bind- Can bind to UDP sockettest_config_default- Default config is correcttest_config_with_options- Config with options workstest_format_object_value- SNMP value formatting workstest_parse_invalid_data- Invalid data is rejectedtest_parse_empty_data- Empty data is rejectedChecklist
snmp-parserdependencyReferences