diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ac1eb2f02bc48fcd854f4c769a9023b3637902ef..e144c90bb4734ec98c6e0b6571b2139fe7722416 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,13 @@ include: - "https://git.autistici.org/pipelines/containers/raw/master/common.yml" - "https://git.autistici.org/ai3/docker/test/golang/raw/master/ci.yml" + +ctest-http: + image: registry.git.autistici.org/ai3/docker/test/float-like-podman:master + stage: container-test + tags: [podman] + variables: + URL: https://www.incal.net/ + script: + - sed -e "s,@URL@,$URL,g" < test/http/config.json > config.json + - with-container --mount=type=bind,source=$PWD/config.json,destination=/etc/service-prober.json --env=SERVICE_PROBER_CONFIG=/etc/service-prober.json --env=SERVICE_PROBER_HTTP_ADDR=:5521 --expose=5521 $IMAGE_TAG ./test/test.sh diff --git a/cmd/service-prober/main.go b/cmd/service-prober/main.go index c8243a8239f2f0c319f7a07c42158307133bbf4e..86eda1c544de7fb803fc4dd1a1c211140a624ca9 100644 --- a/cmd/service-prober/main.go +++ b/cmd/service-prober/main.go @@ -21,12 +21,19 @@ import ( _ "git.autistici.org/ai3/tools/service-prober/probes/openvpn" ) +func getenvDef(key, def string) string { + if s := os.Getenv(key); s != "" { + return s + } + return def +} + var ( - config = flag.String("config", "", "configuration file `path`") + config = flag.String("config", os.Getenv("SERVICE_PROBER_CONFIG"), "configuration file `path`") oneshot = flag.Bool("oneshot", false, "run just one shot and exit") validate = flag.Bool("validate", false, "just validate the configuration syntax") - only = flag.String("only", "", "only run probes with names matching this `regex`") - httpAddr = flag.String("http-addr", ":5522", "`address` for the HTTP server") + only = flag.String("only", os.Getenv("SERVICE_PROBER_ONLY"), "only run probes with names matching this `regex`") + httpAddr = flag.String("http-addr", getenvDef("SERVICE_PROBER_HTTP_ADDR", ":5522"), "`address` for the HTTP server") keepResults = flag.Int("keep-results", 100, "keep `N` results of past probes in memory") ) diff --git a/test/http/config.json b/test/http/config.json new file mode 100644 index 0000000000000000000000000000000000000000..4a13b717e42f2d77ba9e90ecc861d60d4d382cb6 --- /dev/null +++ b/test/http/config.json @@ -0,0 +1,20 @@ +{ + "vars": {}, + "probes": [ + { + "type": "http", + "name": "test", + "interval": "1m", + "timeout": "1m", + "params": { + "script": [ + { + "type": "open", + "url": "@URL@", + "expected_url": "@URL@" + } + ] + } + } + ] +} diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000000000000000000000000000000000000..8dbf92f5ba28eaab1f7a3619e51b7b602db0b590 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +value=$(curl -sf http://localhost:5521/metrics | awk '/^probe_success/ {print $2}') +case "$value" in + 1) + echo "success!" >&2 + exit 0 + ;; + + 0) + echo "probe has failed" >&2 + exit 2 + ;; +esac + +# No probe_success value, or connection error. Retry. +exit 1