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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
cf17ff7f
Commit
cf17ff7f
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
update docker ps --format
parent
a5ad4d17
Branches
Branches containing commit
No related tags found
1 merge request
!242
update docker ps --format
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_docker_info
+5
-2
5 additions, 2 deletions
check_docker_info
check_dockercontainer_info
+163
-0
163 additions, 0 deletions
check_dockercontainer_info
with
168 additions
and
2 deletions
check_docker_info
+
5
−
2
View file @
cf17ff7f
...
...
@@ -17,13 +17,14 @@
# 2024-01-23 v1.2 <axel.hahn@unibe.ch> Show a list of docker containers; add path
# 2024-01-24 v1.3 <axel.hahn@unibe.ch> remove emoji icons; handle "null" in license info; show rootless or not
# 2024-01-29 v1.4 <axel.hahn@unibe.ch> add --target option
# 2024-02-13 v1.5 <axel.hahn@unibe.ch> update docker ps --format
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_dockerfunctions.sh
self_APPVERSION
=
1.
4
self_APPVERSION
=
1.
5
# ----------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -176,7 +177,9 @@ echo "$out"
if
[
$bOptContainers
-eq
1
]
&&
[
"
$iCTotal
"
-gt
"0"
]
;
then
echo
echo
"Containers:"
containers
=
$(
sudo
-n
--preserve-env
docker ps
--all
--format
"{{ json . }}"
--all
2>/dev/null
)
# containers=$( sudo -n --preserve-env docker ps --all --format "{{ json . }}" --all 2>/dev/null )
containers
=
$(
sudo
-n
--preserve-env
docker ps
--all
--format
'{"Names": "{{.Names}}", "State": "{{.State}}", "Status": "{{.Status}}" }'
2>/dev/null
)
echo
"
$containers
"
|
while
read
-r
line
;
do
sName
=
$(
_getString
"
$line
"
".Names"
)
sState
=
$(
_getString
"
$line
"
".State"
)
...
...
This diff is collapsed.
Click to expand it.
check_dockercontainer_info
0 → 100755
+
163
−
0
View file @
cf17ff7f
#!/bin/bash
# ======================================================================
#
# Check DOCKERCONTAINER INFOS
#
# requirements:
# - docker
# - sudo permissions on docker command
#
# ----------------------------------------------------------------------
# Cli docs:
# https://docs.docker.com/engine/reference/commandline/docker/
# ----------------------------------------------------------------------
# 2024-01-18 v0.1 <axel.hahn@unibe.ch> init
# 2024-02-13 v1.0 <axel.hahn@unibe.ch> update docker ps --format
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_dockerfunctions.sh
self_APPVERSION
=
1.0
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function
_usage
(){
local
_self
=
$(
basename
$0
)
cat
<<
EOH
$(
ph.showImlHelpHeader
)
List existing containers and show container details.
To show details you can enter an id or define a regex
USAGE:
$_self
[OPTIONS]
OPTIONS:
-h Show this help and exit.
-s Show containers using 'docker ps --all' and exit.
-i ID
Show details for container with given id.
-f REGEX
Show details for first matching container with given regex in output
of 'docker ps --all'.
If the options -i and -f are used then -i ID has priority.
PARAMETERS:
ID Hexadcimal value for the container id
REGEX String to filter the container list. With it you can set an image
name or a container name.
EXAMPLES:
$_self
-s
Show all containers
$_self
-i 0356f42ed27d
Show container details of container with id 0356f42ed27d
$_self
-f myapp
Show container details of first container that matches "myapp" in the
output of the container list.
EOH
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
ph.hasParamoption
"h"
"
$@
"
;
bOptHelp
=
$?
if
[
$bOptHelp
-eq
0
]
;
then
_usage
exit
0
fi
if
[
-z
"
$1
"
]
;
then
ph.setStatus critical
ph.status
"No parameters were given. Use -h to get help."
ph.exit
fi
ph.require
"docker"
ph.require
"jq"
if
ph.hasParamoption
"s"
"
$@
"
;
then
echo
"List of all containers (docker ps --all):"
echo
docker ps
--all
echo
exit
0
fi
# --- get data
id
=
$(
ph.getValueWithParam
''
i
"
$@
"
)
regex
=
$(
ph.getValueWithParam
''
f
"
$@
"
)
if
[
-z
"
$id
"
]
;
then
if
[
-n
"
$regex
"
]
;
then
id
=
$(
docker ps
--all
|
grep
-E
"
$regex
"
|
head
-1
|
awk
'{ print $1 }'
)
fi
fi
if
[
-z
"
$id
"
]
;
then
ph.setStatus critical
ph.status
"No Docker id was given / found. Use -s to show all containers."
ph.exit
fi
_detectDockerenv
# data=$( sudo -n --preserve-env docker ps --all --format "{{ json . }}" --filter "id=$id" 2>/dev/null )
data
=
$(
sudo
-n
--preserve-env
docker ps
--all
--format
'{
"Names": "{{.Names}}",
"State": "{{.State}}",
"Status": "{{.Status}}",
"Status": "{{.Status}}",
"RunningFor": "{{.RunningFor}}",
"Image": "{{.Image}}",
"CreatedAt": "{{.CreatedAt}}",
"Size": "{{.Size}}",
"Mounts": "{{.Mounts}}",
"Ports": "{{.Ports}}"
}'
--filter
"id=
$id
"
2>/dev/null
)
if
[
-z
"
$data
"
]
;
then
ph.setStatus critical
ph.status
"Docker id [
$id
] does not exist. Use -s to show all containers."
ph.exit
fi
sState
=
$(
_getString
"
$data
"
".State"
)
sCreated
=
$(
_getString
"
$data
"
".RunningFor"
)
sStatus
=
$(
_getString
"
$data
"
".Status"
)
# --- generate result
test
"
$sState
"
!=
"running"
&&
ph.setStatus warning
test
"
$sState
"
=
"exited"
&&
ph.setStatus critical
# --- output
ph.status
"Docker id [
$id
]
$sState
.. created
$sCreated
..
$sStatus
"
echo
"
NAME
$(
_getString
"
$data
"
".Names"
)
image :
$(
_getString
"
$data
"
".Image"
)
created:
$(
_getString
"
$data
"
".CreatedAt"
)
..
$sCreated
size :
$(
_getString
"
$data
"
".Size"
)
mounts :
$(
_getString
"
$data
"
".Mounts"
)
ports :
$(
_getString
"
$data
"
".Ports"
|
grep
.
||
echo
'(None)'
)
"
ph.exit
# ----------------------------------------------------------------------
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