Skip to content

Commit

Permalink
Conditional notification
Browse files Browse the repository at this point in the history
  • Loading branch information
tito committed Jun 5, 2024
1 parent 724cda0 commit 8138133
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ You can configure the most behaviors of *Gantry* via environment variables.
| GANTRY_CLEANUP_IMAGES_OPTIONS | | [Options](https://docs.docker.com/engine/reference/commandline/service_create/#options) added to the `docker service create` command to create a global job for images removal. You can use this to add a label to the service or the containers. |
| GANTRY_NOTIFICATION_APPRISE_URL | | Enable notifications on service update with [apprise](https://github.com/caronc/apprise-api). This must point to the notification endpoint (e.g. `http://apprise:8000/notify`) |
| GANTRY_NOTIFICATION_TITLE | | Add an additional message to the notification title. |
| GANTRY_NOTIFICATION_CONDITION | all | Specifies the conditions under which notifications are sent.
Set to `all` to send notifications every run. Set to `changed-only` to send notifications only when there is a change or an error. |

## Authentication

Expand Down
12 changes: 11 additions & 1 deletion src/lib-gantry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,17 @@ _report_services() {
local TITLE BODY
TITLE="[${STACK}] ${NUM_UPDATED} services updated ${NUM_FAILED} failed${ERROR_STRING}"
BODY=$(echo -e "${UPDATED_MSG}\n${FAILED_MSG}\n${ERROR_MSG}")
_send_notification "${TYPE}" "${TITLE}" "${BODY}"

case "${GANTRY_NOTIFICATION_CONDITION:-all}" in
changed-only)
if [ "${NUM_UPDATED}" -gt 0 ] || [ "${NUM_TOTAL_ERRORS}" -gt 0 ]; then
_send_notification "${TYPE}" "${TITLE}" "${BODY}"
fi
;;
all|*)
_send_notification "${TYPE}" "${TITLE}" "${BODY}"
;;
esac
}

_in_list() {
Expand Down

0 comments on commit 8138133

Please sign in to comment.