This is a slightly more advanced usage of Chaperone, but is very common and useful for collections of similar checks. If you're just starting out, make sure you understand the basic usage scenarios first.
Let's say we have a bunch of apps running on our servers, and we want to periodically check that they're all up.
The apps that are running isn't a constant; it grows and shrinks as teams bring new apps up and retire old apps.
We have a script named list-apps.sh
that when called, returns a list of the currently deployed app names like this:
arbalest
thorn
messenger
We also have a script we can call to get the current health of an app, named get-app-health.sh
that takes a single argument $appName
.
We want to write the health status of each app as a separate health check every 5 minutes.
Let's create app-health.toml
to do this...
description = "team X's application health check status"
template = "list-apps.sh"
name = "app - $1"
command = "get-app-health.sh"
interval = "5m"
timeout = "10s"
tags = {category="appcheck", env="prod", app="$1"}
Now every five minutes, chaperone will call list-apps.sh
, and for each app returned, will execute get-app-health.sh
for that app.
stdout might look like this:
2020-02-21T01:20:02.531372Z app - arbalest OK {category=appcheck,env=prod,app=arbalest} app is healthy
2020-02-21T01:20:02.532529Z app - thorn OK {category=appcheck,env=prod,app=thorn} app is healthy
2020-02-21T01:20:02.532529Z app - messenger FAIL {category=appcheck,env=prod,app=messenger} app failed health check
The template
value is what creates the dynamic list of checks.
Its output is used to generate the arguments that will be passed into the command
, name
, and tags
properties.
The command
property will be sent each line returned by the template command.
The name
and tags
properties can use bash positional argument syntax to filter what is used from the template
output. e.g. $1
, $2
, $@
should all work when specifying the name
and tag
.
There's a couple tests for templates in CheckTest.kt for reference.
There's also an annotated example to start from.