Examples
banshee/examples-collection/examples/protocols/
http-get-json
Example: http.get and json.read; the state a health page declares.
par banshee1 installation1 version
Publiée le 27 octobre 2026. First version in this collection.
// 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'));