Add performance data

This commit is contained in:
Benjamin Renard 2024-04-18 11:14:08 +02:00
parent d0b3649213
commit 28d084da36
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -40,6 +40,13 @@ function in_array() {
return 1 return 1
} }
function implode() {
local d=${1-} f=${2-}
if shift 2; then
printf %s "$f" "${@/#/$d}"
fi
}
function usage() { function usage() {
error="$1" error="$1"
[ -n "$error" ] && echo "$error" [ -n "$error" ] && echo "$error"
@ -252,20 +259,38 @@ fi
debug "Final exit code: $EXIT_CODE" debug "Final exit code: $EXIT_CODE"
debug "Check containers (${#CHECKED_CONTAINERS[@]}): $( implode ", " "${CHECKED_CONTAINERS[@]}" )"
debug "Containers with errors (${#ERRORS[@]}): $( implode ", " "${!ERRORS[@]}" )"
debug "Not found containers (${#NOTFOUNDS[@]}): $( implode ", " "${NOTFOUNDS[@]}" )"
# Compute performance data
let CONTAINER_COUNTS=${#CHECKED_CONTAINERS[@]}+${#NOTFOUNDS[@]}
PERF_DATA=(
"uptodate_containers=${#UPTODATE[@]};;;0;$CONTAINER_COUNTS"
"containers_with_errors=${#ERRORS[@]};1;;0;$CONTAINER_COUNTS"
"unknown_state_containers=${#UNKNOWNS[@]};;;0;$CONTAINER_COUNTS"
)
# Display check result message
case $EXIT_CODE in case $EXIT_CODE in
0) 0)
echo "OK - All ${#UPTODATE[@]} container(s) are uptodate" echo -n "OK - All ${#UPTODATE[@]} container(s) are uptodate"
;; ;;
1) 1)
echo "WARNING - ${#ERRORS[@]} container(s) need to be updated" echo -n "WARNING - ${#ERRORS[@]} container(s) need to be updated"
;; ;;
2) 2)
echo "CRITICAL - ${#ERRORS[@]} container(s) need to be updated" echo -n "CRITICAL - ${#ERRORS[@]} container(s) need to be updated"
;; ;;
*) *)
echo "UNKNOWN - fail to retrieve status of ${#UNKNOWNS[@]} container(s)" echo -n "UNKNOWN - fail to retrieve status of ${#UNKNOWNS[@]} container(s)"
;; ;;
esac esac
# Add performance data
echo " |$( implode " " "${PERF_DATA[@]}" )"
# Display details, starting by errors
for container in ${!ERRORS[@]} for container in ${!ERRORS[@]}
do do
echo ${container} - ${ERRORS[${container}]} echo ${container} - ${ERRORS[${container}]}