diff --git a/docker-api.sh b/docker-api.sh new file mode 100755 index 0000000..1eb0d7b --- /dev/null +++ b/docker-api.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +url=$1 +shift + +if (( $# )); then + url="$url?" +fi + +while (( $# > 1 )); do + key=$1 + value=$2 + shift 2 + url="${url}$key=$(echo $value | jq -s -R -r @uri)&" +done + +if (( $# )); then + url="${url}$1" +fi + +curl -s --fail-with-body --unix-socket /var/run/docker.sock "http://v1.45$url" diff --git a/services.sh b/services.sh index 891104f..c617662 100755 --- a/services.sh +++ b/services.sh @@ -3,12 +3,9 @@ source ./config.sh source ./logger.sh -sock=/var/run/docker.sock -url=http://v1.45 - LABEL="swarm-health-alerter.port" -curl -s --fail-with-body --unix-socket $sock $url/services -o /tmp/services +./docker-api.sh /services > /tmp/services if [ $? -ne 0 ]; then log_error "$(jq -r .message /tmp/services 2>/dev/null || cat /tmp/services)" exit 1