Add containers counts in output message

This commit is contained in:
Benjamin Renard 2024-04-18 11:11:58 +02:00
parent 1cde0c3b86
commit d0b3649213
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -134,6 +134,7 @@ declare -A CONTAINER_STATUS_FILE
declare -A CONTAINER_PID
declare -A UPTODATE
declare -A ERRORS
declare -A UNKNOWNS
CHECKED_CONTAINERS=( )
debug "List running containers..."
@ -227,20 +228,23 @@ do
UPTODATE+=( ["$container"]=$STATUS )
else
ERRORS+=( ["$container"]=$STATUS )
[ $ex -ge 3 ] && UNKNOWNS+=( "$container" )
fi
[ $EXIT_CODE -ge $ex ] && continue
[ $ex -gt 3 ] && ex=3
EXIT_CODE=$ex
done
NOTFOUNDS=()
if ! is_empty $ONLY_CONTAINERS
then
for container in ${ONLY_CONTAINERS[@]}
do
if ! in_array $container ${CHECKED_CONTAINERS[@]}
then
debug "$container - Not found"
ERRORS+=( ["$container"]="Not found" )
debug "$container - Container not found"
ERRORS+=( ["$container"]="Container not found" )
NOTFOUNDS+=( "$container" )
EXIT_CODE=3
fi
done
@ -250,16 +254,16 @@ debug "Final exit code: $EXIT_CODE"
case $EXIT_CODE in
0)
echo "OK - All containers are uptodate"
echo "OK - All ${#UPTODATE[@]} container(s) are uptodate"
;;
1)
echo "WARNING - some containers need to be updated"
echo "WARNING - ${#ERRORS[@]} container(s) need to be updated"
;;
2)
echo "CRITICAL - some containers need to be updated"
echo "CRITICAL - ${#ERRORS[@]} container(s) need to be updated"
;;
*)
echo "UNKNOWN - fail to retrieve status of some containers"
echo "UNKNOWN - fail to retrieve status of ${#UNKNOWNS[@]} container(s)"
;;
esac
for container in ${!ERRORS[@]}