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/

backup-jobs

Example: a REST API end to end, login, token in the cache, one state per backup job.

  • example
  • api
  • rest
  • http
  • token
  • cache
  • backup

par banshee1 installation1 version

v1Dernière

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

A REST API from end to end

A backup server read by its API: log in for a token, keep the token in the cache, read the list of the jobs, return one result and one duration per job.

How to read it

  • The account is banshee's, need('protocol:http:user') and need('protocol:http:password'), set in the tree; the address is a variable of the collector.
  • The login is a function, called at the first pass and when the token is refused. The account goes in Basic, user= and password=: the answer is then not a secret, but the token is, so secret.mark marks it. A secret never goes into a value or a message; in the cache it is kept encrypted.
  • The cache keeps the token 50 minutes, under the hour it lives: the following passes do not log in again.
  • A 401 means the token was refused before its time, the server having restarted: one new login, then the request again.
  • One state per job: per('job', 'Jobs'), and value('result', …, $job['name']) for each job of the list.

To adapt it

  • An API that wants the account in a JSON body: http.post($url, json.write(array('username' => $user, 'password' => $password)), headers=array('Content-Type' => 'application/json')). The body then carries a secret, and the whole answer is a secret by itself: secret.mark is no longer needed.
  • Change the paths (/api/v1/login, /api/v1/jobs) and the keys (token, jobs, last_result, last_duration) for those of your server.