Examples ​
Basic example, to check google.com returns a 200 status code:
yaml
services:
app:
url: https://google.com
every: 1m
expect:
status: 200status code ​
Check for a 301 status code:
yaml
services:
app:
url: https://httpbin.org/status/301
every: 1m
expect:
status: 301max_bytes & regex ​
Check if the content of the response contains the word epazote in the first 1000 bytes:
yaml
services:
app:
url: https://httpbin.org/headers
every: 1m
max_bytes: 1000
expect:
status: 200
body: epazoteJSON response matching ​
Check that a JSON API returns a successful status field:
yaml
services:
vmagent_targets:
url: http://127.0.0.1:8429/api/v1/targets
every: 30s
expect:
status: 200
json:
status: successMatch nested JSON objects and array items:
yaml
services:
vmagent_targets:
url: http://127.0.0.1:8429/api/v1/targets
every: 30s
expect:
status: 200
json:
status: success
data:
activeTargets:
- labels:
job: DBMI-lab-nico
health: upJSON response matching with fallback actions ​
If the JSON expectation fails, if_not can trigger a command or HTTP callback:
yaml
services:
vmagent_targets:
url: http://127.0.0.1:8429/api/v1/targets
every: 30s
expect:
status: 200
json:
status: success
data:
activeTargets:
- labels:
job: DBMI-lab-nico
health: up
if_not:
threshold: 3
stop: 3
cmd: systemctl restart vmagentthreshold waits for consecutive failures before executing the fallback action. stop limits how many times that fallback action is executed afterward.
Alert script with EPAZOTE_* context ​
If you want to send a mail, webhook, or chat notification, use if_not.cmd with a script and read the environment variables that Epazote provides:
yaml
services:
vmagent_targets:
url: http://127.0.0.1:8429/api/v1/targets
every: 30s
expect:
status: 200
json:
status: success
if_not:
threshold: 3
stop: 1
cmd: /usr/local/bin/send-alert.shbash
#!/usr/bin/env bash
set -euo pipefail
mail -s "Epazote alert: ${EPAZOTE_SERVICE_NAME}" [email protected] <<EOF
Service: ${EPAZOTE_SERVICE_NAME}
Type: ${EPAZOTE_SERVICE_TYPE}
Error: ${EPAZOTE_ERROR}
Expected: ${EPAZOTE_EXPECTED_STATUS}
Actual: ${EPAZOTE_ACTUAL_STATUS:-n/a}
Failures: ${EPAZOTE_FAILURE_COUNT}/${EPAZOTE_THRESHOLD}
URL: ${EPAZOTE_URL:-n/a}
Test: ${EPAZOTE_TEST:-n/a}
EOFThis is usually easier than embedding all the alerting logic directly in the Epazote config.
Post JSON ​
yaml
---
services:
test:
url: https://httpbin.org/response-headers
method: POST
every: 1m
body:
json:
message: Hello, World!
expect:
status: 200