Skip to content
Snippets Groups Projects
Commit c4ab3752 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '8066-docker-health' into 'master'

docker info:

See merge request !308
parents 825d05ac fbd45da4
Branches
No related tags found
1 merge request!308docker info:
......@@ -19,13 +19,14 @@
# 2024-01-29 v1.4 <axel.hahn@unibe.ch> add --target option
# 2024-02-13 v1.5 <axel.hahn@unibe.ch> update docker ps --format
# 2025-02-10 v1.6 <axel.hahn@unibe.ch> harden sourcing files
# 2025-06-23 v1.7 <axel.hahn@unibe.ch> check status output "(healthy)"; speedup output of containers
# ======================================================================
# shellcheck source=/dev/null
. "$( dirname "$0" )/inc_pluginfunctions" || exit 1
. "$( dirname "$0" )/inc_dockerfunctions.sh" || exit 1
self_APPVERSION=1.6
self_APPVERSION=1.7
# ----------------------------------------------------------------------
# FUNCTIONS
......@@ -66,8 +67,8 @@ OPTIONS:
multiple users run a rootless docker daemon.
Flags:
-c, --containers Flag: Show containers (slow)
-e, --errors Flag: Show containers on error only (slow)
-c, --containers Flag: Show containers
-e, --errors Flag: Show containers on error only
EXAMPLES:
$_self
......@@ -75,7 +76,7 @@ EXAMPLES:
$_self -c
Show Status of all containers and a list of container names with its
status. Warning: this feature uses docker ps --all and can be slow.
status.
$_self -e
Show Status of all containers. If not all containers are running you
......@@ -178,20 +179,23 @@ echo "$out"
if [ $bOptContainers -eq 1 ] && [ "$iCTotal" -gt "0" ]; then
echo
echo "Containers:"
# containers=$( sudo -n --preserve-env docker ps --all --format "{{ json . }}" --all 2>/dev/null )
containers=$( sudo -n --preserve-env docker ps --all --format '{"Names": "{{.Names}}", "State": "{{.State}}", "Status": "{{.Status}}" }' 2>/dev/null )
# containers=$( sudo -n --preserve-env docker ps --all --format '{"Names": "{{.Names}}", "State": "{{.State}}", "Status": "{{.Status}}" }' 2>/dev/null )
containers=$( sudo -n --preserve-env docker ps --format "table {{.Names}} | {{.State}} | {{.Status}}" --all 2>/dev/null | sed -n 2,\$p )
echo "$containers" | while read -r line; do
sName=$( _getString "$line" ".Names" )
sState=$( _getString "$line" ".State" )
sStatus=$( _getString "$line" ".Status" )
sIco=
# Icinga ui does not show these characters
# sIco="🔶"
# grep "exited" <<< "${sState}" >/dev/null && sIco="❌"
# grep "running" <<< "${sState}" >/dev/null && sIco="✅"
printf " %-14s %-40s %-20s\n" "$sIco $sState" "$sName" "$sStatus"
contStatus="OK"
if grep -q "(" <<< "$line"; then
if grep -Fv "(healthy)" <<< "$line" | grep -q "("; then
contStatus="??"
# commented because within a while loop I am in a subshell
# ph.setStatus critical
fi
else
if ! grep -q "| running |" <<< "$line"; then
contStatus="??"
fi
fi
echo "$contStatus $line"
done
echo
......
......@@ -37,7 +37,7 @@ If DOCKER_HOST is not set then the docker socket is detected from a running dock
______________________________________________________________________
CHECK_DOCKER_INFO
v1.6
v1.7
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
......@@ -73,8 +73,8 @@ OPTIONS:
multiple users run a rootless docker daemon.
Flags:
-c, --containers Flag: Show containers (slow)
-e, --errors Flag: Show containers on error only (slow)
-c, --containers Flag: Show containers
-e, --errors Flag: Show containers on error only
EXAMPLES:
check_docker_info
......@@ -82,7 +82,7 @@ EXAMPLES:
check_docker_info -c
Show Status of all containers and a list of container names with its
status. Warning: this feature uses docker ps --all and can be slow.
status.
check_docker_info -e
Show Status of all containers. If not all containers are running you
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment