banshee est en développement actif : les collecteurs vont encore changer, et une version que vous publiez demandera sans doute des ajustements. Pour un usage stable, attendez la version 1.0.0.

Examples

banshee/examples-collection/examples/protocols/

http-get-json

Example: http.get and json.read; the state a health page declares.

  • example
  • protocol
  • http
  • json
  • health

par banshee1 installation1 version

v1Dernière

Publiée le 27 octobre 2026. First version in this collection.

Keen 1.0.0 · 22 lignes
// http.get and JSON: read a health page that answers {"status": "ok", ...}.
// http.get returns array('status' => code, 'headers' => ..., 'body' => text, 'time' => milliseconds).
need('protocol:http');

$url = variable('example:health:url', 'text', array(
    'label' => 'Address of the health page',
    'help'  => 'For example https://api.example/health.',
));

output('health', 'text', array('label' => 'State declared'));

watch.expect('unhealthy', 'Service unhealthy', 'health', array('critical' => array('ok')));

// A code 500 is an answer, not a failure: the collector reads it and decides.
$answer = http.get($url);
if ($answer['status'] != 200) {
    fail('critical', 'The health page answers ' . $answer['status']);
}

// json.read turns the text into arrays; list.get reads a key that may be missing.
$health = json.read($answer['body']);
value('health', list.get($health, 'status', 'missing'));