Skip to content

Receivers: SNMP traps and syslog ​

Most sensors ask a device a question. Two do not: the snmp_trap and syslog sensors count what a device sends to the probe. This page is the design: how the listening is arranged, what is kept, how a flood is held back, and what to set up on the probe. Each sensor's own page has its parameters and channels. NetFlow, IPFIX and sFlow are collected the same way and keep aggregates instead of messages; see flow collectors.

The shape ​

A sensor is still polled, and still produces channels with limits, so the failure count, incidents, acknowledgement, maintenance windows and notifications work on it as they do on every other kind. What is new is where the numbers come from:

device ──UDP 162 / 514, TCP 514──▶ receiver (one per probe process) ──▶ store (memory, bounded)
                                                                           ▲
sensor poll: "what did these addresses send in the last N seconds?" ───────┘
  • One receiver per probe process. The core's local probe has one, and every remote probe has one. It is shared by all the receiver sensors that probe polls, so a hundred syslog sensors still mean one socket on port 514. A probe that has no receiver sensor listens on nothing: the first poll of a trap or syslog sensor opens the port its kind needs (UDP 162 for traps; UDP and TCP 514 for syslog), and it stays open until the process ends.
  • A message belongs to the device whose address it came from. There is no other matching rule. A sensor watches the address of its device, and optionally more addresses (extra_sources) for a router that sends from a loopback address. The first poll of a sensor is what starts the watching; a datagram from an address nobody watches is dropped before it is read, and a message that arrived before the sensor's first poll is lost.
  • The poll counts. It asks the store for the messages of its addresses in a sliding window (window_secs), applies its filters, and reports the counts as channels. A message counts at every poll until it is older than the window, which is why a sensor that is set to Down on a match stays Down for the window and then recovers by itself. Keep the window at least as long as the poll interval: a message that arrives and ages out between two polls is never seen.
  • Alerting is the normal alerting. matched has a default limit (a warning above 0) and state_on_match can make a match Warning or Down on its own; the sensor's failure count decides when that becomes an incident. A trap or syslog line is never itself an incident. See the acceptance scenarios.
  • The probe does the work, on any probe. A remote probe reads its own sockets and sends the poll's result to the core like any other, so a device in a branch office sends to the probe in that office. Nothing about the receiver needs a new connection between the probe and the core.

What is read ​

