SNMP traps (snmp_trap)
Counts the SNMP traps and informs that a device sent to the probe, in a sliding window, optionally only those with certain trap OIDs or variable bindings, and keeps the matching ones on the sensor's page. Use it for what a device volunteers and polling cannot see: a link that went down and came back between two polls, a power supply that failed, a restart, an authentication failure. v1, v2c and v3 are read.
It is the other kind of sensor: it listens instead of asking. The listening is shared by every receiver sensor on the probe and is described, with its limits and what the probe needs, in Receivers: SNMP traps and syslog. This page is about the sensor.
What it looks like

The sensor's page after a few polls, with the traps it matched listed above the channels. Four traps were sent: two linkDown, one linkUp and one coldStart; the sensor asked for link traps only. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.
How it counts
Each poll asks the receiver for the traps that came from the device's address (and extra_sources) in the last window_secs, keeps those that match the filters, and reports how many. A trap counts at every poll until it is older than the window. So:
- With the default limit on
matched(a warning above 0), the sensor is Warning for as long as a matching trap is in the window, and Up again when none is.state_on_match: downmakes it Down instead, and the sensor's failure count then decides when that becomes an incident, as for any other sensor. - The window should be at least as long as the poll interval. A trap that arrives and ages out between two polls is never seen. The default window is 300 s for a 60 s interval.
- Messages that arrived before the sensor's first poll are not seen, and neither are those that arrive while the probe is down: the receiver keeps them in memory (see what is kept).
Matching is by source address alone. A device that sends from another address than the one it is monitored on (a router's loopback, the interface that faces the probe) needs that address in extra_sources. A trap from an address no sensor names is dropped before it is read.
Channels
| Key | Name | Unit | Default limits |
|---|---|---|---|
matched | Matching traps in the window | none | warning above 0 |
received | Traps received in the window | none | none |
dropped | Dropped by the rate limit | none | warning above 0 |
unreadable | Unreadable or unauthenticated | none | warning above 0 |
since_last_match_s | Time since the last match | s | none; unknown when nothing matched |
received counts every trap from the device in the window, whether it matched or not, so the share that matched is visible. dropped is what the rate limit cut off (the device sends faster than 100 a second, by default); when it is not 0 the counts are a minimum, and the sensor's message says so. unreadable counts datagrams from the device that were not SNMP, or v3 messages that did not authenticate with the sensor's credential: a sensor that shows only these has the wrong credential.
To count only, without the sensor going to Warning, raise the limit of matched on the sensor's page (Limits), or set it to none.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
window_secs | 300 | How far back each poll counts, 10 to 86400. The receiver keeps messages for an hour by default (PROBEWARD_RECEIVER_RETENTION_SECS); a longer window than that is cut to it, and the message says so. |
trap_oids | none (every trap) | Count only traps whose OID is one of these, or lies below one. 1.3.6.1.6.3.1.1.5.3 is linkDown; 1.3.6.1.6.3.1.1.5 is every standard trap. Compared arc by arc, so …5.3 does not match …5.31. Up to 32. |
varbinds | none | Conditions on the trap's variable bindings; all must hold. Each is { "oid": "1.3.6.1.2.1.2.2.1.8", "pattern": "^2$" }: a binding whose OID is that or lies below it, and whose value (as text) matches the regular expression. Without pattern, the binding only has to be present. Up to 16. In the form this is a list of objects, typed as JSON. |
extra_sources | none | More addresses the device sends from. Up to 16. |
state_on_match | count | count: only the channels and their limits decide. warning or down: the sensor is in that state while something matched in the window. |
Suggested interval: 60 seconds. The credential is optional: an SNMPv3 credential, set as for the other SNMP sensors, makes the sensor read v3 traps from its device (see below); a v2c credential is not needed and is ignored. The regular expressions use the Rust regex syntax, which has no look-around or backreferences, with a size limit.
A trap's variable bindings are matched as text: an integer is its number, an octet string its text if it is printable and 0x… hex if it is not, an OID its dotted form. So ifOperStatus of 2 is the string 2, and a pattern of ^2$ finds it.
What is kept for each trap
The sensor page lists the traps the sensor matched, newest first, 50 at a time, and GET /api/v1/sensors/{id}/events returns the same. A line is linkDown trap (v2c) from 192.0.2.1: ifIndex.7=7, ifDescr.7=GigabitEthernet0/7, ifAdminStatus.7=1, ifOperStatus.7=2: the standard traps are named, and the objects of the interface and system groups are given as name and instance; any other binding shows the last number of its OID. Behind each line is the parsed trap:
{
"source": "192.0.2.1",
"trap": {
"version": "2c",
"confirmed": false,
"trap_oid": "1.3.6.1.6.3.1.1.5.3",
"trap_name": "linkDown",
"uptime_ticks": 10000000,
"varbinds": [
{ "oid": "1.3.6.1.2.1.2.2.1.8.7", "name": "ifOperStatus.7", "kind": "integer", "value": "2" }
]
}
}At most 32 bindings are kept per trap and 256 characters of each value. A v1 trap is shown with the trap OID it maps to under RFC 3584 (the enterprise, then 0, then the specific trap number; the generic traps are the standard ones), and its agent address is not kept. The community is never kept, and a v3 trap shows its user name and the security level it arrived at, never keys. A sensor keeps at most 1,000 traps, and the timeline's retention applies.
SNMPv3
A v3 trap can be read only with the sender's user and keys, and the sender (not the receiver) is the authority for its own engine. The sensor reads the v3 traps of its device with the SNMPv3 credential that is set for it, in the same place as for the SNMP sensors: a user name, the authentication protocol and password, and for authPriv the privacy protocol and password. The device must be configured to send traps as that user.
- The credential's level is also the least level accepted: a sensor with an
authPrivuser does not count a v3 trap that arrived signed but not encrypted, or not signed at all. It counts them asunreadable. - A v3 trap whose user, keys or protocols are not those of the credential is counted as
unreadableand not kept. - Informs are acknowledged, v3 ones included.
- One credential covers the sensor's own addresses. Two sensors on one device must agree on it.
- The receiver derives the keys from the credential in memory and never stores or logs them.
- A device that sends v3 traps before the sensor's first poll, or without a credential on the sensor, is not read.
What the probe needs
UDP port 162, which is privileged on Linux, and a firewall that lets the device in. See what the probe needs for the capability, an unprivileged port and a container. In short, on a packaged install:
# systemctl edit probeward.service (or probeward-probe.service for a remote probe)
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICEor PROBEWARD_TRAP_LISTEN=0.0.0.0:10162 and the devices pointed at port 10162. On the device, set the trap destination to the probe's address (for a v1 or v2c trap, with any community: it is ignored).
Failures
| Message | Meaning |
|---|---|
cannot listen for SNMP trap on UDP 0.0.0.0:162: permission denied ... (kind config) | See what the probe needs. |
cannot listen for SNMP trap on UDP ...: another program on this host holds it ... (kind config) | snmptrapd or another receiver has the port. Stop it, or set PROBEWARD_TRAP_LISTEN. |
this probe already watches N devices for SNMP trap messages, the most it keeps (kind config) | PROBEWARD_RECEIVER_SOURCES is reached. |
SNMPv3 credential: ... (kind config) | The credential is incomplete or a password is too short for the protocol. |
Nothing else fails a poll. No traps is a reading: matched is 0.
Verification
- Real devices. A MikroTik RouterOS Cloud Hosted Router (SNMP trap target set, trap generator for interfaces) and a VyOS router (net-snmp, trap target set) sent v2c traps to a probe listening on port 162, read by the receiver as
linkUpandcoldStart(with their interface bindings, six on VyOS, four on RouterOS) and a net-snmp notification of its own (1.3.6.1.4.1.8072.4.0.2). The traps were provoked by adding and removing a bridge interface and switching it off and on, and by restarting the VyOS SNMP service. The live test iscrates/probeward-sensors/tests/live_receivers.rs. - The SNMP library's own sender, on loopback, for v2c traps, v2c informs (acknowledged: the sender's
send_informreturns only when the receiver's answer arrives), and v3 traps atauthPrivandauthNoPrivwith SHA-256 and AES-128: read with the right credential; the same sender with other passwords counted asunreadable; a v3 trap with no credential counted asunreadable; a signed-only trap refused by anauthPrivcredential. - Hand-built bytes for a v1 trap (enterprise, generic and specific trap, time stamp, a binding) mapped to its v2 trap OID, and for datagrams that are not SNMP.
- The filters (OID prefixes arc by arc, binding conditions, windows, events once, restarts of the receiver, the flood and the rate limit) are tested against a scripted receiver, and the limits, retention and byte budget in the store with a scripted clock. See Receivers and the acceptance scenarios.
- Not seen: v1 traps or v3 traps from a real device, informs from a real device, a device that sends from a second address, IPv6 senders, a very large trap that does not fit one datagram.
Running the live test
The test listens on the ports devices use, so it needs the privilege: run it as root in a container on the host network, with the test binary mounted into it, and while it waits make the device send something.
cargo test -p probeward-sensors --test live_receivers --no-run # prints the path of the test binary
docker run --rm --network host -v "$BIN:/t/live_receivers:ro" \
-e PROBEWARD_TEST_TRAP_SOURCE -e PROBEWARD_TEST_TRAP_OID \
-e PROBEWARD_TEST_SYSLOG_SOURCE -e PROBEWARD_TEST_SYSLOG_TEXT \
-e PROBEWARD_TEST_RECEIVER_WAIT_SECS \
debian:stable-slim /t/live_receivers --nocapture| Variable | Meaning |
|---|---|
PROBEWARD_TEST_TRAP_SOURCE | The address a device sends traps from. Also what turns the trap test on. |
PROBEWARD_TEST_TRAP_OID | Optional: the trap OID (or a prefix) that at least one trap must have. |
PROBEWARD_TEST_SYSLOG_SOURCE | The address a device sends syslog from. Turns the syslog test on. |
PROBEWARD_TEST_SYSLOG_TEXT | Optional: text that at least one syslog message must contain. |
PROBEWARD_TEST_RECEIVER_WAIT_SECS | How long to wait for the device, default 90. |