Skip to content

Commit 9fc0e78

Browse files
committed
feat(strongswan-connections): add --match and --ignore filter parameters
Adds --match (include filter) and --ignore (exclude filter), both Python regex, case-sensitive by default (use (?i) for case-insensitive matching), both repeatable. Include-first, exclude-second semantics match the disk-usage plugin and the lib.args canonical --match / --ignore convention. Typical use cases on a strongSwan VPN gateway: - --ignore='^RA_' to hide transient remote-access clients and keep a single Icinga service for all permanent site-to-site peers - --match='^S2S_SITE-XY$' to pin a dedicated Icinga service to one specific site-to-site peer (per-site granularity, named alerts) The filter applies to both the "configured" and the "active" connection lists before the "configured but not active" comparison, so an ignored connection that happens to be down does not trigger the warning. Along the way the test mode was fixed: format_sas_data() and format_child_data() now accept both VICI bytes and JSON strings, which uncovered that the existing unit tests were passing only because the pre-existing fixture-load path triggered a swallowed exception and left state at STATE_OK, asserting only the trivial "Everything is ok." fallback. With the fix, fixtures actually drive the plugin through format_sas_data / format_child_data and the assertions can check real rendered output. Other polish in the same commit: dedupe get_possible_connection_keys / get_active_connection_keys via a _collect_keys helper, fix a socket leak (try/finally + close), narrow a bare except Exception on socket.connect to OSError with a descriptive error message, replace an O(n*m) sas[key] probe loop with items() + set lookup, move import json to module scope, drop an unused import lib.shell, delete a vestigial 1173-char OrderedDict-repr comment, delete the vestigial "do not call the command" comment on the --test else branch. Closes #738
1 parent 12d0e16 commit 9fc0e78

File tree

8 files changed

+464
-47
lines changed

8 files changed

