Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds pushover notifications #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ AUTOHEAL_DEFAULT_STOP_TIMEOUT=10 # Docker waits max 10 seconds (the Docker def
DOCKER_SOCK=/var/run/docker.sock # Unix socket for curl requests to Docker API
CURL_TIMEOUT=30 # --max-time seconds for curl requests to Docker API
WEBHOOK_URL="" # post message to the webhook if a container was restarted (or restart failed)
PUSHOVER_USER_KEY="" # post message with pushover if a container was restarted (or restart failed), needs to be used in conjunction with PUSHOVER_APP_TOKEN
PUSHOVER_APP_TOKEN="" # post message with pushover if a container was restarted (or restart failed), needs to be used in conjunction with PUSHOVER_USER_KEY
```

### Optional Container Labels
Expand Down
18 changes: 18 additions & 0 deletions docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ DOCKER_SOCK=${DOCKER_SOCK:-/var/run/docker.sock}
UNIX_SOCK=""
CURL_TIMEOUT=${CURL_TIMEOUT:-30}
WEBHOOK_URL=${WEBHOOK_URL:-""}
PUSHOVER_APP_TOKEN=${PUSHOVER_APP_TOKEN:-""}
PUSHOVER_USER_KEY=${PUSHOVER_USER_KEY:-""}

# only use unix domain socket if no TCP endpoint is defined
case "${DOCKER_SOCK}" in
Expand Down Expand Up @@ -77,6 +79,20 @@ generate_webhook_payload() {
EOF
}

# https://support.pushover.net/i44-example-code-and-pushover-libraries#unix
notify_pushover() {
local message="$@"

if [ -n "$PUSHOVER_USER_KEY" ] && [ -n "$PUSHOVER_APP_TOKEN" ]
then
curl -s \
--form-string "token=${PUSHOVER_APP_TOKEN}" \
--form-string "user=${PUSHOVER_USER_KEY}" \
--form-string "message=${message}" \
https://api.pushover.net/1/messages.json
fi
}

# SIGTERM-handler
term_handler() {
exit 143 # 128 + 15 -- SIGTERM
Expand Down Expand Up @@ -116,8 +132,10 @@ if [ "$1" = "autoheal" ] && [ -e "$DOCKER_SOCK" ];then
then
echo "$DATE Restarting container $CONTAINER_SHORT_ID failed" >&2
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" &
notify_pushover "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" &
else
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
notify_pushover "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
fi
fi
done
Expand Down