List all unhealthy containers
authorMartin Mágr <mmagr@redhat.com>
Tue, 3 Oct 2017 08:43:23 +0000 (10:43 +0200)
committerMartin Mágr <mmagr@redhat.com>
Mon, 9 Oct 2017 12:28:35 +0000 (14:28 +0200)
Currently the default Sensu check defined in docker/services/sensu-client.yaml
reports only first unhealthy container. This patch changes the check output
to contain list of all unhealthy containers.

Change-Id: I0a934367ef22984d9091d160ec7105092edc8149
Closes-Bug: #1720972
(cherry picked from commit 9b016c9f3fbe9552497737974b9928d1dff4d299)

docker/services/sensu-client.yaml

index b64231c..a535af4 100644 (file)
@@ -39,13 +39,17 @@ parameters:
   SensuDockerCheckCommand:
     type: string
     default: |
+      output=''
       for i in $(docker ps --format '{{.ID}}'); do
         if result=$(docker inspect --format='{{.State.Health.Status}}' $i 2>/dev/null); then
           if [ "$result" != 'healthy' ]; then
-            echo "$(docker inspect --format='{{.Name}}' $i) ($i): $(docker inspect --format='{{json .State}}' $i)" && exit 2;
+            output="${output} ; $(docker inspect --format='{{.Name}}' $i) ($i): $(docker inspect --format='{{(index .State.Health.Log 0).Output}}' $i)";
           fi
         fi
       done
+      if [ ! -z "${output}" ]; then
+        echo ${output:3} && exit 2;
+      fi
   SensuDockerCheckInterval:
     type: number
     description: The frequency in seconds the docker health check is executed.