mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-07-30 11:38:33 -07:00
Add a method to send a slack message and call it if a webhook url is specified in the /etc/plexupdate.cron.conf file.
This commit is contained in:
parent
a6953f1217
commit
2a0ea34337
1 changed files with 26 additions and 0 deletions
|
@ -15,6 +15,27 @@
|
|||
# (typically /var/log/daemon.log or /var/log/syslog)
|
||||
#
|
||||
|
||||
sendSlackMessage() {
|
||||
escapedText=$(cat ${1} | sed 's/"/\"/g' | sed "s/'/\'/g" )
|
||||
slackUsername=${SLACK_USERNAME:-plexupdate}
|
||||
|
||||
if [ $RET -eq 10 ] || [ $RET -eq 0 ]; then
|
||||
color="#36a64f"
|
||||
else
|
||||
color="#ad2d2d"
|
||||
fi
|
||||
ts=`date +%s`
|
||||
attachment="{\"color\": \"$color\",\"footer\": \"Plex Update\",\"title\": \"Log File\", \"text\": \"$escapedText\", \"ts\": $ts}"
|
||||
|
||||
if [ ! -z "$SLACK_CHANNEL" ]; then
|
||||
json="{\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$slackUsername\", \"attachments\": [$attachment]}"
|
||||
else
|
||||
json="{\"username\": \"$slackUsername\", \"attachments\": [$attachment]}"
|
||||
fi
|
||||
|
||||
curl -s -X POST -H 'Content-type: application/json' -d "$json" "$SLACK_WEBHOOK_URL"
|
||||
}
|
||||
|
||||
if [ ! -f /etc/plexupdate.cron.conf ]; then
|
||||
echo "ERROR: You have not configured /etc/plexupdate.cron.conf" >&2
|
||||
exit 255
|
||||
|
@ -59,6 +80,11 @@ if [ $RET -ne 0 ] ; then
|
|||
# Make sure user gets an email about this (when not success or if user has specified when)
|
||||
cat ${LOGFILE} >&2
|
||||
|
||||
# If there's a slack webhook specified then send a slack message with the log output
|
||||
if [ ! -z "$SLACK_WEBHOOK_URL" ]; then
|
||||
sendSlackMessage ${LOGFILE}
|
||||
fi
|
||||
|
||||
# Output will produce a cron email, so we can reset the exit status
|
||||
if [ $RET -eq 10 ]; then
|
||||
RET=0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue