Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
fb303bb3
Commit
fb303bb3
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Plain Diff
Merge branch 'docker-checks' into 'master'
Docker checks See merge request
!230
parents
066bf511
ea97b5fd
Branches
Branches containing commit
No related tags found
1 merge request
!230
Docker checks
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
check_docker_info
+37
-24
37 additions, 24 deletions
check_docker_info
docs/20_Checks/check_docker_info.md
+35
-1
35 additions, 1 deletion
docs/20_Checks/check_docker_info.md
inc_dockerfunctions.sh
+69
-0
69 additions, 0 deletions
inc_dockerfunctions.sh
with
141 additions
and
25 deletions
check_docker_info
+
37
−
24
View file @
fb303bb3
...
@@ -5,17 +5,21 @@
...
@@ -5,17 +5,21 @@
#
#
# requirements:
# requirements:
# - docker
# - docker
# - sudo permissions on docker command
#
#
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# Cli docs:
# Cli docs:
# https://docs.docker.com/engine/reference/commandline/docker/
# https://docs.docker.com/engine/reference/commandline/docker/
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# 2024-01-18 v1.0 <axel.hahn@unibe.ch> init
# 2024-01-18 v1.0 <axel.hahn@unibe.ch> init
# 2024-01-22 v1.1 <axel.hahn@unibe.ch> detect DOCKER; use sudo; add debug
# ======================================================================
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
self_APPVERSION
=
1.0
.
$(
dirname
$0
)
/inc_dockerfunctions.sh
self_APPVERSION
=
1.1
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# FUNCTIONS
# FUNCTIONS
...
@@ -30,38 +34,39 @@ $( ph.showImlHelpHeader )
...
@@ -30,38 +34,39 @@ $( ph.showImlHelpHeader )
Show docker version and count of containers total and by its status.
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:
USAGE:
$_self
[OPTIONS]
$_self
[OPTIONS]
OPTIONS:
OPTIONS:
-h this help
-h this help
-d Debug; Flag: show all docker system infos
EXAMPLES:
EXAMPLES:
$_self
$_self
Show Status of all containers
EOH
$_self
-d
}
Show Status of all containers and json with all docker system infos
# 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
EOH
# param string json data
# param string jq filter
function
_getString
(){
_filterJson
"
$1
"
"
$2
"
|
tr
-d
'"'
}
}
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# MAIN
# MAIN
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
ph.hasParamoption
"h"
"
$@
"
;
bOptHelp
=
$?
ph.hasParamoption
"h"
"
$@
"
;
bOptHelp
=
$?
ph.hasParamoption
"d"
"
$@
"
;
bOptDebug
=
$?
if
[
$bOptHelp
-eq
0
]
;
then
if
[
$bOptHelp
-eq
0
]
;
then
_usage
_usage
...
@@ -71,10 +76,12 @@ fi
...
@@ -71,10 +76,12 @@ fi
ph.require
"docker"
ph.require
"docker"
ph.require
"jq"
ph.require
"jq"
_detectDockerenv
# --- get data
# --- get data
data
=
$(
docker system info
--format
"{{ json . }}"
)
data
=
$(
sudo
-n
--preserve-env
docker system info
--format
'{{ json . }}'
)
_detectDockererror
"
$data
"
typeset
-i
iCTotal
;
typeset
-i
iCTotal
;
iCTotal
=
$(
_getString
"
$data
"
".Containers"
)
iCTotal
=
$(
_getString
"
$data
"
".Containers"
)
...
@@ -87,17 +94,21 @@ sLicense=$( _getString "$data" ".ProductLicense" )
...
@@ -87,17 +94,21 @@ sLicense=$( _getString "$data" ".ProductLicense" )
# --- generate result
# --- generate result
if
[
"
$iCTotal
"
-eq
"0"
]
;
then
out+
=
"No container was created yet."
else
if
[
"
$iCRunning
"
-eq
"0"
]
;
then
if
[
"
$iCRunning
"
-eq
"0"
]
;
then
ph.setStatus critical
ph.setStatus critical
out+
=
"No container is running"
out+
=
"No container is running"
else
else
if
[
"
$iCRunning
"
-ne
"
$iCTotal
"
]
;
then
if
[
"
$iCRunning
"
-ne
"
$iCTotal
"
]
;
then
ph.setStatus
warning
ph.setStatus
critical
out+
=
"Not all containers are running"
out+
=
"Not all containers are running"
else
else
out+
=
"All containers are running"
out+
=
"All containers are running"
fi
fi
fi
fi
fi
ph.perfadd
"containers-running"
"
$iCRunning
"
""
""
0
"
$iCTotal
"
ph.perfadd
"containers-running"
"
$iCRunning
"
""
""
0
"
$iCTotal
"
ph.perfadd
"containers-paused"
"
$iCPaused
"
""
""
0
"
$iCTotal
"
ph.perfadd
"containers-paused"
"
$iCPaused
"
""
""
0
"
$iCTotal
"
...
@@ -109,6 +120,8 @@ ph.perfadd "images" "$iImages"
...
@@ -109,6 +120,8 @@ ph.perfadd "images" "$iImages"
ph.status
"Docker
$sVersion
(
$sLicense
) .. containers:
$iCTotal
running:
$iCRunning
paused:
$iCPaused
stopped:
$iCStopped
.. images:
$iImages
"
ph.status
"Docker
$sVersion
(
$sLicense
) .. containers:
$iCTotal
running:
$iCRunning
paused:
$iCPaused
stopped:
$iCStopped
.. images:
$iImages
"
echo
"
$out
"
echo
"
$out
"
# if -d was given then show debug infos too
test
$bOptDebug
-eq
0
&&
(
echo
;
echo
"DEBUG: full docker system infos as json"
;
echo
"
$data
"
| jq
)
ph.exit
ph.exit
...
...
This diff is collapsed.
Click to expand it.
docs/20_Checks/check_docker_info.md
+
35
−
1
View file @
fb303bb3
...
@@ -9,6 +9,11 @@ This check sends performance data.
...
@@ -9,6 +9,11 @@ This check sends performance data.
## Requirements
## Requirements
*
`docker`
Docker must be installed
*
`docker`
Docker must be installed
*
sudo permissions on docker command
```
txt
icingaclient ALL=(ALL) NOPASSWD:SETENV: /usr/bin/docker
```
## Syntax
## Syntax
...
@@ -16,7 +21,7 @@ This check sends performance data.
...
@@ -16,7 +21,7 @@ This check sends performance data.
______________________________________________________________________
______________________________________________________________________
CHECK_DOCKER_INFO
CHECK_DOCKER_INFO
v1.
0
v1.
1
(c) Institute for Medical Education - University of Bern
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
Licence: GNU GPL 3
...
@@ -26,14 +31,29 @@ ______________________________________________________________________
...
@@ -26,14 +31,29 @@ ______________________________________________________________________
Show docker version and count of containers total and by its status.
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:
USAGE:
check_docker_info [OPTIONS]
check_docker_info [OPTIONS]
OPTIONS:
OPTIONS:
-h this help
-h this help
-d Debug; Flag: show all docker system infos
EXAMPLES:
EXAMPLES:
check_docker_info
check_docker_info
Show Status of all containers
check_docker_info -d
Show Status of all containers and json with all docker system infos
```
```
...
@@ -50,3 +70,17 @@ OK: Docker 20.10.14 (Community Engine) .. containers: 2 running: 2 paused: 0 sto
...
@@ -50,3 +70,17 @@ OK: Docker 20.10.14 (Community Engine) .. containers: 2 running: 2 paused: 0 sto
All containers are running
All containers are running
|containers-running=2;;;0;2 containers-paused=0;;;0;2 containers-stopped=0;;;0;2 images=33;;
|containers-running=2;;;0;2 containers-paused=0;;;0;2 containers-stopped=0;;;0;2 images=33;;
```
```
## Troubleshooting
### Missing environment
```
txt
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
This diff is collapsed.
Click to expand it.
inc_dockerfunctions.sh
0 → 100644
+
69
−
0
View file @
fb303bb3
#!/bin/bash
# ======================================================================
#
# Shared functions for DOCKER checks
#
# requirements:
# - docker
# - jq
#
# ----------------------------------------------------------------------
# Cli docs:
# https://docs.docker.com/engine/reference/commandline/docker/
# ----------------------------------------------------------------------
# 2024-01-19 v1.0 <axel.hahn@unibe.ch> init
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# 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
'"'
}
# if DOCKER_HOST is not set we try to detect the user running "containerd"
# create an env var DOCKER_HOST="unix:///run/user/<ID>/docker.sock"
function
_detectDockerenv
(){
if
[
-z
"
$DOCKER_HOST
"
]
;
then
dockeruid
=
$(
ps
-ef
|
grep
containerd |
grep
-Eo
"/run/user/([0-9]*)/"
|
head
-1
|
cut
-f
4
-d
'/'
)
test
-n
"
$dockeruid
"
&&
export
DOCKER_HOST
=
"unix:///run/user/
$dockeruid
/docker.sock"
# Don't abort - it is allowed that the variable DOCKER_HOST is missing
fi
}
# detect error after dicker command. It stops if
# - no content was fetched
# - content contains key "ServerErrors"
function
_detectDockererror
(){
local
data
=
"
$1
"
if
[
-z
"
$data
"
]
;
then
ph.setStatus unknown
ph.status
"No data. Unable to fetch Docker information."
ph.exit
fi
sSrvErrror
=
$(
_filterJson
"
$data
"
".ServerErrors"
)
if
[
"
$sSrvErrror
"
!=
"null"
]
;
then
ph.setStatus unknown
ph.status
"Unable to connect to Docker:"
echo
"
$sSrvErrror
"
|
grep
"^ "
ph.exit
fi
}
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment