From fcfa9ac0649a1433f5e6057131706629e3b6b81c Mon Sep 17 00:00:00 2001 From: Tunghsiao Liu Date: Fri, 26 Feb 2016 14:54:34 +0800 Subject: [PATCH] Add Slack incoming webhook notifications support --- duplicity-backup.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/duplicity-backup.sh b/duplicity-backup.sh index d36ea7e..e7f81e4 100755 --- a/duplicity-backup.sh +++ b/duplicity-backup.sh @@ -370,6 +370,15 @@ email_logfile() fi } +send_notification() +{ + if [ ! -z "$NOTIFICATION_SERVICE" ]; then + if [ "$NOTIFICATION_SERVICE" = "slack" ]; then + curl -X POST -H 'Content-type: application/json' --data "{\"text\": \"$NOTIFICATION_CONTENT\", \"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNAME\", \"icon_emoji\": \":$SLACK_EMOJI:\"}" ${SLACK_HOOK_URL} + fi + fi +} + get_lock() { echo "Attempting to acquire lock ${LOCKFILE}" >> ${LOGFILE} @@ -858,6 +867,20 @@ else email_logfile fi +if [ "$NOTIFICATION_FAILURE_ONLY" = "yes" ]; then + if [ ${BACKUP_ERROR} ]; then + NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`" + send_notification + fi +else + if [ ${BACKUP_ERROR} ]; then + NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`" + else + NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`" + fi + send_notification +fi + # remove old logfiles # stops them from piling up infinitely [[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find ${LOGDIR} -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete