diff --git a/check_docker_stats b/check_docker_stats index d215f2fe4ec6e4c9e8ce427e876bb47c296d44ca..3c5d60dc2339e1c78871862e8482c8d71f0a220f 100755 --- a/check_docker_stats +++ b/check_docker_stats @@ -45,7 +45,7 @@ OPTIONS: General: -h, --help this help - -d, --debug Debug; Flag: show all docker system infos + -d, --debug Debug; Flag: show docker env values. Connect to docker: -p, --path Custom directory for docker binary @@ -127,22 +127,7 @@ _detectDockerenv # --- get stats data data=$( sudo -n --preserve-env docker stats --no-stream --format '{{ json . }}' ) - -if [ -z "$data" ]; then - # zero output could mean: - # - connect to docker failed - # - no data because no container is running - # --> let's detect it... - infos=$( sudo -n --preserve-env docker system info --format '{{ json . }}' ) - _detectDockererror "$infos" - - typeset -i iCRunning; - iCRunning=$(_getString "$data" ".ContainersRunning" ) - if [ "$iCRunning" -eq "0" ]; then - ph.status "$sLabel >> Do data. No container is running" - ph.exit - fi -fi +_detectDockererror "$data" # --- checks to detect maximum diff --git a/inc_dockerfunctions.sh b/inc_dockerfunctions.sh index 761ab31e3dba73d42d0f192ed39fc61a53937b92..e34e4251638290a06201a834cd8b1f26bef36cb9 100644 --- a/inc_dockerfunctions.sh +++ b/inc_dockerfunctions.sh @@ -12,6 +12,7 @@ # https://docs.docker.com/engine/reference/commandline/docker/ # ---------------------------------------------------------------------- # 2024-01-19 v1.0 <axel.hahn@unibe.ch> init +# 2024-01-29 v1.1 <axel.hahn@unibe.ch> _detectDockererror # ====================================================================== @@ -67,10 +68,28 @@ function _debugInfos(){ # detect error after dicker command. It stops if # - no content was fetched # - content contains key "ServerErrors" +# param string output of docker command (json) +# param bool flag: is output from docker system info function _detectDockererror(){ local data="$1" if [ -z "$data" ] ; then + if [ "$2" != "1" ]; then + # zero output could mean: + # - connect to docker failed + # - no data because no container is running + # --> let's detect it... + infos=$( sudo -n --preserve-env docker system info --format '{{ json . }}' ) + _detectDockererror "$infos" + + typeset -i iCRunning; + iCRunning=$(_getString "$data" ".ContainersRunning" ) + if [ "$iCRunning" -eq "0" ]; then + ph.status "No data. No container is running" + ph.exit + fi + fi + ph.setStatus unknown ph.status "No data. Unable to fetch Docker information." ph.exit