Examples
banshee/examples-collection/examples/mechanics/
fail
Example: fail and its three states, critical, misconfigured, unreachable; software RAID by SSH.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
// fail: stop the collector on a state it alone knows, with a summary and a detail. Three states:
// critical, the target is in trouble; misconfigured, the probe is set wrong; unreachable, the target
// cannot be read. A stopped collector returns no value, and no watch is judged.
// The collector reads the software RAID arrays of a Linux, by SSH.
need('protocol:ssh');
output('raid', 'text', array('label' => 'State of the RAID arrays'));
watch.state('rebuilding', 'Array rebuilding', 'raid', array('warning' => array('recovering')));
$mdstat = ssh.run('cat /proc/mdstat');
if ($mdstat['exit'] != 0) {
fail('misconfigured', 'No software RAID on this host', $mdstat['errors']);
}
if (text.trim($mdstat['output']) == '') {
fail('unreachable', 'Empty answer from /proc/mdstat');
}
// "[UU]" when every disk of an array is up, "[U_]" when one is missing.
if (list.count(text.match($mdstat['output'], '\[U*_[U_]*\]')) > 0) {
fail('critical', 'A RAID array lost a disk', $mdstat['output']);
}
$raid = 'clean';
if (text.contains($mdstat['output'], 'recovery') || text.contains($mdstat['output'], 'resync')) {
$raid = 'recovering';
}
value('raid', $raid);