Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Script to be notified by your UPS with differents notifications :
- Pushbullet
- Pushover
- SMS
- Discord

## Install
- Copy git
Expand All @@ -28,7 +29,7 @@ mkdir /var/log/nutNotify
chown nut:nut /var/log/nutNotify
cp nutNotify.logrotate /etc/logrotate.d
```

Activate nutNotify by editing `upsmon.conf` and replace "NOTIFYCMD" with `/usr/local/bin/nutNotify.sh`.

## Link
Here an article (in french) in my website about [the notification of Nut by Telegram Pushbullet or Pushover](https://www.monlinux.net/2023/02/nut-notifications-push-telegram-pushbullet-pushover-pour-ups/)
Expand Down
6 changes: 5 additions & 1 deletion nutNotify.conf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pushoverUserkey='xxxxxxxxxxxxxxxxxxxxxxxxxxxx' #UserKey
pushoverSubject="UPS event $argument" #subject sent by Pushover
pushoverMessage="$bodyDefault" #body message sent by Pushover

#--- Data for Discord ---#
discordWebhookURL=''
discordMessage="$bodyDefault" #body message sent by Discord

# methods to use on event (array to multi alert)
# can be mail, telegram, pushober, pushbullet, sms
# or an array like '(telegram mail)' for multiple methods
Expand All @@ -56,4 +60,4 @@ methodLowbatt=$methodDefault
methodFsd=$methodDefault
methodShutdown=$methodDefault
methodComm=$methodDefault
methodServerOnline=$methodDefault
methodServerOnline=$methodDefault
10 changes: 7 additions & 3 deletions nutNotifyBoot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ ! -e "$configFile" ] ; then
fi

function aide() {
echo "$0 [mail|pushbullet|telegram]"
echo "$0 [mail|pushbullet|telegram|discord]"
}

# verify method
Expand All @@ -29,7 +29,9 @@ elif [ $# == 1 ] ; then
echo "Error pushbullet not configured" 1>&2 && echo "Error telegram not configured" > $logfile && exit 1
elif [ "$1" == "telegram" ] && [ ! -x $curlBin ] && [ "$telegramAccessToken" != "" ] && [ "$telegramChatID" != "" ] ; then
echo "Error telegram not configured" 1>&2 && echo "Error telegram not configured" > $logfile && exit 1
elif [ "$1" == "mail" ] || [ "$1" == "pushbullet" ] || [ "$1" == "telegram" ] ; then
elif [ "$1" == "discord" ] && [ ! -x $curlBin ] && [ "$discordWebhookURL" != "" ] ; then
echo "Error discord is not configured" 1>&2 && echo "Error discord is not configured" > $logfile && exit 1
elif [ "$1" == "mail" ] || [ "$1" == "pushbullet" ] || [ "$1" == "telegram" ] || [ "$1" == "discord" ] ; then
notifynut_method="$1"
else
aide
Expand All @@ -52,8 +54,10 @@ if [ -e $flagfile ] ; then
sleep 30; sendTelegram "$text" "$telegramSubject" ;;
pushover)
sleep 30; sendPushover "$text" "$pushoverSubject" ;;
discord)
sleep 30; sendDiscord "$text" ;;
esac
rm $flagfile
fi

exit 0
exit 0
32 changes: 31 additions & 1 deletion nutNotifyFct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ function sendPushover {
return $returnCurl
}

function sendDiscord {
#replace default mesg
if [ "$2" != "" ] ; then
textDiscord="$2"
fi

#var verification
if [ "$discordWebhookURL" == "" ]; then
echo "Can't send message without a Discord webhook URL" 1>&2
addLog "Can't send message without a Discord webhook URL"
return 1
fi

tempjson=$(mktemp --suffix '.nutNotifyDiscord')
payload="{
\"content\": \"$message\"
}"

curl -s -H "Content-Type: application/json" -X POST -d "$payload" "$discordWebhookURL" > $tempjson
returnCurl=$?
if [ $returnCurl -ne 0 ]; then
cat $tempjson
fi
rm $tempjson
return $returnCurl
}

function conditionalNotification {
local event=$1
local text=$2
Expand Down Expand Up @@ -203,6 +230,9 @@ function conditionalNotification {
fi
if [[ " ${method[*]} " =~ " sms " ]] ; then
sendSms "$text"
fi
if [[ " ${method[*]} " =~ " discord " ]] ; then
sendDiscord "$text"
fi

}
}