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/api/

elasticsearch-key

Example: base64.encode for an API key header; the health of an Elasticsearch cluster.

  • example
  • api
  • elasticsearch
  • base64
  • secret
  • http

par banshee1 installation1 version

v1Dernière

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

Keen 1.0.0 · 32 lignes
// An API key of Elasticsearch: the header is "ApiKey " followed by the id and the key joined by a colon,
// written in base64 by base64.encode. The collector reads the health of the cluster.
need('protocol:http');

$base = variable('example:elastic:url', 'text', array(
    'label' => 'Address of the cluster',
    'help'  => 'For example https://search.example:9200.',
));
$id = variable('example:elastic:key-id', 'text', array(
    'label' => 'Id of the API key',
    'help'  => 'The id Elasticsearch gave with the key.',
));
$key = variable('example:elastic:key', 'text', array(
    'label'  => 'API key',
    'help'   => 'The key itself, of a role that can read the health of the cluster.',
    'secret' => true,
));

output('health', 'text', array('label' => 'Health of the cluster'));

watch.state('unhealthy', 'Cluster unhealthy', 'health', array('warning' => array('yellow'), 'critical' => array('red')));

// Made from the secret key, the encoded text is a secret too: it only goes into the request.
$authorization = 'ApiKey ' . base64.encode($id . ':' . $key);
$answer = http.get($base . '/_cluster/health', headers=array('Authorization' => $authorization));
if ($answer['status'] != 200) {
    fail('misconfigured', 'The cluster answers ' . $answer['status']);
}

// {"cluster_name": "logs", "status": "green", ...}
$cluster = json.read($answer['body']);
value('health', $cluster['status']);