Created
June 8, 2015 19:25
-
-
Save dky/82a00acc0da5809c7b6e to your computer and use it in GitHub Desktop.
check docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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