Skip to content

Examples ​

Basic example, to check google.com returns a 200 status code:

yaml
services:
  app:
    url: https://google.com
    every: 1m
    expect:
      status: 200

status code ​

Check for a 301 status code:

yaml
services:
  app:
    url: https://httpbin.org/status/301
    every: 1m
    expect:
      status: 301

max_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: epazote

JSON 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: success

Match 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: up

JSON 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 vmagent

threshold 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.sh
bash
#!/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}
EOF

This 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

Released under the BSD-3-Clause License