Examples
banshee/examples-collection/examples/mechanics/
selection-only
Example: per with only, a default selection of named elements; systemd services by SSH.
by banshee1 installation2 versions
v2Latest
Published on October 28, 2026. One naming convention across collections; documentation completed.
// per with only: the default selection is "only these elements". Of all the systemd services of a Linux,
// the SSH server and cron are watched by default, under their names on Debian (ssh, cron) and on Fedora
// (sshd, crond); the administrator adds others on the probe, by name or by pattern.
need('protocol:ssh');
per('service', 'Services', array('only' => array('ssh', 'sshd', 'cron', 'crond')));
output('state', 'text', array('label' => 'State', 'per' => 'service'));
watch.expect('stopped', 'Service not running', 'state', array('critical' => array('active')));
// One line per service, "cron.service loaded active running Regular background program processing daemon".
// A machine without systemd (Alpine) refuses the command: the collector says so rather than return nothing,
// which no watch would judge.
$units = ssh.run('systemctl list-units --type=service --all --plain --no-legend');
if ($units['exit'] != 0) {
fail('misconfigured', 'systemctl did not answer: is this machine run by systemd?', $units['errors']);
}
$found = 0;
foreach (text.lines($units['output']) as $line) {
$m = text.match($line, '([^ ]+)\.service +[^ ]+ +([^ ]+)');
if (list.count($m) > 0) {
value('state', $m[2], $m[1]);
$found = $found + 1;
}
}
if ($found == 0) {
fail('misconfigured', 'No service found in the answer of systemctl', $units['output']);
}