The plugins' self-check
A plugin relies on OPNsense: its files, its classes and their methods, its configd actions, how its firewall classes write a rule. An update of OPNsense can change any of them, and a plugin built on the old one then does something wrong without an error anywhere: a block rule whose table was dropped blocks everything, a pass rule whose interface was dropped passes on every interface. The self-check looks at what the plugin relies on as it is on the firewall now - at boot, after every update of OPNsense and after every install or update of the plugin - and where something no longer holds, it switches off the risky part that relies on it, and only that part. The rest of the plugin and the traffic go on, OPNsense's status (the bell in its header) names the part, and a later check that passes switches it back on.
It catches what can be read on the firewall. What only traffic shows - which end of a connection a pf state counts first, what a pf table holds after a reload - is for the behaviour tests, run on a lab appliance.
os-blocklists had it first (2026-12-01). Every plugin carries its own: pkg lets no two packages own one file, and a plugin runs without os-xgs-npu. What all of them share is written into each from tools/selfcheck, and a plugin's checks.yml holds it there.
What a plugin has
Written by hand, in the plugin:
| file | says |
|---|---|
selfcheck.json |
the plugin's name, its program in the system log, its parts and what of OPNsense each relies on |
src/opnsense/scripts/<scripts>/selfcheck.py |
its own checks, and what switches a part off or on now |
| what reads the safe mode | the code of each part, leaving the part out while the record says it is off |
its test-selfcheck.py, in its tools folder |
its checks and its safe mode, with stand-ins |
Written by tools/selfcheck/generate.py from selfcheck.json and
contract.json:
| file | is |
|---|---|
scripts/<scripts>/selfcheck_core.py |
the common part: the checks of the contract, the dry run's judgement, the safe mode, the waits and the locks |
scripts/<scripts>/selfcheck_probe.php |
the look at OPNsense's PHP: the classes, the firewall hook's dry run, the models |
scripts/<scripts>/selfcheck_data.json |
the plugin's settings and its contract's entries, each with its part |
scripts/<scripts>/safemode.py |
the record's reader, for the plugin's Python |
rc.syshook.d/start/<NN>-<scripts>-selfcheck, rc.syshook.d/update/... |
the runs at boot and after an update of OPNsense |
cron.d/<scripts>-selfcheck |
the hourly look while a part is off |
System/Status/<Status>Status.php |
the warning in OPNsense's status |
its test-selfcheck-core.py, in its tools folder |
the common part held to the plugin |
and a block, between selfcheck: begin and selfcheck: end, in the plugin's own actions_<scripts>.conf
(configctl <scripts> selfcheck), its firewall hook (<prefix>_selfcheck_off()), install/install.sh,
install/uninstall.sh, pkg/post-install.sh, README.md, .github/workflows/checks.yml and
.gitattributes, which leaves the settings and the tests out of the archive a release is made from.
python3 tools/selfcheck/generate.py <plugin checkout> write them
python3 tools/selfcheck/generate.py --check <plugin checkout>... what the plugins' checks run
A change to the kit here is followed by the generator run over every plugin, in one pull request each.
Until then a plugin holds to the kit it was written from: its checks
(plugin-selfcheck.yml) try main's generator first, then each
earlier kit of main's history, newest first, and pass on the first that writes the plugin's files as they
are, with a warning that main's is newer. A file changed by hand, or a selfcheck.json changed without
the generator run, is no kit's, and fails.
selfcheck.json
| key | |
|---|---|
selfcheck |
1 |
plugin, scripts, tag |
os-quota; its folder under scripts/; the program its lines are logged under, which os-xgs-npu's problem reporter takes for it |
title, location, status |
its name in the menu, its page, the class name of its line in OPNsense's status |
parts |
{part: {name, label, off, looks}}: what is switched off, as the log, the status and the README say it |
contract |
{"<section>:<entry>": part}: the part an entry of contract.json is of; "classes:<class>" covers its methods, "<section>:*" a section; an entry not named is of no part, a warning |
skip |
["<section>:<entry>"]: entries not read on the firewall - another plugin's file, a page's partial |
firewall |
{part, marker, function, samples, nat}: the firewall hook, the start of its rules' descriptions, and rules of its kinds registered beside the owner's in the dry run |
models |
the plugin's model classes, constructed by the probe |
priority, minute, prefix, hook, anchors, own, services, includes |
rarely needed: the hooks' number, cron's minute, the PHP prefix, the hook's file, where blocks go, more files of its own, the services check, what the probe includes |
contract.json's sections read on the firewall are its files, classes and methods, PHP functions,
configd actions, templates, texts and the captive portal's columns; runtime paths only where mapped. The
GUI's - JavaScript, the API, config.xml's paths - and the hooks and events are for the contract check
against OPNsense's trees (plugin-contract.yml).
A plugin's checks
import selfcheck_core as core
@core.check('enforce-states', 'block')
def enforce_states():
"""'' where all is well, else the reason"""
def switch(part, now_off): what makes the change take effect now: a filter reload, a service stop
def residue(part): whether a part that is off still acts, so it is switched off again
def in_use(): {part: whether its feature is turned on}
def judge_rules(rules, dry): more reasons about the dry run's rules ({conf, text} as OPNsense wrote them)
if __name__ == '__main__':
sys.exit(core.main(sys.argv[1:], sys.modules[__name__]))
A check of no part (None) is a warning; error=True makes it an error line that switches nothing off,
for a plugin whose part would do more harm off than on. A check reads, never changes. What it looks at is
what the part's code reads - the same function where it can be called - so a pass means the code reads it.
The safe mode in the code
A part's code reads the record and leaves the part out while it is off: in Python
safemode.off('<part>'), in the firewall hook <prefix>_selfcheck_off('<part>'), which reads
nothing where the dry run defines <PREFIX>_SELFCHECK_RECORD as ''. The hook keeps what it catches in
$GLOBALS['<prefix>_selfcheck_error'], for the dry run to fail on. The record is
/var/db/<plugin>/selfcheck.json: the last run, and under off each part with since when, by which checks,
on which OPNsense, and whether it was in use.
What it does not
It does not repair: what breaks a check is OPNsense or the plugin changing, and what mends it is the next update of one of them, which runs it again. There is no button to switch a part on while a check of its own fails. It does not see behaviour: that is for the behaviour tests and the canary.
The discussion of this page is held in the project's GitHub Discussions. Showing it here loads giscus from giscus.app and GitHub, and writing in it needs a GitHub account - what that means.