Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from benjamin-maynard/dev
Browse files Browse the repository at this point in the history
Version 1.1.1 - Fix Slack alerting
  • Loading branch information
benjamin-maynard authored Dec 16, 2018
2 parents 66e0096 + d4a5e90 commit c76ecc2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v1.1.1] - 16-12-2018
### Fix issue with Slack Alerts
- Fixed issue with failed Slack alerts when log messages contained special characters
- Fixed /bin/ash error when evaluating if the log files are empty or not
- Fixed an error message about the log file not existing when the backup runs successfully
- Suppressed CURL output for Slack alerts

## [v1.1.0] - 15-12-2018
### Slack Integration & Error Handling
- Added Slack Integration
Expand Down
8 changes: 4 additions & 4 deletions resources/perform-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ else
fi


# Put the contents of the database backup logs into a variable
logcontents=`cat /tmp/aws-database-backup.log`


# Check if any of the backups have failed. If so, exit with a status of 1. Otherwise exit cleanly with a status of 0.
if [ "$has_failed" = true ]
then

# If Slack alerts are enabled, send a notification alongside a log of what failed
if [ "$SLACK_ENABLED" = true ]
then
# Put the contents of the database backup logs into a variable
logcontents=`cat /tmp/aws-database-backup.log`

# Send Slack alert
/slack-alert.sh "One or more backups on database host $TARGET_DATABASE_HOST failed. The error details are included below:" "$logcontents"
fi

Expand Down
8 changes: 4 additions & 4 deletions resources/slack-alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


# Check if there is any value in $2. If so, post an entry to the Slack channel with log information. If not, send a general message that all databases successfully completed
if [ -v "$2"]
if [ "$(printf '%s' "$2")" == '' ]
then
PAYLOAD="payload={\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNAME\", \"text\": \"$1\", \"icon_emoji\": \":slack:\"}"
else
PAYLOAD="payload={\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNAME\", \"text\": \"$1\`\`\`$2\`\`\`\", \"icon_emoji\": \":slack:\"}"
PAYLOAD="payload={\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNAME\", \"text\": \"$1\`\`\`$(echo $2 | sed "s/\"/'/g")\`\`\`\", \"icon_emoji\": \":slack:\"}"
fi


curl -X POST --data-urlencode "$PAYLOAD" "$SLACK_WEBHOOK_URL"
# Send Slack message
curl -s -X POST --data-urlencode "$PAYLOAD" "$SLACK_WEBHOOK_URL" > /dev/null

0 comments on commit c76ecc2

Please sign in to comment.