SNMP-Trap-Tools(at)Work

SNMP-Trap-Tools(at)Work / Technical description

SNMP Trap Sender

Simulator that sends SNMP traps and informs like a network device, with web GUI

Version 1.2.0Revised 2026-10-11

1. Summary

SNMP Trap Sender simulates a network device that sends SNMP notifications. It can send a periodic heartbeat, simulate a reboot, take a network interface down and up, and send free-text test messages or load-test bursts, as SNMPv1 traps, SNMPv2c traps or informs, or SNMPv3 traps or informs, to one or more trap receivers.

It ships with its own MIB, TRAPSIM-MIB. Uploaded to a trap receiver, it lets the receiver show every simulated notification by name. Standard events use SNMPv2-MIB (coldStart, warmStart) and IF-MIB (linkDown, linkUp), which every receiver already knows.

It runs as a systemd service on Rocky Linux 9, either in a VM or in a Proxmox LXC container, is controlled from a web GUI in English or Norwegian, and installs from one file without internet access. It is the counterpart of SNMP Trap Receiver 2.0.

2. Purpose and scope

Simulates

One network device with name, SNMPv1 agent address, SNMPv3 engine ID, sysUpTime that restarts at a simulated reboot, and a heartbeat sequence number

Sends

SNMPv1 Trap-PDU, SNMPv2c Trap and InformRequest, SNMPv3 Trap and InformRequest (USM: noAuthNoPriv, authNoPriv, authPriv; MD5, SHA-1, SHA-2; DES, 3DES, AES-128/192/256) over UDP/IPv4 and UDP/IPv6

Events

Heartbeat, reboot (announced, cold/warm start, device up), interface down/up (IF-MIB and TRAPSIM-MIB), test message

Scenarios

Reboot with downtime, interface flap (repeated down/up), burst at a fixed rate

Schedules

Any event repeated every N seconds, for example a heartbeat every 60 s

Does not

Answer SNMP GET requests, act as a real agent, or receive traps

3. Architecture

                Rocky Linux 9 (VM or Proxmox LXC)
 ┌───────────────────────────────────────────────────────────────┐
 │  snmp-trap-sender.service  (user trapsender)                  │
 │                                                               │
 │  ┌──────────────┐  ┌────────────────────────────────────────┐ │
 │  │ Flask app on │  │ Engine: thread + asyncio event loop    │ │
 │  │ Waitress     ├─►│  send()     schedules     scenarios    │ │
 │  │ (8 threads)  │  │  one pysnmp SnmpEngine per target      │ │
 │  └──────▲───────┘  └──────────┬───────────────────┬─────────┘ │
 │         │                     │                   │           │
 │  state.json (device,          │ history (2000)    │           │
 │  targets, schedules)          │ + sent_traps.jsonl│           │
 └─────────┼─────────────────────┼───────────────────┼───────────┘
           │ HTTP 8082           │ UDP → 162         │ UDP → 162
      ┌────┴────┐        ┌───────┴────────┐  ┌───────┴────────┐
      │ browser │        │ trap receiver 1│  │ trap receiver 2│
      └─────────┘        └────────────────┘  └────────────────┘

One process contains everything. All SNMP traffic runs in one asyncio event loop in its own thread. Web requests hand work to that loop with run_coroutine_threadsafe and wait for the result. Schedules and scenarios are asyncio tasks in the same loop, so they never block the GUI.

The engine keeps one pysnmp SnmpEngine per target. When several targets share one engine, pysnmp’s high-level API also sends later notifications to the targets of earlier calls. Separate engines avoid that, and they also let a v3 target use the device’s own engine ID. An engine is rebuilt when its target or the engine ID changes.

3.1. Modules

Module Responsibility

trapsender/events.py

The event catalogue: OID per event, parameters, validation, and how each event becomes variable bindings

trapsender/engine.py

Engine: sending, schedules, scenarios, history, sent-log, statistics

trapsender/state.py

Simulated device, targets and schedules in state.json; validation; secrets kept out of the GUI

trapsender/config.py

/etc/snmp-trap-sender/config.ini (web, limits, storage)

trapsender/web.py

Flask GUI and JSON API: login, CSRF, security headers

trapsender/i18n.py

GUI texts in English and Norwegian (196 keys; both languages must have the same keys)

trapsender/manual.py

Shows the user manual (docs/en/User-Manual.md, docs/no/Brukermanual.md) in the GUI. A small Markdown renderer without dependencies: all text is HTML-escaped first, links may only point to #anchors or http(s)

trapsender/selftest.py

End-to-end test with a temporary local receiver

trapsender/main.py

Command line: serve, set-password, add-target, send, selftest, version

trapsender/mib/TRAPSIM-MIB.mib

The simulator’s MIB

4. Events

Every notification starts with sysUpTime.0 (the simulated device’s uptime) and snmpTrapOID.0. For SNMPv1 targets, snmpTrapAddress.0 is added when an agent address is set. pysnmp uses it as the agent-addr field of the Trap-PDU (RFC 3584), and it converts the notification OID into the v1 enterprise, generic-trap and specific-trap fields.

Event Notification Variables

Heartbeat

TRAPSIM-MIB::tsimHeartbeat

tsimDeviceName, tsimSequence (1, 2, 3 … since the last reboot), tsimInterval

Reboot announced

TRAPSIM-MIB::tsimReboot

tsimDeviceName, tsimRebootReason, tsimDowntime, tsimMessage

Device up

TRAPSIM-MIB::tsimDeviceUp

tsimDeviceName, tsimRebootReason, tsimDowntime

Interface down / up

TRAPSIM-MIB::tsimInterfaceDown / tsimInterfaceUp

tsimDeviceName, tsimIfIndex, tsimIfName, tsimIfAlias, tsimSeverity, tsimMessage

Test message

TRAPSIM-MIB::tsimTestMessage

tsimDeviceName, tsimSeverity, tsimMessage

coldStart / warmStart

SNMPv2-MIB::coldStart / warmStart

–

linkDown / linkUp

IF-MIB::linkDown / linkUp

ifIndex.n, ifAdminStatus.n = up(1), ifOperStatus.n = down(2) / up(1), plus ifName.n and ifAlias.n as many vendors add them

Parameters are validated on the server: ifIndex 1…2147483647, downtime 0…86400 s, severity and reason from the MIB enumerations, interface name and description up to 64 characters, message up to 255.

5. TRAPSIM-MIB

The MIB is SMIv2 and passes smilint -l 6 (libsmi’s strictest level) without remarks. It sits under enterprise 32473, which IANA reserves for documentation and examples (RFC 5612), so it never collides with a real vendor’s OIDs.

1.3.6.1.4.1.32473            example (RFC 5612)
 └─ .1                       trapSimRoot
     └─ .1                   trapSimMIB (MODULE-IDENTITY)
         ├─ .0               trapSimNotifications
         │   ├─ .1  tsimHeartbeat       .4  tsimInterfaceDown
         │   ├─ .2  tsimReboot          .5  tsimInterfaceUp
         │   ├─ .3  tsimDeviceUp        .6  tsimTestMessage
         ├─ .1               trapSimObjects (accessible-for-notify)
         │   ├─ .1 tsimDeviceName   .5 tsimRebootReason   .9  tsimIfAlias
         │   ├─ .2 tsimSequence     .6 tsimDowntime       .10 tsimMessage
         │   ├─ .3 tsimInterval     .7 tsimIfIndex
         │   └─ .4 tsimSeverity     .8 tsimIfName
         └─ .2               trapSimConformance (compliance and groups)

Enumerations: TrapSimSeverity = clear(1), info(2), warning(3), minor(4), major(5), critical(6); TrapSimRebootReason = operatorRequest(1), softwareUpgrade(2), powerFailure(3), watchdog(4), crash(5), scheduled(6).

The file is in Documentation/MIB/, in Offline-Installation/, in the installed program (/opt/snmp-trap-sender/app/trapsender/mib/), and can be downloaded from the Device tab.

6. Scenarios

Reboot

Sends tsimReboot (reason, downtime). Then the device is "down" for the downtime: scheduled notifications pause and the GUI shows Device rebooting. After that, sysUpTime and the heartbeat sequence restart at 0, and the scenario sends coldStart (or warmStart) and tsimDeviceUp. This is the order a real device produces, so it is a good test of rules on the receiving side.

Interface flap

For count times: interface down, wait down seconds, interface up, wait up seconds. The notifications are IF-MIB linkDown/linkUp, TRAPSIM tsimInterfaceDown/Up, or both.

Burst

count notifications of one event at rate per second. The pace follows a fixed timetable, so a slow send does not stretch the whole burst. Limits: max_rate (default 500/s) and max_burst (default 100 000).

Scenarios send to all enabled targets, run in the background, show their progress in the GUI, and can be cancelled. Cancelling a reboot ends the "down" state at once.

7. Schedules

A schedule repeats one event with fixed parameters every interval seconds (1…86 400) to all enabled targets or to selected ones. The first send happens when the schedule is started. On a fresh install, a disabled Heartbeat schedule exists. The installer can enable it with --heartbeat N. Schedules are saved in state.json and start again with the service.

8. Targets

A target is one trap receiver: host name or IP address (IPv4 or IPv6), UDP port, SNMP version, trap or inform, community (v1/v2c) or USM user with protocols and keys (v3), timeout and retries (used by informs), and an enabled switch.

  • Traps are fire-and-forget. Sent means the packet left the sender, not that a receiver accepted it.

  • Informs are acknowledged by the receiver. A missing acknowledgement after the timeout and retries is shown as an error. Informs are the way to check that the receiver really got the notification.

  • SNMPv3 traps are sent with the simulated device’s engine ID as the authoritative engine. The receiver must have the same user for that engine ID. The GUI shows the line to put in SNMP Trap Receiver’s configuration ([v3user:NAME] … engine_id = …).

Communities and v3 keys are stored in state.json (mode 0600, readable by the service user only). They are never sent back to the browser. The edit form shows "unchanged" and keeps the stored value when the field is left empty.

9. Simulated device

Name

Sent as tsimDeviceName. The installer sets it to the host name.

Agent address

Optional IPv4 address put into SNMPv1 traps as agent-addr, so the trap seems to come from another device

sysUpTime

Counts from the last (simulated) reboot, in hundredths of a second, wraps at 232

Heartbeat sequence

+1 per heartbeat (the same number to all targets), back to 0 at a reboot. A receiver can spot lost heartbeats from gaps.

Engine ID

RFC 3411 format: 80007ed905 (enterprise 32473, octets) + 6 random bytes. Created at the first start. New engine ID in the GUI makes a new one.

10. Web GUI and API

10.1. Pages

Send

Quick buttons (Heartbeat, Reboot, Interface down, Interface up), a form for any event with its parameters and selected targets, scenarios, and running or recent scenarios with Cancel

Schedules

Table with an on/off switch per schedule; create, edit, delete

Targets

Table; create, edit, delete, Test (sends a test message to that target and shows the result)

History

The last 2000 notifications with time, notification, target, version, origin (manual, schedule, scenario, CLI) and result; filter; download the log

Device

Simulated device, uptime, sequence, reboots, engine ID, counters; download TRAPSIM-MIB

Top bar

Device up / Device rebooting (n s), device name and uptime, EN/NO, log out

Footer

Version, Licences, Licence report, Third-party notices

10.2. Endpoints

Path Method Purpose

/login, /logout, /lang/<en|no>

Session and language

/healthz

GET

{"ok": true, "version": "1.2.0"} without login

/manual

GET

User manual in the selected language, with contents and search. The Manual button links to /manual#<tab>

/api/meta

GET

Event catalogue, enumerations, limits

/api/status

GET

Device, uptime, down state, counters, scenarios

/api/send

POST

{"event", "params", "targets"} → result per target

/api/scenario

POST

{"kind": "reboot|flap|burst", "params"}

/api/scenario/<id>/cancel

POST

Cancel

/api/targets

GET/POST

List (without secrets) / create or update

/api/targets/<id>/test, …/delete

POST

Test / delete

/api/jobs

GET/POST

Schedules

/api/jobs/<id>/enable, …/delete

POST

On/off / delete

/api/history?since=N

GET

Sent notifications with id > N

/api/device, /api/device/engine-id

POST

Device name and agent address / new engine ID

/download/mib, /download/log

GET

TRAPSIM-MIB / sent_traps.jsonl

/api/legal, /api/legal/<report|notices>

GET

Licence data

10.3. Security

The same model as SNMP Trap Receiver: one password (scrypt hash), session cookie HttpOnly + SameSite=Strict, back-off after 5 failed logins, CSRF token on every POST, Content-Security-Policy: default-src 'self' without inline script, X-Frame-Options: DENY, nosniff, and all values escaped before they are shown. Request bodies are limited to 256 KB.

The sender can be used to flood a receiver (burst). Access to the GUI should therefore be limited to the people who run tests.

11. Configuration

/etc/snmp-trap-sender/config.ini (root:trapsender, 0640). Restart the service after a change.

Section Key Default Meaning

[web]

host, port

0.0.0.0, 8082

Web GUI address

auth, password_hash, secret_key

true, set by installer

Login

default_language

en

en or no

session_hours

12

[sender]

max_rate

500

Upper limit for bursts, per second

max_burst

100000

Largest burst

history_size

2000

Notifications kept for the History tab

[storage]

data_dir

/var/lib/snmp-trap-sender

state.json

log_dir

/var/log/snmp-trap-sender

sent_traps.jsonl

log_max_mb, log_backups

20, 5

Log rotation

Targets, schedules and the device are edited in the GUI and stored in state.json.

12. Log format

Each line of sent_traps.jsonl is one sent notification:

{"id": 42, "time": "2026-10-02 12:20:53", "ts": 1790936453.2,
 "event": "sim_if_down", "trap": "TRAPSIM-MIB::tsimInterfaceDown",
 "origin": "manual", "target": "Receiver", "target_id": "1cce00181e",
 "dest": "172.16.101.83:162", "version": "v2c", "notify": "trap",
 "params": {"if_index": 1, "if_name": "GigabitEthernet0/1",
            "if_alias": "Uplink", "severity": "major",
            "message": "Fibre cut on uplink"},
 "result": "sent", "error": "", "ms": 1.4}

result is sent, acknowledged (inform answered) or error.

13. Installation and operation

13.1. Files

Path

Owner, mode

Content

/opt/snmp-trap-sender/

root

Program, Python environment, documentation; .previous/ after an upgrade

/etc/snmp-trap-sender/config.ini

root:trapsender, 0640

Configuration

/var/lib/snmp-trap-sender/state.json

trapsender, 0600

Device, targets (with secrets), schedules

/var/log/snmp-trap-sender/

trapsender, 0750

sent_traps.jsonl and rotations

/usr/local/bin/snmp-trap-sender

root, 0755

Command line

13.2. systemd and LXC

The service runs as the system user trapsender with no capabilities. Sending to port 162 needs no privileges, because the source port is a random high port. The unit itself only sets NoNewPrivileges, an empty CapabilityBoundingSet and UMask=0027, which works in every container.

Further sandboxing is in a drop-in, snmp-trap-sender.service.d/hardening.conf (ProtectSystem=strict, PrivateTmp, PrivateDevices, ProtectKernel*, RestrictNamespaces, RestrictAddressFamilies, …). It needs mount namespaces. They work in VMs and in Proxmox LXC containers with nesting turned on, the default for new unprivileged containers. Without nesting, systemd stops the service with status=226/NAMESPACE. The installer notices this, removes the drop-in, starts again and says so. --no-hardening skips the drop-in from the start.

The service does not listen on any SNMP port, so only the web port needs to be open.

13.3. Command line

snmp-trap-sender serve

Run (used by systemd)

snmp-trap-sender set-password [--password-stdin | --generate]

Web password (root)

snmp-trap-sender add-target HOST [--port N] [--version v1|v2c] [--community C] [--heartbeat N]

Add a target; restart the service afterwards

snmp-trap-sender send EVENT [-p name=value …] [-t TARGET_ID]

Send one event now, e.g. send link_down -p if_index=3 -p if_name=Gi0/3. Events: heartbeat, sim_reboot, sim_device_up, sim_if_down, sim_if_up, test_message, cold_start, warm_start, link_down, link_up

snmp-trap-sender selftest

End-to-end test (see Verification)

snmp-trap-sender version

13.4. Offline installer

The same design as SNMP Trap Receiver. A bash header checks the SHA-256 of the appended archive with python3, unpacks it with the safe tarfile data filter and starts install.sh. That script checks OS, Python 3.9, architecture, glibc ≥ 2.34 and file checksums. It then builds a virtual environment from the bundled wheels only (no network), installs program, user, configuration and systemd unit, optionally adds a target and heartbeat, starts the service, waits for /healthz and runs the self-test. An upgrade keeps configuration, state.json and logs, and moves the previous program to .previous/.

build-offline-installer.sh builds it on any machine with internet. It downloads the wheels in Application/requirements.lock for CPython 3.9 on x86_64 and aarch64, generates the licence files and the GPL scan, verifies an offline install with Python 3.9 when the build machine has it, and runs pip-audit when installed.

14. Verification

snmp-trap-sender selftest starts a pysnmp receiver on a free port on 127.0.0.1 (community selftest plus one SHA-256/AES-128 v3 user for the sender’s engine ID) and uses temporary directories. It checks:

  • state.json has mode 0600; four targets (v1, v2c trap, v2c inform, v3 authPriv) are saved; an invalid host is refused;

  • every one of the 10 events is received through all four targets with the right snmpTrapOID; the versions v1, v2c and v3 arrive; informs are acknowledged; the v1 agent address is the simulated one; the heartbeat carries device name and sequence 1; linkDown carries ifIndex, ifAdminStatus = up and ifOperStatus = down;

  • the reboot scenario produces tsimReboot → coldStart → tsimDeviceUp and resets sysUpTime, sequence and reboot counter; a flap ×2 with both styles produces 8 notifications; a burst of 40 at 100/s takes between 0.3 and 3 s and delivers all 40;

  • a 1 s heartbeat schedule produces increasing sequence numbers; history and log are written; an inform to a port without a receiver reports an error;

  • web: login, wrong password, English default, CSRF, sending through the API, refusal of invalid parameters, no secrets in the target list, editing a target keeps its keys, starting a scenario, MIB download, user manual in English and Norwegian, Norwegian page, security headers, licence inventory and documents in both languages.

The installer runs the self-test after every installation (46 checks).

15. Limits

  • HTTP only; put a TLS reverse proxy in front or use an SSH tunnel across untrusted networks.

  • One simulated device per installation. For several devices, run several containers.

  • The simulator does not answer SNMP GET, so a receiver that polls the device after a trap gets no answer.

  • Measured on one core: about 1000 v2c traps per second in a burst. The pysnmp engine is the limit.

16. Licences

All third-party components are under permissive licences. See License-Report.md, THIRD_PARTY_NOTICES.txt and third_party_inventory.json. TRAPSIM-MIB is part of this project and may be used, copied and changed freely.

Appendix A: Ports

Port

Protocol

Direction

Purpose

8082

TCP

in

Web GUI (configurable)

162 (configurable per target)

UDP

out

Traps and informs to the receivers

The counterpart that receives and shows the notifications: Technical description for SNMP Trap Receiver