Skip to content
Snippets Groups Projects
Commit 066bf511 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'docker-checks' into 'master'

add docker info with count of containers

See merge request !229
parents 4de9cff4 c2e18fe9
No related branches found
No related tags found
1 merge request!229add docker info with count of containers
#!/bin/bash
# ======================================================================
#
# Check DOCKER INFOS
#
# requirements:
# - docker
#
# ----------------------------------------------------------------------
# Cli docs:
# https://docs.docker.com/engine/reference/commandline/docker/
# ----------------------------------------------------------------------
# 2024-01-18 v1.0 <axel.hahn@unibe.ch> init
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
self_APPVERSION=1.0
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function _usage(){
local _self=$( basename $0 )
cat <<EOH
$( ph.showImlHelpHeader )
Show docker version and count of containers total and by its status.
USAGE:
$_self [OPTIONS]
OPTIONS:
-h this help
EXAMPLES:
$_self
EOH
}
# filter json data with jq
# param string json data
# param string jq filter
function _filterJson(){
echo "$1" | jq "$2"
}
# filter json data with jq (by expecting a single result) and remove quotes
# param string json data
# param string jq filter
function _getString(){
_filterJson "$1" "$2" | tr -d '"'
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
ph.hasParamoption "h" "$@"; bOptHelp=$?
if [ $bOptHelp -eq 0 ]; then
_usage
exit 0
fi
ph.require "docker"
ph.require "jq"
# --- get data
data=$( docker system info --format "{{ json . }}" )
typeset -i iCTotal;
iCTotal=$( _getString "$data" ".Containers" )
iCRunning=$(_getString "$data" ".ContainersRunning" )
iCPaused=$( _getString "$data" ".ContainersPaused" )
iCStopped=$(_getString "$data" ".ContainersStopped" )
iImages=$( _getString "$data" ".Images" )
sVersion=$( _getString "$data" ".ServerVersion")
sLicense=$( _getString "$data" ".ProductLicense" )
# --- generate result
if [ "$iCRunning" -eq "0" ]; then
ph.setStatus critical
out+="No container is running"
else
if [ "$iCRunning" -ne "$iCTotal" ]; then
ph.setStatus warning
out+="Not all containers are running"
else
out+="All containers are running"
fi
fi
ph.perfadd "containers-running" "$iCRunning" "" "" 0 "$iCTotal"
ph.perfadd "containers-paused" "$iCPaused" "" "" 0 "$iCTotal"
ph.perfadd "containers-stopped" "$iCStopped" "" "" 0 "$iCTotal"
ph.perfadd "images" "$iImages"
# --- output
ph.status "Docker $sVersion ($sLicense) .. containers: $iCTotal running: $iCRunning paused: $iCPaused stopped: $iCStopped .. images: $iImages"
echo "$out"
ph.exit
# ----------------------------------------------------------------------
......@@ -20,6 +20,7 @@ There is one include script used by all checks:
* [check_cronstatus](check_cronstatus.md)
* [check_disk-io](check_disk-io.md)
* [check_dns_responsetime](check_dns_responsetime.md)
* [check_docker_info](check_docker_info.md)
* [check_eol](check_eol.md)
* [check_fs_errors](check_fs_errors.md)
* [check_fs_writable](check_fs_writable.md)
......
# CHECK_DOCKER_INFO
## Introduction
**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
## Syntax
```txt
______________________________________________________________________
CHECK_DOCKER_INFO
v1.0
(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.
USAGE:
check_docker_info [OPTIONS]
OPTIONS:
-h this help
EXAMPLES:
check_docker_info
```
### Parameters
None.
## Examples
`$ ./check_docker_info` returns
```txt
OK: Docker 20.10.14 (Community Engine) .. 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;;
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment