Examples
banshee/examples-collection/examples/mechanics/
cache
Example: the cache, set, has, get and delete; a restart told by the boot id of the kernel.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
// The cache: a few values the collector keeps from one pass to the next, each for a lifetime. Here, the
// boot id of the kernel, which changes at every start: a different one means the host restarted.
need('protocol:ssh');
output('restarted', 'text', array('label' => 'Restarted since the previous pass'));
watch.state('restart', 'Host restarted', 'restarted', array('warning' => array('yes')));
$read = ssh.run('cat /proc/sys/kernel/random/boot_id');
$boot_id = text.trim($read['output']);
if ($boot_id == '') {
// cache.delete: forget the key; the next pass starts afresh, as a first one.
cache.delete('boot-id');
fail('misconfigured', 'No boot id in /proc/sys/kernel/random/boot_id', $read['errors']);
}
// cache.has before cache.get: get stops the collector on a key missing or expired.
$restarted = 'no';
if (cache.has('boot-id') && cache.get('boot-id') != $boot_id) {
$restarted = 'yes';
}
// cache.set: kept one day (86 400 seconds); a probe stopped longer than that starts afresh.
cache.set('boot-id', $boot_id, 86400);
value('restarted', $restarted);