Created
August 4, 2023 10:33
-
-
Save T2Knock/1c0a170146f8e34e437f9d4bbc3b5273 to your computer and use it in GitHub Desktop.
quick and dirty docker event monitor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
event () { | |
timestamp="$(date "+%Y-%m-%d %H:%M:%S")"; | |
event_type=$1 | |
container_id=$2 | |
name=$(docker inspect --format {{.Name}} $container_id) | |
# curl to hook maybe | |
echo "$timestamp: $event_type $name" | |
} | |
docker events --filter 'type=container' --filter 'event=create' --filter 'event=restart' --filter 'event=destroy' | while read event | |
do | |
# space character is set as delimiter | |
IFS=' ' | |
# str is read into an array as tokens separated by IFS | |
read -ra values <<< "$event" | |
echo $event | |
#echo each of the value to output | |
event "${values[2]}" "${values[3]}" | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment