Skip to content

Add strongswan IPsec extend script#622

Open
lirone wants to merge 1 commit into
librenms:masterfrom
lirone:strongswan
Open

Add strongswan IPsec extend script#622
lirone wants to merge 1 commit into
librenms:masterfrom
lirone:strongswan

Conversation

@lirone

@lirone lirone commented Jun 10, 2026

Copy link
Copy Markdown

Add strongswan IPsec extend script

Companion agent script for the new strongSwan / IPsec application proposed in
librenms/librenms#19858.

It outputs the LibreNMS JSON SNMP extend
payload describing every IPsec connection on a strongSwan host:

  • per-connection state, inbound/outbound traffic, installed child SAs, and
    re-establishment count
  • global daemon counters (IKE/child rekeys, invalid / invalid SPI errors)

It works by parsing swanctl --list-sas and swanctl --counters. The raw per-SA byte/packet
counters reset on every rekey, so the script keeps a small state file
(/var/lib/librenms-strongswan-state.json) and emits monotonic cumulative counters, giving
LibreNMS clean DERIVE rates instead of spikes at each rekey.

Connection labels come from the OPNsense config.xml when present (covers both the legacy
"Tunnel Settings" con<N> model and the new "Connections" UUID model); on plain Linux strongSwan
the raw connection name is used.

Install

wget https://github.com/librenms/librenms-agent/raw/master/snmp/strongswan -O /etc/snmp/strongswan
chmod +x /etc/snmp/strongswan
# snmpd.conf:
extend strongswan /etc/snmp/strongswan

Tested on OPNsense 21.1 / 22.7 / 23.7 and Linux strongSwan, polled by LibreNMS 26.5.
swanctl is auto-detected via PATH and the usual locations. Python 3, stdlib only.

Companion agent script for the LibreNMS 'strongswan' application. Emits the JSON
SNMP extend payload (per-connection IPsec state, in/out traffic, child SAs,
re-establishments + global rekey/error counters) by parsing 'swanctl --list-sas'
and 'swanctl --counters'. Per-SA counters reset on rekey, so it keeps a small
state file and emits monotonic cumulative counters for clean DERIVE rates.

Works on OPNsense (legacy con<N> and new UUID 'Connections' model) and plain
Linux strongSwan.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant