From 0f50e94ad8d2379274befbe1b5b6d7037cf2e4e5 Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:01:35 -0500 Subject: [PATCH 1/8] Update nutNotify.conf.txt Added Discord support --- nutNotify.conf.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nutNotify.conf.txt b/nutNotify.conf.txt index 63430eb..4ebe3d2 100644 --- a/nutNotify.conf.txt +++ b/nutNotify.conf.txt @@ -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 Pushover + # 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 @@ -56,4 +60,4 @@ methodLowbatt=$methodDefault methodFsd=$methodDefault methodShutdown=$methodDefault methodComm=$methodDefault -methodServerOnline=$methodDefault \ No newline at end of file +methodServerOnline=$methodDefault From f4155cb8dc0ed24406e9a0e45381afe0a7fbc10b Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:02:35 -0500 Subject: [PATCH 2/8] Update nutNotify.conf.txt --- nutNotify.conf.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutNotify.conf.txt b/nutNotify.conf.txt index 4ebe3d2..f6cbb74 100644 --- a/nutNotify.conf.txt +++ b/nutNotify.conf.txt @@ -47,7 +47,7 @@ pushoverMessage="$bodyDefault" #body message sent by Pushover #--- Data for Discord ---# discordWebhookURL='' -discordMessage="$bodyDefault" #body message sent by Pushover +discordMessage="$bodyDefault" #body message sent by Discord # methods to use on event (array to multi alert) # can be mail, telegram, pushober, pushbullet, sms From 6d9c18c44ac84300cdc2bc61d4a7a3eaf4bee730 Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:16:07 -0500 Subject: [PATCH 3/8] Update nutNotifyFct.sh Add Discord support --- nutNotifyFct.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/nutNotifyFct.sh b/nutNotifyFct.sh index 8100589..560db75 100644 --- a/nutNotifyFct.sh +++ b/nutNotifyFct.sh @@ -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" -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 @@ -205,4 +232,4 @@ function conditionalNotification { sendSms "$text" fi -} \ No newline at end of file +} From a5ec2b717bb1087b905a0707cf31a7861a226589 Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:23:08 -0500 Subject: [PATCH 4/8] Update nutNotifyFct.sh --- nutNotifyFct.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nutNotifyFct.sh b/nutNotifyFct.sh index 560db75..81121e1 100644 --- a/nutNotifyFct.sh +++ b/nutNotifyFct.sh @@ -230,6 +230,9 @@ function conditionalNotification { fi if [[ " ${method[*]} " =~ " sms " ]] ; then sendSms "$text" + fi + if [[ " ${method[*]} " =~ " discord " ]] ; then + sendDiscord "$text" fi } From 90c4ed53e1563d2006cec36358a258f9e5383cfb Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:34:45 -0500 Subject: [PATCH 5/8] Update nutNotifyBoot.sh Add Discord Support --- nutNotifyBoot.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nutNotifyBoot.sh b/nutNotifyBoot.sh index b90b74c..50b2b13 100644 --- a/nutNotifyBoot.sh +++ b/nutNotifyBoot.sh @@ -12,7 +12,7 @@ if [ ! -e "$configFile" ] ; then fi function aide() { - echo "$0 [mail|pushbullet|telegram]" + echo "$0 [mail|pushbullet|telegram|discord]" } # verify method @@ -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 @@ -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 \ No newline at end of file +exit 0 From 70cbbe466268f647e3f863f685f479c6094edd18 Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:43:39 -0500 Subject: [PATCH 6/8] Update README.md Add Discord Support and added the last instruction for the activation of the script for those that follow the instructions without reading how the program works. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4b4d14..70914f4 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Script to be notified by your UPS with differents notifications : - Pushbullet - Pushover - SMS +- Discord ## Install - Copy git @@ -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/) From 0746173c34968ab39c57406a599d80fd7554b9a9 Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Sun, 6 Aug 2023 11:56:33 -0500 Subject: [PATCH 7/8] Update nutNotifyFct.sh corrected mistake in the Discord webhook variable. --- nutNotifyFct.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutNotifyFct.sh b/nutNotifyFct.sh index 81121e1..486316a 100644 --- a/nutNotifyFct.sh +++ b/nutNotifyFct.sh @@ -174,7 +174,7 @@ function sendDiscord { \"content\": \"$message\" }" - curl -s -H "Content-Type: application/json" -d "$payload" "$discordWebhookUrl" > $tempjson + curl -s -H "Content-Type: application/json" -X POST -d "$payload" "$discordWebhookURL" > $tempjson returnCurl=$? if [ $returnCurl -ne 0 ]; then cat $tempjson From 98282e6ee914d585987d0322eb8f137543fe6a2c Mon Sep 17 00:00:00 2001 From: NeoPlayer13 <98669870+NeoPlayer13@users.noreply.github.com> Date: Tue, 8 Aug 2023 19:45:53 -0500 Subject: [PATCH 8/8] mistake in variable --- nutNotifyFct.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nutNotifyFct.sh b/nutNotifyFct.sh index 486316a..9243dcb 100644 --- a/nutNotifyFct.sh +++ b/nutNotifyFct.sh @@ -163,7 +163,7 @@ function sendDiscord { fi #var verification - if [ "$discordWebhookUrl" == "" ]; then + 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