Skip to content

Instantly share code, notes, and snippets.

@lgfa29
Last active October 31, 2021 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgfa29/0f8947d813bc86283db5a4b8386298b8 to your computer and use it in GitHub Desktop.
Save lgfa29/0f8947d813bc86283db5a4b8386298b8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function nomad_curl {
cmd=(curl --silent -H "X-Nomad-Token: $NOMAD_TOKEN")
if [[ -n "$NOMAD_CACERT" ]]; then
cmd+=(--cacert "$NOMAD_CACERT" --key "$NOMAD_CLIENT_KEY" --cert "$NOMAD_CLIENT_CERT")
fi
"${cmd[@]}" "$@"
}
nomad_addr="${NOMAD_ADDR:-http://localhost:4646}"
nodes=$(nomad_curl "${nomad_addr}/v1/nodes")
nodes_len=$(echo "$nodes" | jq -r length )
node_ids=$(echo "$nodes" | jq -r -c '.[]|.ID')
echo "=> Found ${nodes_len} nodes"
echo "=> Nodes without Consul:"
echo ""
while IFS= read -r line; do
node=$(nomad_curl "${nomad_addr}/v1/node/${line}")
node_name=$(echo "$node" | jq -r -c '.Name')
consul_version=$(echo "$node" | jq -r -c '.Attributes["consul.version"]')
ip=$(echo "$node" | jq -r -c '.Attributes["unique.network.ip-address"]')
eligible=$(echo "$node" | jq -r -c '.SchedulingEligibility')
if [ "$consul_version" = "null" ] && [ "$eligible" = "eligible" ]; then
echo " $ip - $node_name - $line"
fi
done <<< "$node_ids"
#!/usr/bin/env bash
function nomad_curl {
cmd=(curl --silent -H "X-Nomad-Token: $NOMAD_TOKEN")
if [[ -n "$NOMAD_CACERT" ]]; then
cmd+=(--cacert "$NOMAD_CACERT" --key "$NOMAD_CLIENT_KEY" --cert "$NOMAD_CLIENT_CERT")
fi
"${cmd[@]}" "$@"
}
nomad_addr="${NOMAD_ADDR:-http://localhost:4646}"
nodes=$(nomad_curl "${nomad_addr}/v1/nodes")
nodes_len=$(echo "$nodes" | jq -r length )
node_ids=$(echo "$nodes" | jq -r -c '.[]|.ID')
echo "=> Found ${nodes_len} nodes"
echo "=> Nodes without Consul:"
echo ""
while IFS= read -r line; do
node=$(nomad_curl "${nomad_addr}/v1/node/${line}")
node_name=$(echo "$node" | jq -r -c '.Name')
consul_version=$(echo "$node" | jq -r -c '.Attributes["consul.version"]')
ip=$(echo "$node" | jq -r -c '.Attributes["unique.network.ip-address"]')
eligible=$(echo "$node" | jq -r -c '.SchedulingEligibility')
if [ "$consul_version" != "null" ] && [ "$eligible" != "eligible" ]; then
echo " $ip - $node_name - $line"
fi
done <<< "$node_ids"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment