Skip to content

Instantly share code, notes, and snippets.

@T2Knock
Created August 4, 2023 10:33
Show Gist options
  • Save T2Knock/1c0a170146f8e34e437f9d4bbc3b5273 to your computer and use it in GitHub Desktop.
Save T2Knock/1c0a170146f8e34e437f9d4bbc3b5273 to your computer and use it in GitHub Desktop.
quick and dirty docker event monitor
#!/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