Skip to content

Instantly share code, notes, and snippets.

@dky
Created June 8, 2015 19:25
Show Gist options
  • Save dky/82a00acc0da5809c7b6e to your computer and use it in GitHub Desktop.
Save dky/82a00acc0da5809c7b6e to your computer and use it in GitHub Desktop.
check docker containers
#!/bin/bash
# Nagios Usage: check_nrpe!check_docker_container!_container_id_
# Usage: ./check_docker_container.sh _container_id_
#
# The script checks if a docker host if all container are running.
# OK - running
# UNKNOWN - Container has non-zero exit code
CONTAINERS=`docker ps | awk '{if (NR!=1) {print}}' | perl -ne '@cols = split /\s{2,}/, $_; printf "%30s %20s %20s\n", $cols[5]'`
for CONTAINER in `echo ${CONTAINERS}`
do
RUNNING=$(docker inspect --format="{{ .State.ExitCode }}" $CONTAINER 2> /dev/null)
if [ $RUNNING -eq 1 ]; then
echo "UNKNOWN - Check $CONTAINER state, non-zero Exit Code"
exit 3
fi
STARTED=$(docker inspect --format="{{ .State.StartedAt }}" $CONTAINER)
echo "OK - $CONTAINER is running. StartedAt: $STARTED"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment