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/

variables

Example: variable() in its five forms, required, optional and with a default; words in a web page.

  • example
  • variable
  • settings
  • http
  • page

by banshee1 installation1 version

v1Latest

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

Keen 1.0.0 · 62 lines
// variable(): a setting of the collector, given on the probe. Five forms: text, multiline, integer,
// boolean and choice. Each one is required unless 'required' => false, and may have a default.
// The collector checks that a web page answers and holds the words expected.
need('protocol:http');

// Required, the rule when nothing is said: the probe does not run without it.
$url = variable('example:page:url', 'text', array(
    'label' => 'Address of the page',
    'help'  => 'For example https://www.example/.',
));
// Optional: left empty, it reads ''.
$words = variable('example:page:words', 'multiline', array(
    'label'    => 'Words expected',
    'help'     => 'One word or phrase per line, each expected in the page.',
    'required' => false,
));
// A default: the value the probe has until the administrator changes it.
$expected_status = variable('example:page:status', 'integer', array(
    'label'   => 'Expected code',
    'help'    => 'The code the page must answer with, 200 for most pages.',
    'default' => 200,
));
$ignore_case = variable('example:page:ignore-case', 'boolean', array(
    'label'   => 'Ignore case',
    'help'    => 'Checked, "Welcome" is found in a page that says "WELCOME".',
    'default' => true,
));
$mode = variable('example:page:mode', 'choice', array(
    'label'   => 'Words to find',
    'help'    => 'All the words, or any one of them.',
    'choices' => array('all', 'any'),
    'default' => 'all',
));

output('missing', 'number', array('label' => 'Expected words missing'));

watch.above('words-missing', 'Expected words missing', 'missing', array('critical' => 0));

$answer = http.get($url);
if ($answer['status'] != $expected_status) {
    fail('critical', 'The page answers ' . $answer['status'] . ', not ' . $expected_status);
}

$page = $answer['body'];
if ($ignore_case) {
    $page = text.lower($page);
}
$wanted = text.lines($words);
$missing = 0;
foreach ($wanted as $word) {
    if ($ignore_case) {
        $word = text.lower($word);
    }
    if (!text.contains($page, $word)) {
        $missing = $missing + 1;
    }
}
// any: one word found is enough.
if ($mode == 'any' && $missing < list.count($wanted)) {
    $missing = 0;
}
value('missing', $missing);