+464
-47
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Monitoring Plugins:
5555
* scanrootkit: add 41 signatures for modern Linux rootkits, backdoors and implants, including BPFDoor, Drovorub, Ebury 1.7/1.8, FontOnLake, HiddenWasp, Kaiji, Kobalos, Lightning Framework, Medusa, Nuk3Gh0st, OrBit, perfctl, PUMAKIT, Pygmy Goat, Reptile, RotaJakiro, sedexp, Skidmap, SSHdoor, Symbiote, Syslogk, TripleCross, UNC3886, Winnti for Linux, Adore-NG, Azazel, BEURK, Father, Honey Pot Bears and Umbra. Sourced from public vendor and threat-research IoC reports (ESET, Sandfly, Intezer, Elastic, Mandiant, Sophos, NCSC UK, fkie-cad/linux-rootkit-iocs, etc.)
5656
* scanrootkit: each finding now shows the year the rootkit was first publicly disclosed when known, e.g. `* CiNIK Worm (2002): /tmp/.cinik (File)`. Old rkhunter-era signatures and the new 2019+ signatures have all been dated where a reliable public source exists; signatures without a confirmed year are shown without the suffix as before
5757
* sensors-temperatures: add `--ignore` parameter to filter out sensors by regex ([#965](https://github.com/Linuxfabrik/monitoring-plugins/issues/965))
58+
* strongswan-connections: add `--match` and `--ignore` parameters to filter configured and active VICI connections by regex. Useful for gateways that mix permanent site-to-site peers with transient remote-access clients: admins can either hide the RA clients via `--ignore='^RA_'` (and keep a single Icinga service for all S2S peers) or pin a dedicated Icinga service to a single site via `--match='^S2S_SITE-XY$'`. Include-first, exclude-second semantics, same as the `disk-usage` plugin; both parameters follow the `lib.args` canonical convention (case-sensitive by default, `(?i)` opt-in, appending). As part of this work the test-mode code path was fixed so fixtures stop silently matching the trivial "Everything is ok." fallback via a swallowed exception ([#738](https://github.com/Linuxfabrik/monitoring-plugins/issues/738))
5859
* statuspal: also detect 'emergency-maintenance' state
5960
* valkey-status: support user and password credentials [PR #954](https://github.com/Linuxfabrik/monitoring-plugins/pull/954), thanks to [Claudio Kuenzler](https://github.com/Napsty)
6061

check-plugins/strongswan-connections/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,41 @@ Checks IPSec connection states on a strongSwan VPN gateway by connecting to the
3434
## Help
3535

3636
```text
37-
usage: strongswan-connections [-h] [-V] [--always-ok] [--lengthy]
38-
[--socket SOCKET] [--test TEST]
37+
usage: strongswan-connections [-h] [-V] [--always-ok] [--ignore IGNORE]
38+
[--lengthy] [--match MATCH] [--socket SOCKET]
39+
[--test TEST]
3940
4041
Checks IPSec connection states on a strongSwan VPN gateway. Connects to the
4142
charon daemon via the VICI interface to retrieve IKE SA and CHILD SA states.
42-
Alerts on connections that are not in the expected established state. Requires
43+
Alerts on connections that are not in the expected established state.
44+
Connection names can be filtered out with --ignore, which is useful for
45+
gateways that mix permanent site-to-site peers with transient remote-access
46+
clients where only the site-to-site peers should drive the alert. Requires
4347
root or sudo.
4448
4549
options:
4650
-h, --help show this help message and exit
4751
-V, --version show program's version number and exit
4852
--always-ok Always returns OK.
53+
--ignore IGNORE Ignore connections whose VICI key matches this Python
54+
regular expression. Case-sensitive by default; use `(?i)`
55+
for case-insensitive matching. Can be specified multiple
56+
times. Example: `--ignore="^RA_"` to skip transient remote-
57+
access clients on a VPN gateway that also carries permanent
58+
site-to-site peers. Example: `--ignore="(?i)test"` (case-
59+
insensitive) to skip any connection with "test" in its
60+
name. Default: None
4961
--lengthy Extended reporting.
62+
--match MATCH Only check connections whose VICI key matches this Python
63+
regular expression. Case-sensitive by default; use `(?i)`
64+
for case-insensitive matching. Can be specified multiple
65+
times. If both `--match` and `--ignore` are given, a
66+
connection must match `--match` AND not match `--ignore` to
67+
be checked (include first, exclude second). Example:
68+
`--match="^S2S_SITE-XY$"` to pin an Icinga service to one
69+
specific site-to-site peer. Example: `--match="(?i)^s2s_"`
70+
(case-insensitive) to check every site-to-site peer on a
71+
gateway. Default: None
5072
--socket SOCKET Path to the Versatile IKE Control Interface (VICI) socket.
5173
Default: /run/strongswan/charon.vici
5274
--test TEST For unit tests. Needs "path-to-stdout-file,path-to-stderr-

check-plugins/strongswan-connections/icingaweb2-module-director/strongswan-connections.json

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
"--always-ok": {
66
"set_if": "$strongswan_connections_always_ok$"
77
},
8+
"--ignore": {
9+
"value": "$strongswan_connections_ignore$",
10+
"repeat_key": true
11+
},
812
"--lengthy": {
913
"set_if": "$strongswan_connections_lengthy$"
1014
},
15+
"--match": {
16+
"value": "$strongswan_connections_match$",
17+
"repeat_key": true
18+
},
1119
"--socket": {
1220
"value": "$strongswan_connections_socket$"
1321
}
@@ -29,6 +37,16 @@
2937
"datafield_id": 3,
3038
"is_required": "n",
3139
"var_filter": null
40+
},
41+
{
42+
"datafield_id": 4,
43+
"is_required": "n",
44+
"var_filter": null
45+
},
46+
{
47+
"datafield_id": 5,
48+
"is_required": "n",
49+
"var_filter": null
3250
}
3351
],
3452
"imports": [],
@@ -72,7 +90,7 @@
7290
"tpl-service-generic"
7391
],
7492
"max_check_attempts": 5,
75-
"notes": "Checks IPSec connection states on a strongSwan VPN gateway. Connects to the charon daemon via the VICI interface to retrieve IKE SA and CHILD SA states. Alerts on connections that are not in the expected established state. Requires root or sudo.",
93+
"notes": "Checks IPSec connection states on a strongSwan VPN gateway. Connects to the charon daemon via the VICI interface to retrieve IKE SA and CHILD SA states. Alerts on connections that are not in the expected established state. Connection names can be filtered out with --ignore, which is useful for gateways that mix permanent site-to-site peers with transient remote-access clients where only the site-to-site peers should drive the alert. Requires root or sudo.",
7694
"notes_url": "https://linuxfabrik.github.io/monitoring-plugins/check-plugins/strongswan-connections/",
7795
"object_name": "tpl-service-strongswan-connections",
7896
"object_type": "template",
@@ -84,7 +102,9 @@
84102
"vars": {
85103
"criticality": "C",
86104
"strongswan_connections_always_ok": false,
105+
"strongswan_connections_ignore": [],
87106
"strongswan_connections_lengthy": false,
107+
"strongswan_connections_match": [],
88108
"strongswan_connections_socket": "/run/strongswan/charon.vici"
89109
},
90110
"volatile": null,
@@ -103,6 +123,17 @@
103123
"uuid": "584d20e3-6a37-49bd-8775-e659107932ea"
104124
},
105125
"2": {
126+
"varname": "strongswan_connections_ignore",
127+
"caption": "Strongswan Connections: Ignore",
128+
"description": "Ignore connections whose VICI key matches this Python regular expression. Case-sensitive by default; use `(?i)` for case-insensitive matching. Can be specified multiple times. Example: `--ignore=\"^RA_\"` to skip transient remote-access clients on a VPN gateway that also carries permanent site-to-site peers. Example: `--ignore=\"(?i)test\"` (case-insensitive) to skip any connection with \"test\" in its name.",
129+
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
130+
"format": null,
131+
"settings": {
132+
"visibility": "visible"
133+
},
134+
"uuid": "aa407e77-234d-4bd0-ace0-81c21fe71a9d"
135+
},
136+
"3": {
106137
"varname": "strongswan_connections_lengthy",
107138
"caption": "Strongswan Connections: Lengthy?",
108139
"description": "Extended reporting.",
@@ -111,7 +142,18 @@
111142
"settings": {},
112143
"uuid": "a59704e1-8a80-4f5a-a8f5-e7ed09ef73ab"
113144
},
114-
"3": {
145+
"4": {
146+
"varname": "strongswan_connections_match",
147+
"caption": "Strongswan Connections: Match",
148+
"description": "Only check connections whose VICI key matches this Python regular expression. Case-sensitive by default; use `(?i)` for case-insensitive matching. Can be specified multiple times. If both `--match` and `--ignore` are given, a connection must match `--match` AND not match `--ignore` to be checked (include first, exclude second). Example: `--match=\"^S2S_SITE-XY$\"` to pin an Icinga service to one specific site-to-site peer. Example: `--match=\"(?i)^s2s_\"` (case-insensitive) to check every site-to-site peer on a gateway.",
149+
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
150+
"format": null,
151+
"settings": {
152+
"visibility": "visible"
153+
},
154+
"uuid": "003dbb6e-6dd0-40f7-892c-e61871dd5e7c"
155+
},
156+
"5": {
115157
"varname": "strongswan_connections_socket",
116158
"caption": "Strongswan Connections: Socket",
117159
"description": "Path to the Versatile IKE Control Interface (VICI) socket.",

0 commit comments

Comments
 (0)