Add Slack incoming webhook notifications support

This commit is contained in:
Tunghsiao Liu 2016-02-26 14:54:34 +08:00
parent 17b3f70063
commit fcfa9ac064

View file

@ -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