feat(core): add SNMP trap source for UDP trap ingestion #24514
+1,036
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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