Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP Trap community string tag #8189

Merged
merged 1 commit into from Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/inputs/snmp_trap/README.md
Expand Up @@ -87,15 +87,16 @@ On Mac OS, listening on privileged ports is unrestricted on versions
- version (string, "1" or "2c" or "3")
- context_name (string, value from v3 trap)
- engine_id (string, value from v3 trap)
- community (string, value from 1 or 2c trap)
- fields:
- Fields are mapped from variables in the trap. Field names are
the trap variable names after MIB lookup. Field values are trap
variable values.

### Example Output
```
snmp_trap,mib=SNMPv2-MIB,name=coldStart,oid=.1.3.6.1.6.3.1.1.5.1,source=192.168.122.102,version=2c snmpTrapEnterprise.0="linux",sysUpTimeInstance=1i 1574109187723429814
snmp_trap,mib=NET-SNMP-AGENT-MIB,name=nsNotifyShutdown,oid=.1.3.6.1.4.1.8072.4.0.2,source=192.168.122.102,version=2c sysUpTimeInstance=5803i,snmpTrapEnterprise.0="netSnmpNotificationPrefix" 1574109186555115459
snmp_trap,mib=SNMPv2-MIB,name=coldStart,oid=.1.3.6.1.6.3.1.1.5.1,source=192.168.122.102,version=2c,community=public snmpTrapEnterprise.0="linux",sysUpTimeInstance=1i 1574109187723429814
snmp_trap,mib=NET-SNMP-AGENT-MIB,name=nsNotifyShutdown,oid=.1.3.6.1.4.1.8072.4.0.2,source=192.168.122.102,version=2c,community=public sysUpTimeInstance=5803i,snmpTrapEnterprise.0="netSnmpNotificationPrefix" 1574109186555115459
```

[net-snmp]: http://www.net-snmp.org/
Expand Down
4 changes: 4 additions & 0 deletions plugins/inputs/snmp_trap/snmp_trap.go
Expand Up @@ -357,6 +357,10 @@ func makeTrapHandler(s *SnmpTrap) handler {
// SNMP RFCs like 3411 and 5343 show engine ID as a hex string
tags["engine_id"] = fmt.Sprintf("%x", packet.ContextEngineID)
}
} else {
if packet.Community != "" {
tags["community"] = packet.Community
}
}

s.acc.AddFields("snmp_trap", fields, tags, tm)
Expand Down
13 changes: 8 additions & 5 deletions plugins/inputs/snmp_trap/snmp_trap_test.go
Expand Up @@ -224,11 +224,12 @@ func TestReceiveTrap(t *testing.T) {
testutil.MustMetric(
"snmp_trap", // name
map[string]string{ // tags
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "2c",
"source": "127.0.0.1",
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "2c",
"source": "127.0.0.1",
"community": "public",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
Expand Down Expand Up @@ -305,6 +306,7 @@ func TestReceiveTrap(t *testing.T) {
"version": "1",
"source": "127.0.0.1",
"agent_address": "10.20.30.40",
"community": "public",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": uint(now),
Expand Down Expand Up @@ -358,6 +360,7 @@ func TestReceiveTrap(t *testing.T) {
"version": "1",
"source": "127.0.0.1",
"agent_address": "10.20.30.40",
"community": "public",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": uint(now),
Expand Down