Table of Contents
CHECK_DOCKER_INFO
Script: check_docker_info
check_docker_info_ shows the docker version and count of containers. You get the count of containers by state running, paused or stopped. This check sends performance data.
Requirements
-
docker
Docker must be installed -
jq
Docker must be installed - sudo permissions on docker command
icingaclient ALL=(ALL) NOPASSWD:SETENV: /usr/bin/docker
Standalone installation
From this repository ypu need next to this script:
-
inc_pluginfunctions
shared function for all IML checks written in bash -
inc_dockerfunctions.sh
Rootless docker
It works with docker setups as root and can handle rootless docker instances.
To bring it up and running with an unpriviledged icinga user it must be able to access docker. Copy the docker binary eg. from /home/dockeruser/bin/docker to /usr/bin/. Then use the parameter -p /usr/bin
.
If DOCKER_HOST is not set then the docker socket is detected from a running docker instance and will be fetched from the process list.
Syntax
______________________________________________________________________
CHECK_DOCKER_INFO
v1.5
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_docker_info.html
______________________________________________________________________
Show docker version and count of containers total and by its status.
It returns
CRITICAL if a created container is not running.
OK if no container was created yet or all conmtainers are running.
UNKNOWM if
- docker or jq were not found
- docker data were not fetched
- docker cannot be connected
This check provides performance data.
USAGE:
check_docker_info [OPTIONS]
OPTIONS:
General:
-h, --help this help
-d, --debug Debug; Flag: show all docker system infos
Connect to docker:
-p, --path Custom directory for docker binary
-t, --target Custom docker target; value for DOCKER_HOST
Needed only if Docker does not run on a unix socket or
multiple users run a rootless docker daemon.
Flags:
-c, --containers Flag: Show containers (slow)
-e, --errors Flag: Show containers on error only (slow)
EXAMPLES:
check_docker_info
Show Status of all containers
check_docker_info -c
Show Status of all containers and a list of container names with its
status. Warning: this feature uses docker ps --all and can be slow.
check_docker_info -e
Show Status of all containers. If not all containers are running you
get a list of container names with its status.
check_docker_info -p /usr/bin
Show Status of all containers. The docker binary will be searched in
given path first - then in all other dirs of $PATH
check_docker_info -d
Show Status of all containers and json with all docker system infos.
Parameters
None.
Examples
$ ./check_docker_info
returns
OK: Docker 20.10.14 (Community Engine, rootless) .. containers: 2 running: 2 paused: 0 stopped: 0 .. images: 5
All containers are running
|containers-running=2;;;0;2 containers-paused=0;;;0;2 containers-stopped=0;;;0;2 images=33;;
Troubleshooting
Missing environment
sudo: sorry, you are not allowed to preserve the environment
UNKNOWN: No data. Unable to fetch Docker information.
Solution: you did not set SETENV in the sudoers config file
icingaclient ALL=(ALL) NOPASSWD:SETENV: /usr/bin/docker
Docker not found
If you get an error message that docker was not found then it is not reachable in ofe of the directories of $PATH. This can happen especialy in rootless docker instances.
Solution: Use the parameter -p /usr/bin
to define a target. Copy the docker binary there.