From 1475ae32b95d7629a04f62f63e9e2e6e5612c9f1 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 3 Aug 2022 21:07:33 +0200 Subject: actually run --- colocation-client.in | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/colocation-client.in b/colocation-client.in index dfb1662..0226682 100644 --- a/colocation-client.in +++ b/colocation-client.in @@ -2,7 +2,7 @@ configuration_file="${1:-#ETC#/colocation-client.conf}" -jq '{ +jq -c '{ colocation_server, machine: .machines[] } | { @@ -16,6 +16,47 @@ jq '{ .machine.key ) ), - values: .machine.values, + test: ( + .machine.values | + to_entries | + .[] | + { + state: .key, + command: (.value.command // "true"), + result: (.value.result // "exitcode") + } + ) +} | { + url: ( .url + "&" + .test.state + "=" ), + command: .test.command, + result: .test.result }' \ -<"${configuration_file}" +<"${configuration_file}" \ +| sed ' + s@^{"url":"\([^"]\+\)","command":"\([^"]\+\)","result":"\([^"]\+\)"}$@\1\n\2\n\3@ + t + d +' \ +| while read -r url && read -r command && read -r result_strategy; do + case "${result_strategy}" in + 'exitcode') + ${command} 2>/dev/null >/dev/null + result=$? + ;; + 'stderr') + result=$(${command} >/dev/null 2>&1) + ;; + 'stdout') + result=$(${command} 2>/dev/null) + ;; + *) + >&2 printf 'unknown result strategy "%s"\n' "${result_strategy}" + exit 1 + ;; + esac + if printf '%s\n' "${result}" | grep -vxF '0' | grep -qvxF '1'; then + >&2 printf 'result must be 0 or 1, but is "%s" for command "%s" with result strategy "%s"\n' "${result}" "${command}" "${result_strategy}" + exit 1 + fi + curl -Ss "${url}${result}" +done -- cgit v1.2.3-54-g00ecf