SNMP. v1 and v2c traps and v2c informs from every watched source; v3 traps and informs from a source whose sensor has an SNMPv3 credential (see the trap sensor's page). Informs are acknowledged, so a sender does not retransmit them. The SNMP protocol work is done by the same library the SNMP sensors use. A v1 or v2c community is read and thrown away: it is a credential, it proves nothing (it travels in clear), and the source address is what matches a message to a device. Nothing about it reaches the store, the logs or the API.

Syslog. RFC 5424 and RFC 3164, over UDP (one message per datagram) and TCP (RFC 6587: octet-counted or one message per line). A header that cannot be read does not lose the message: it is kept as text with facility user and severity notice. Messages are cut to 2,048 characters and control characters are removed. Syslog over TLS is not implemented; terminate TLS in front of the probe (a relay such as rsyslog or stunnel on the same host that forwards to 127.0.0.1 on the TCP port) and give the probe a loopback address to listen on.

What is kept, and for how long ​

There are two stores, for two purposes.

WhatWhereForBounded by
Every message of a watched device, to be countedThe probe's memoryPROBEWARD_RECEIVER_RETENTION_SECS (1 hour)Messages per device, bytes in all, devices watched
The messages a sensor matched, to be readThe core's database (sensor_events)The timeline's retention (Settings, 365 days by default)1,000 per sensor

The first is what the counts are computed from. It is lost when the probe restarts, which is why a restart is a gap in the counts, never a cause for a page. The second is what the sensor's page lists ("Recent traps", "Recent messages"), with the parsed message behind a disclosure, and what GET /api/v1/sensors/{id}/events serves. A message is stored once, however many polls its window covers it for, and stays after the sensor has recovered. Credentials never appear in either (see below).

Limits, so that a flood cannot overload the server ​

LimitDefaultVariable
Messages per second one device may send, sustained100PROBEWARD_RECEIVER_RATE
Messages one device may send at once500PROBEWARD_RECEIVER_BURST
Messages kept per device and kind1,000PROBEWARD_RECEIVER_MESSAGES
How long a message is kept3,600 sPROBEWARD_RECEIVER_RETENTION_SECS
Bytes kept in all64 MiBPROBEWARD_RECEIVER_BYTES
Devices watched at once on one probe1,024PROBEWARD_RECEIVER_SOURCES
How long a device stays watched after its sensor last asked6 hPROBEWARD_RECEIVER_WATCH_SECS
Open syslog TCP connections256fixed
Largest syslog TCP frame16 KiBfixed

Each is read where the receiver runs: the core's environment for the local probe, the probe's own environment (probe.env) for a remote one. A value that does not parse or is out of range is ignored, so a typo cannot switch a protection off.

How they act, from the outside in:

  1. A datagram from an address no sensor watches is counted and dropped before it is read. A TCP connection from one is closed at once.
  2. Each watched device has its own token bucket. A message that finds it empty is dropped and counted against that device, so the sensor reports dropped (and says so in its message) instead of hiding the flood, and one noisy device cannot use up another's allowance.
  3. Each device's newest messages are kept up to the count and the retention time. When messages inside the sensor's window were evicted for want of room, the counts are a minimum, and the sensor's message says so.
  4. The byte budget is shared: a device that would go over it gives up its own oldest messages first.

An unreadable datagram, or a v3 message that fails authentication, is counted too (unreadable), because a sensor that suddenly shows only unreadable messages usually has a wrong credential.

What the probe needs ​

The receiver listens on the ports devices send to by default: UDP 162 (traps) and UDP and TCP 514 (syslog). Both are privileged on Linux. Either give the probe the capability, or listen on a port above 1023 and send the devices there.

  • The capability. The packaged services drop every capability, so give this one back with a drop-in, for the server's local probe (probeward.service) or a remote probe (probeward-probe.service):

    ini
    # systemctl edit probeward-probe.service
    [Service]
    AmbientCapabilities=CAP_NET_BIND_SERVICE
    CapabilityBoundingSet=CAP_NET_BIND_SERVICE

    then systemctl restart the service. Do not use setcap on the binary: an update replaces the file and the file capability with it. In a container, --cap-add NET_BIND_SERVICE (Docker's default already allows it for root) and --network host (or publish the UDP and TCP ports) are enough.

  • An unprivileged port. Set PROBEWARD_TRAP_LISTEN=0.0.0.0:10162 and PROBEWARD_SYSLOG_LISTEN=0.0.0.0:10514 and point the devices at those ports. Devices that cannot send to another port than 162 or 514 need the capability.

  • A firewall has to let the devices in: UDP 162, UDP and TCP 514 (or the ports you chose). The probe's host firewall, and any between the device and the probe.

  • Addresses. PROBEWARD_TRAP_LISTEN and PROBEWARD_SYSLOG_LISTEN take address:port; the default address is 0.0.0.0 (all IPv4 interfaces). Use [::]:162 to listen on IPv6 too where the system's dual-stack setting allows it, or a single address to listen on one interface only. PROBEWARD_SYSLOG_TCP=off stops the TCP listener.

  • Another program on the port (snmptrapd, rsyslog) stops the probe from listening. The poll fails with the message that says so, and tries again about ten seconds later.

If the port cannot be opened, the sensor's poll fails with kind config, and the message says what to do:

text
cannot listen for SNMP trap on UDP 0.0.0.0:162: Permission denied (os error 13). Port 162 is privileged: give the
probe the CAP_NET_BIND_SERVICE capability (systemd: AmbientCapabilities=CAP_NET_BIND_SERVICE) or run it as root, or
set PROBEWARD_TRAP_LISTEN to a port above 1023 (for example 10162) and send the devices there

If only the TCP port cannot be opened, the poll still works, and the sensor's message says that TCP is not listening.

Security ​

  • Anyone who can reach the port can send a message that claims to be from a device: UDP source addresses can be forged, and v1, v2c and syslog messages carry no proof of who sent them. A match is therefore evidence, not proof. Keep the ports reachable only from the devices (a firewall, or a network the devices share with the probe), and use SNMPv3 with authentication where the device supports it: a v3 message is read only if it authenticates with the sensor's credential, and at the level that credential names or better.
  • Nothing a device sends can name a credential into the store. The community is dropped on the way in. A v3 credential is held by the receiver in memory only, for the sources of the sensors that use it, and is never logged or stored; the messages kept carry the v3 user name and level, not the keys.
  • Messages are untrusted text: bounded, cleaned of control characters, and shown as plain text in the interface and the API.
  • A flood is bounded, as above, in memory per device and in all. The receiver reads UDP in one task per port, so a flood costs the probe CPU for the datagrams it reads but never database writes: only a sensor's matches reach the database, at most 50 per poll.

Where it lives in the code ​

PartFile
The store, the token buckets, the limits (pure, the time is an argument)crates/probeward-sensors/src/proto/receiver/store.rs
The syslog reader.../receiver/syslog.rs
The trap reader (the library's socketless processor; v3 credentials by source).../receiver/trap.rs
The sockets, the TCP framing, the process-wide receiver.../receiver/listen.rs
The trait the sensors use, so tests script it.../receiver/mod.rs (ReceiverClient), testing.rs (FakeReceivers)
The two sensors and what they sharecrates/probeward-sensors/src/sensors/{snmp_trap,syslog,receiver_common}.rs
What a poll hands to the page: SensorEventcrates/probeward-model/src/event.rs
The database table and its repositorycrates/probeward-store/migrations/0011_sensor_events.sql, src/events.rs
The journal item, the API routecrates/probeward-server/src/runtime/journal.rs, src/api/sensor_events.rs

The engine is unchanged: it never touches a socket and takes the time as an argument, and a receiver sensor reaches it as a poll result like any other.

AGPL-3.0-only