Examples
banshee/examples-collection/examples/watches/
custom
Example: the watch custom, its settings, watch.setting and watch.raise; a backup status by SSH.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
// The watch "custom": the collector judges by itself, with settings the administrator changes on the
// probe. watch.setting reads a setting; watch.raise raises the watch, with its own sentence.
// The collector reads the status file a backup tool writes on a Linux, by SSH.
need('protocol:ssh');
output('age', 'number', array('label' => 'Age of the last backup', 'unit' => 'h'));
// A setting has a form: number, duration, names (a list) or text. This one uses three of them.
watch.custom('backup', 'Backup not good', array(
'help' => 'Critical when the last backup is too old or ended with a result not accepted; warning when it is too small.',
'settings' => array(
'max-age' => array('label' => 'Critical when older than', 'form' => 'duration', 'default' => '1 d'),
'accepted' => array('label' => 'Accepted result', 'form' => 'text', 'default' => 'success'),
'min-size' => array('label' => 'Warning under', 'form' => 'number', 'unit' => 'MiB', 'default' => 100),
'owner' => array('label' => 'Who to call', 'form' => 'text'),
),
));
// Three lines, "finished=1761555600" (seconds since 1970), "result=success", "size=2048" (MiB).
$read = ssh.run('cat /var/lib/example-backup/status');
$status = array();
foreach (text.lines($read['output']) as $line) {
$pair = text.split($line, '=');
$status[$pair[0]] = $pair[1];
}
$age = time.now() - $status['finished'];
value('age', number.round($age / 3600, 1));
// Each setting comes back in its form: seconds for a duration, a number, a text; '' when left empty.
$max_age = watch.setting('backup', 'max-age');
$accepted = watch.setting('backup', 'accepted');
$min_size = watch.setting('backup', 'min-size');
$owner = watch.setting('backup', 'owner');
$call = '';
if ($owner != '') {
$call = ', call ' . $owner;
}
if ($max_age != '' && $age > $max_age) {
watch.raise('backup', 'critical', 'last backup ' . number.round($age / 3600) . ' h ago' . $call);
}
if ($accepted != '' && $status['result'] != $accepted) {
watch.raise('backup', 'critical', 'last backup ended ' . $status['result'] . $call);
}
if ($min_size != '' && $status['size'] < $min_size) {
watch.raise('backup', 'warning', 'last backup only ' . $status['size'] . ' MiB' . $call);
}