Table of Contents
CHECK_DOCKER_SWARM_NODES
Script: check_docker_swarm_nodes
check_docker_swarm_nodes shows the node state of a docker swarm cluster. It checks the nodes are ‘active’ and ‘ready’ (not in drain state).
This check sends performance data.
Requirements
dockerDocker must be installedjqmust be installed - commandline JSON processor- sudo permissions on docker command
icingaclient ALL=(ALL) NOPASSWD:SETENV: /usr/bin/docker
Standalone installation
From this repository you need next to this script:
inc_pluginfunctionsshared function for all IML checks written in bashinc_dockerfunctions.sh
Syntax
______________________________________________________________________
CHECK_DOCKER_SWARM_NODES
v0.1
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_docker_swarm_nodes.html
______________________________________________________________________
Show docker swarm nodes
It returns
CRITICAL if a node is not 'ready' or availability is not 'active'
OK if all nodes are up and running
UNKNOWM if
- docker or jq were not found
- docker data were not fetched
- docker cannot be connected
- This host is not a swarm manager
USAGE:
check_docker_swarm_nodes [OPTIONS]
OPTIONS:
General:
-h, --help this help
-d, --debug Debug; Flag: add json of all docker nodes
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:
-n, --nodes Flag: Show services
-e, --errors Flag: Show containers on error only
EXAMPLES:
check_docker_swarm_nodes
Show a short status of all nodes
check_docker_swarm_nodes -e
Show short status with all nodes. Non OK services will be shown.
check_docker_swarm_nodes -s
Show long status with all services and its state.
check_docker_swarm_nodes -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_swarm_nodes -d
Add json with all docker node infos
Parameters
None.
Examples
Short status
$ ./check_docker_swarm_nodes
OK: Docker swarm services 3 ... OK: 3 errors: 0
|nodes-ok=3;;;0;3 nodes-critical=0;;;0;3
Long status
Without given options it returns a short info.
To show all nodes of a swarm cluster use -nor --nodes:
$ ./check_docker_swarm_services -n
OK: Docker swarm services 3 ... OK: 3 errors: 0
[OK] f89v7jn0uxvnla9agi6fmw2p7 * swarm-0.example.com Ready Active Leader 29.8.1
[OK] vqd6g506wjl00zipfo9q2ed3h swarm-1.example.com Ready Active Reachable 29.8.1
[OK] wb72ldwesr8ghz7hf5q6os8ud swarm-2.example.com Ready Active 29.8.1
|nodes-ok=3;;;0;3 nodes-critical=0;;;0;3
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.