banshee is under active development: collectors will keep changing, and a version you publish will likely need adjustments. For stable use, wait for version 1.0.0.

Examples

banshee/examples-collection/examples/mechanics/

text

Example: the text tools, lines, match, lower, words, join, length, split, is_number; /etc/os-release.

  • example
  • text
  • tools
  • os-release
  • ssh

by banshee1 installation1 version

v1Latest

Published on October 27, 2026. First version in this collection.

Keen 1.0.0 · 43 lines
// The text tools, on the file /etc/os-release of a Linux: lines NAME=value, some values between double
// quotes. The collector returns the distribution, its family and its major version.
need('protocol:ssh');

output('distribution', 'text', array('label' => 'Distribution'));
output('family', 'text', array('label' => 'Family'));
output('version', 'number', array('label' => 'Major version'));

watch.below('old', 'Old release', 'version', array('warning' => 12, 'enabled' => false));

$read = ssh.run('cat /etc/os-release');
$release = array();
// text.lines: the lines that are not empty, without the blanks at their ends.
foreach (text.lines($read['output']) as $line) {
    // text.match: the groups of the first match, 0 for the whole, 1, 2... for each group; array() when
    // nothing matches.
    $m = text.match($line, '^([A-Z_]+)="?([^"]*)"?$');
    if (list.count($m) > 0) {
        $release[$m[1]] = $m[2];
    }
}

// text.lower: "Debian" and "debian" become the same text.
$id = text.lower(list.get($release, 'ID', 'unknown'));
value('distribution', $id);

// text.words: the words, cut at the blanks; ID_LIKE names the distributions this one follows.
// text.join: a list back into one text.
$family = text.words(list.get($release, 'ID_LIKE', $id));
value('family', text.join($family, ', '));

// text.length: the number of characters; a rolling distribution has no version at all.
$version_id = list.get($release, 'VERSION_ID', '');
if (text.length($version_id) == 0) {
    skip('No VERSION_ID: a rolling distribution has no version');
}
// text.split: "12.4" cut at each point; the first piece is the major version.
$pieces = text.split($version_id, '.');
// text.is_number: is the text the writing of a number?
if (!text.is_number($pieces[0])) {
    fail('misconfigured', 'VERSION_ID is not a version', $version_id);
}
value('version', $pieces[0]);