From 8855498e1ddf8ccd773065eadfc0f70e0fd67831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 26 Sep 2023 11:19:07 +0200 Subject: [PATCH] consul/get_services: tabulated list of services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- consul/get_services.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 consul/get_services.sh diff --git a/consul/get_services.sh b/consul/get_services.sh new file mode 100755 index 0000000..428019a --- /dev/null +++ b/consul/get_services.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +CONSUL_URL="${CONSUL_URL:-http://localhost:8500/v1/catalog}" +SERVICE="${1}" + +[[ -z "${SERVICE}" ]] && { echo "No service name given!" >&2; exit 1; } + +readarray -t DCS < <(curl -s "${CONSUL_URL}/datacenters" | jq -r '.[]') + +for DC in "${DCS[@]}"; do + curl -s "${CONSUL_URL}/service/${SERVICE}?dc=${DC}" +done \ + | jq -r '.[] | [.Node, .ServiceName, .ServiceID, .ServiceMeta.version] | @tsv' \ + | column -t