fcfa9ac0649a1433f5e6057131706629e3b6b81c
- Author
- Tunghsiao Liu <t@sparanoid.com>
- Committer
- Tunghsiao Liu <t@sparanoid.com>
- Date
Message
Add Slack incoming webhook notifications support
Diff
1diff --git a/duplicity-backup.sh b/duplicity-backup.sh
2index d36ea7ee95907e366d51ef27bd7f46ba6b2d084c..e7f81e4a22447edfa85151910ca74057ae1a053c 100755
3--- a/duplicity-backup.sh
4+++ b/duplicity-backup.sh
5@@ -370,6 +370,15 @@ email_logfile()
6 fi
7 }
8
9+send_notification()
10+{
11+ if [ ! -z "$NOTIFICATION_SERVICE" ]; then
12+ if [ "$NOTIFICATION_SERVICE" = "slack" ]; then
13+ 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}
14+ fi
15+ fi
16+}
17+
18 get_lock()
19 {
20 echo "Attempting to acquire lock ${LOCKFILE}" >> ${LOGFILE}
21@@ -858,6 +867,20 @@ else
22 email_logfile
23 fi
24
25+if [ "$NOTIFICATION_FAILURE_ONLY" = "yes" ]; then
26+ if [ ${BACKUP_ERROR} ]; then
27+ NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
28+ send_notification
29+ fi
30+else
31+ if [ ${BACKUP_ERROR} ]; then
32+ NOTIFICATION_CONTENT="BACKUP ERROR: ${HOSTNAME} - \`$LOGFILE\`"
33+ else
34+ NOTIFICATION_CONTENT="BACKUP OK: ${HOSTNAME} - \`$LOGFILE\`"
35+ fi
36+ send_notification
37+fi
38+
39 # remove old logfiles
40 # stops them from piling up infinitely
41 [[ -n "${REMOVE_LOGS_OLDER_THAN}" ]] && find ${LOGDIR} -type f -mtime +"${REMOVE_LOGS_OLDER_THAN}" -delete