Skip to content

Instantly share code, notes, and snippets.

@soyo42
Last active March 17, 2020 08:22
Show Gist options
  • Save soyo42/ead834d6c164f2508e2ddea87ce9644e to your computer and use it in GitHub Desktop.
Save soyo42/ead834d6c164f2508e2ddea87ce9644e to your computer and use it in GitHub Desktop.
spring-boot service inspection (parallel)
Inspect spring-boot services (parallel) - reading their /info
EMPH="$(echo -en '\e[37;1m')"
NOC="$(echo -en '\e[0m')"
function getSafely() {
response="$(curl --write-out "\n%{http_code}" "$1" -m 5 2>/dev/null)"
status="$(echo "${response}" | tail -n 1)"
#echo "${status}" >&2
#echo "${response}"
if [[ "${status}" =~ ^2[0-9]{2}$ ]]; then
echo "${response}" | sed '$d'
else
echo "HTTP ${status}" >&2
fi
}
function digBuildInfo() {
if [ ! -t 0 ]; then
#cat
jq -r "(\"${EMPH}\" + .build.artifact + \":\" + .build.version + \" \" + .version + \"${NOC}\")"
fi
}
function digHealthInfo() {
if [ ! -t 0 ]; then
#cat
jq -r "(\"${EMPH}\" + .status + \"${NOC}\")"
fi
}
function dumpError() {
while read -e i; do echo -en "\e[41;1m! $i\e[0m "; done
}
#!/bin/bash
if [ -z "$1" ]; then
#echo "usage:: $0 <dataflow files, e.g.: IT*xml>"
echo "usage:: $0 <land project config, e.g.: application.yml>"
echo "usage:: $0 - # to read application.yml from stdin"
exit 1
fi
SCRIPT_HOME="$(dirname "$(readlink -f "$0")")"
source ${SCRIPT_HOME}/.util
# for i in "$@"; do
# echo $i
# echo 'cat //service/@api' | xmllint --nonet --shell $i
# done \
# | sed -En 's/^\s*api="(http[^"]{5,})".*$/\1/ p' \
# | sed -E -e 's~/api/?~~' -e 's~http:~https:~' -e 's~/graphql/?~~' \
if [[ "$1" != '-' ]]; then
application_yml="$1"
fi
cat ${application_yml} | yq -r '.client as $clients | $clients | keys[] | $clients[.].url' \
| sort -u \
| ( while read j; do
(
build="$(getSafely "${j}/info" 2> >(dumpError) 1> >(digBuildInfo))"
status="$(getSafely "${j}/health" 2> >(dumpError) 1> >(digHealthInfo))"
# fallback to actuator
if echo "${status}" | grep '!' > /dev/null; then
build="$(getSafely "${j}/actuator/info" 2> >(dumpError) 1> >(digBuildInfo))"
status="$(getSafely "${j}/actuator/health" 2> >(dumpError) 1> >(digHealthInfo))"
fi
echo "status= ${status} $j --> ${build}"
)&
done
wait
echo -e '\e[2m--done--\e[0m'
)
#!/bin/bash
SCRIPT_HOME="$(dirname "$(readlink -f "$0")")"
source ${SCRIPT_HOME}/.util
key=${0##*_}
echo "key: ${key}"
lands=(
#'fer-le-nz'
'fbm-le-se'
'fbm-le-lv'
'fbm-le-dk'
'myaccount'
)
function doInspect() {
build="$(getSafely "${1}/info" 2> >(dumpError) 1> >(digBuildInfo))"
status="$(getSafely "${1}/health" 2> >(dumpError) 1> >(digHealthInfo))"
# fallback to actuator
if echo "${status}" | grep '!' > /dev/null; then
build="$(getSafely "${1}/actuator/info" 2> >(dumpError) 1> >(digBuildInfo))"
status="$(getSafely "${1}/actuator/health" 2> >(dumpError) 1> >(digHealthInfo))"
fi
echo -e "\e[37;2mstatus:\e[0m ${status} $1 \e[37;2m-->\e[0m ${build}"
}
for i in "${lands[@]}"; do
echo -e "\e[37;2mLAND:\e[0m $i"
j="https://process-${i}.${key}.ferratum.com"
doInspect "$j" &
j="https://process-${i}-manager.${key}.ferratum.com"
doInspect "$j" &
done
wait
echo -e '\e[2m--done--\e[0m'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment