diff --git a/check_docker_info b/check_docker_info new file mode 100755 index 0000000000000000000000000000000000000000..db2fe9e07cc4186a9ce09816b797eac2138990b7 --- /dev/null +++ b/check_docker_info @@ -0,0 +1,115 @@ +#!/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 + +# ---------------------------------------------------------------------- diff --git a/docs/20_Checks/_index.md b/docs/20_Checks/_index.md index 5cb5fc2666c0f117ada8701ba583a687aaf73a24..720e28e3111978abdb9361a95690f355ce27564c 100644 --- a/docs/20_Checks/_index.md +++ b/docs/20_Checks/_index.md @@ -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) diff --git a/docs/20_Checks/check_docker_info.md b/docs/20_Checks/check_docker_info.md new file mode 100644 index 0000000000000000000000000000000000000000..2bf02f6de7c6908963a8f67684f5b8360a3e8d96 --- /dev/null +++ b/docs/20_Checks/check_docker_info.md @@ -0,0 +1,52 @@ +# 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;; +```