Docker events notifier
Slack, Discord or Email notifications for docker events on your host, < 10mb image, no exposed ports.
General http webhooks like POST requests possible, e.g.
payload
docker hub: hasnat/docker-events-notifier
https://hub.docker.com/r/hasnat/docker-events-notifier/
Look for config.xml, template/*.json for email, slack, discord templates
Docker events Reference
Cli, making sure you have copy of templates and config.yml in current directory
docker run -it \
--name docker-events-notifier \
-e HOST_TAG=local \
-e DOCKER_API_VERSION=1.43 \
-e RLOG_LOG_LEVEL=DEBUG \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-v "$(pwd)/config.yml:/etc/docker-events-notifier/config.yml" \
-v "$(pwd)/templates:/etc/docker-events-notifier/templates" \
hasnat/docker-events-notifier
Compose
version: '2'
services:
docker-events-notifier:
image: hasnat/docker-events-notifier
container_name: docker-events-notifier
environment:
HOST_TAG: local
DOCKER_API_VERSION: "1.43"
RLOG_LOG_LEVEL: DEBUG
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "./config.yml:/etc/docker-events-notifier/config.yml"
- "./templates:/etc/docker-events-notifier/templates"
Run & develop locally by, check docker-compose.override.yml
docker-compose up --build
Design you config by looking into docker events
& jq
command
notifiers:
slack:
url: "https://hooks.slack.com/services/XXXX"
template: /etc/docker-events-notifier/templates/slack.json
data_encoding: urlencode.payload
discord:
url: "https://hooks.discord.com/services/XXXX"
template: /etc/docker-events-notifier/templates/discord.json
data_encoding: json
email:
url: "smtp://user:pass@some.mail.host:587?from=sender@example.net&to=recipient1@example.net&to=recipient2@example.net"
template: /etc/docker-events-notifier/templates/email.txt
# global filters ( check https://docs.docker.com/engine/reference/commandline/events/#filter-events-by-criteria )
# anything not matching this would be ignored
filters:
event: ["start", "stop", "die", "destroy"]
# container: ["some_container_name"]
# image: ["hasnat/docker-events-notifier"]
notifications:
- title: "Alert me when tianon/.* based container dies with exitCode 1"
when_regex:
status: ["(die|destroy)"]
"Actor.Attributes.image": ["tianon/.*"]
when:
"Actor.Attributes.exitCode": ["1"]
notify:
- email
- slack
- discord
- title: "Alert only on slack when container dies with exitCode 0"
when_regex:
status: ["(die|destroy)"]
"Actor.Attributes.image": ["hasnat/.*"]
when:
"Actor.Attributes.exitCode": ["0"]
notify:
- slack
- discord
- title: "Alert me on anything happening to images by hasnat"
when_regex:
"Actor.Attributes.image": ["hasnat/.*"]
notify:
- email
- slack