Sign inSign up

dokeraj/deathwatch

By dokeraj

Updated over 5 years ago

Python script to notify when docker container crashes, through Discord / Telegram / Slack

Image
0

831

dokeraj/deathwatch repository overview

This is a python script that notifies the user through Discord, Telegram or Slack, when a container has crashed

It notifies only when a Docker event die or oom is being triggered. Additionally it offers the customization to pick which exit codes to be listening for.

discord notification

Supported Architectures

  • armhf - Raspberry Pi 3 and 4
  • amd64

The tag latest is multi-arch, so you can use it for any architecture.

Usage

IMPORTANT: you must create the following file named config.yml and place it in a folder, that will be binded to a volume. Otherwise you cannot use this docker image.

config.yml

general_settings:
  tags: ## DELETE IF NOT USED. List of tags you want to appear in notifications for identification purposes
    - myTag
    - Production
  inclusions: ## DELETE IF NOT USED. Name of the containers you ONLY want to include to be watched by deathwatch. Use only if you want a small number of containers to be watched. Warning: Should not be used in conjunction with exclusions. Side note: delete both inclusions and exclusions if you want all containers to be monitored
    - example_container_name_1
    - example_container_name_2
  exclusions: ## DELETE IF NOT USED. Name of the containers you want to exclude in deathwatch. Use only if you want a small number of containers to be excluded. Warning: Should not be used in conjunction with inclusions. In case the same container name is in both include and exclude - exclude will take precedence. Side note: delete both inclusions and exclusions if you want all containers to be monitored
    - example_container_name_3
    - example_container_name_4

container_settings:
  exit_codes: ## exit codes for more granular control of the DIE container event
      - 1
      - 139
  restart_policy: ## DELETE IF NOT WANTED. Whether to notify when the container has crashed, but the restart policy was set to "on-failure"/"always"/"unless-stopped"
    enabled: true
    ## "max_count_notify" - the max number of times you will receive notification if the container is caught in a restart loop
    max_count_notify: 3

integrations: ## Available integrations
  telegram: ## DELETE IF NOT USED
    token: <PASTE YOUR TELEGRAM BOT TOKEN HERE>
    chat_id: <PASTE YOUR TELEGRAM BOT CHAT_ID HERE>
  discord: ## DELETE IF NOT USED
    url: <PASTE YOUR DISCORD WEBHOOK HERE>
  slack: ## DELETE IF NOT USED
    url: <PASTE YOUR SLACK WEBHOOK HERE>

The config.yml can also be found here.

YML config file settings explanation
SettingFunction
tagsOptional. You can specify the tags to show when the message is displayed - for easier searching through the chat application.
inclusionsOptional. Pick specific container names to be ONLY listened for - all the others that are not specified, will be ignored.
exclusionsOptional. Pick specific container names to be EXCLUDED from monitoring - all the others that are not specified, will be listened.
exit_codesMandatory. These are the default exit codes that will be listened for. You can change them as you see fit. Note, if you omit this setting, 1 and 139 exit code will be still default
restart_policyOptional. This setting is highly recommended if you have any containers that have been run with any restart policy (on-failure,always,unless-stopped). If this setting is being set to enabled:true then it will notify when a container has crashed and is being restarted.
max_count_notifyOptional. The maximum number of times a notification will be issued, if the container crashes and is being automatically restarted due to the restart policy. This setting prevents flooding on the chat app, if the docker container is stuck on a catastrophic reboot loop. Note, if you omit this setting and the restart_policy is enabled, then the default value for this setting will be 5
integrationsMandatory. This setting is self-explanatory. The thing is not self-explanatory is that, there must be at least one integration (telegram, discord or slack) setup in order for this image to work. Of course you can have all of the integrations set and the notification will be sent to all of them.

You can check which settings from the config.yml file have been actually set, by looking at the docker container's log.

Please note that all of the lines that have the comment ## DELETE IF NOT USED/WANTED means that you need to delete the parent and all of the child settings.

Docker create command

docker create \
--name deathwatch \
-v path/to/your/config/yml/file:/yaml/ \
-v /var/run/docker.sock:/var/run/docker.sock \
--restart unless-stopped \
dokeraj/deathwatch:latest
Binded volumes explanation
binded volumeFunction
-v path/to/your/config/yml/file:/yaml/Mandatory. This is the location where the config.yml file is stored on your local machine.
-v /var/run/docker.sock:/var/run/docker.sockMandatory. This bind should be left as it is - it helps the docker container to get access to docker server environment and monitor for events.

Github project

You can find the source at this location

Tag summary

Content type

Image

Digest

Size

25.3 MB

Last updated

over 5 years ago

docker pull dokeraj/deathwatch