#!/bin/bash

LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do
  pushd $(dirname $f) > /dev/null
    for service in $(docker compose ps --services); do
      status=$(docker compose ps --format '{"name":"{{.Names}}","created":"{{.CreatedAt}}","elapsed":"{{.RunningFor}}","state":"{{.State}}","status":"{{.Status}}"}' ${service})
      if [ "${status}" ]; then
        echo $status
        if command -v bgsystemlog &> /dev/null
        then
          bgsystemlog -j streamline_emr -m ${status}
        fi
      else
        echo "no services found"
      fi
    fi
  popd > /dev/null
done
echo "done."