feature configure method by the config file
This commit is contained in:
+14
-1
@@ -43,4 +43,17 @@ pushoverProviderApi='https://api.pushover.net/1/messages.json'
|
|||||||
pushoverAppToken='xxxxxxxxxxxxxxxxxxxxxxxxxxxx' #ApplicationToken
|
pushoverAppToken='xxxxxxxxxxxxxxxxxxxxxxxxxxxx' #ApplicationToken
|
||||||
pushoverUserkey='xxxxxxxxxxxxxxxxxxxxxxxxxxxx' #UserKey
|
pushoverUserkey='xxxxxxxxxxxxxxxxxxxxxxxxxxxx' #UserKey
|
||||||
pushoverSubject="UPS event $argument" #subject sent by Pushover
|
pushoverSubject="UPS event $argument" #subject sent by Pushover
|
||||||
pushoverMessage="$bodyDefault" #body message sent by Pushover
|
pushoverMessage="$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
|
||||||
|
methodDefault=mail
|
||||||
|
|
||||||
|
methodOnline=$methodDefault
|
||||||
|
methodOnbatt=$methodDefault
|
||||||
|
methodLowbatt=$methodDefault
|
||||||
|
methodFsd=$methodDefault
|
||||||
|
methodShutdown=$methodDefault
|
||||||
|
methodComm=$methodDefault
|
||||||
|
methodServerOnline=$methodDefault
|
||||||
+17
-36
@@ -29,10 +29,17 @@ powerdownflag=$(sed -ne 's#^ *POWERDOWNFLAG *\(.*\)$#\1#p' /etc/nut/upsmon.conf)
|
|||||||
# Variables
|
# Variables
|
||||||
configFile=/usr/local/etc/nutNotify.conf
|
configFile=/usr/local/etc/nutNotify.conf
|
||||||
|
|
||||||
source "$configFile"
|
if [ ! -e "$(dirname $0)/nutNotifyFct.sh" ] ; then
|
||||||
|
echo "Functions script $(dirname $0)/nutNotifyFct.sh doesn't exist" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
source "$(dirname $0)/nutNotifyFct.sh"
|
source "$(dirname $0)/nutNotifyFct.sh"
|
||||||
|
|
||||||
if [ ! -e "$configFile" ] ; then
|
if [ -e "$configFile" ] ; then
|
||||||
|
source "$configFile"
|
||||||
|
elif [ -e "$(dirname $0)/nutNotify.conf" ] ; then
|
||||||
|
source "$(dirname $0)/nutNotify.conf"
|
||||||
|
else
|
||||||
echo "File $configFile doesn't exist" 1>&2
|
echo "File $configFile doesn't exist" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -51,66 +58,43 @@ case "$argument" in
|
|||||||
ONLINE)
|
ONLINE)
|
||||||
text="UPS $ups is now online at $(date +'%H:%M:%S')"
|
text="UPS $ups is now online at $(date +'%H:%M:%S')"
|
||||||
writeLog
|
writeLog
|
||||||
sendMail "$subjectMail" "$text"
|
conditionalNotification $argument "$text" ""
|
||||||
#sendPushBullet "$pushbulletSubject" "$text"
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
sendTelegram "$text" "$telegramSubject"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
ONBATT)
|
ONBATT)
|
||||||
text="Powercut at $(date +'%H:%M:%S')! UPS $ups run on battery!"
|
text="Powercut at $(date +'%H:%M:%S')! UPS $ups run on battery!"
|
||||||
writeLog
|
writeLog
|
||||||
#sendMail "$subjectMail" "$text"
|
|
||||||
#sendPushBullet "$pushbulletSubject" "$text"
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
emoji=$(echo -e "\xE2\x9A\xA0")
|
emoji=$(echo -e "\xE2\x9A\xA0")
|
||||||
sendTelegram "$text" "$telegramSubject" "$emoji"
|
conditionalNotification $argument "$text" "$emoji"
|
||||||
# sendSms "$text"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
LOWBATT)
|
LOWBATT)
|
||||||
# note : notify get when /sbin/upsdrvctl shutdown executed
|
# note : notify get when /sbin/upsdrvctl shutdown executed
|
||||||
text="Low level battery at $(date +'%H:%M:%S') UPS $ups... Shutdown imminent !"
|
text="Low level battery at $(date +'%H:%M:%S') UPS $ups... Shutdown imminent !"
|
||||||
writeLog
|
writeLog
|
||||||
#sendMail "$subjectMail" "$text"
|
|
||||||
#sendPushBullet "$pushbulletSubject" "$text"
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
emoji=$(echo -e "\xF0\x9F\x94\xA5")
|
emoji=$(echo -e "\xF0\x9F\x94\xA5")
|
||||||
sendTelegram "$text" "$telegramSubject" "$emoji"
|
conditionalNotification $argument "$text" "$emoji"
|
||||||
# sendSms "$text"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
FSD)
|
FSD)
|
||||||
# note : for slave only
|
# note : for slave only
|
||||||
text="Force shutdown slave server $server at $(date +'%H:%M:%S') !"
|
text="Force shutdown slave server $server at $(date +'%H:%M:%S') !"
|
||||||
writeLog
|
writeLog
|
||||||
#sendMail "$subjectMail" "$text"
|
|
||||||
#sendPushBullet "$pushbulletSubject" "$text"
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
emoji=$(echo -e "\xE2\x9A\xA0")
|
emoji=$(echo -e "\xE2\x9A\xA0")
|
||||||
sendTelegram "$text" "$telegramSubject" "$emoji"
|
conditionalNotification $argument "$text" "$emoji"
|
||||||
# sendSms "$text"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
SHUTDOWN)
|
SHUTDOWN)
|
||||||
# note : executed on the master only
|
# note : executed on the master only
|
||||||
text="Shutdown master serveur $server at $(date +'%H:%M:%S') !"
|
text="Shutdown master serveur $server at $(date +'%H:%M:%S') !"
|
||||||
writeLog
|
writeLog
|
||||||
#sendMail "$subjectMail" "$text"
|
|
||||||
#sendPushBullet "$pushbulletSubject" "$text"
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
emoji=$(echo -e "\xF0\x9F\x94\xA5")
|
emoji=$(echo -e "\xF0\x9F\x94\xA5")
|
||||||
sendTelegram "$text" "$telegramSubject" "$emoji"
|
conditionalNotification $argument "$text" "$emoji"
|
||||||
# sendSms "$text"
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
COMMOK|COMMBAD|REPLBATT|NOCOMM)
|
COMMOK|COMMBAD|REPLBATT|NOCOMM)
|
||||||
writeLog
|
writeLog
|
||||||
#sendMail
|
conditionalNotification $argument "$text" ""
|
||||||
#sendPushBullet
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
sendTelegram "$text" "$telegramSubject"
|
|
||||||
# sendSms
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
SERVERONLINE)
|
SERVERONLINE)
|
||||||
@@ -120,11 +104,8 @@ SERVERONLINE)
|
|||||||
# add your script here to wakeup other servers etc
|
# add your script here to wakeup other servers etc
|
||||||
text="Serveur $server online at $(date +'%H:%M:%S') !"
|
text="Serveur $server online at $(date +'%H:%M:%S') !"
|
||||||
rm -f $powerdownflag && \
|
rm -f $powerdownflag && \
|
||||||
writeLog && \
|
writeLog
|
||||||
sendMail "$subjectMail" "$text"
|
conditionalNotification $argument "$text" ""
|
||||||
#sendPushBullet "$pushbulletSubject" "$text"
|
|
||||||
#sendPushover "$pushoverSubject" "$text"
|
|
||||||
sendTelegram "$text" "$telegramSubject"
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
@@ -154,4 +154,55 @@ function sendPushover {
|
|||||||
if [ $returnCurl -ne 0 ] ; then cat $tempfile ; fi
|
if [ $returnCurl -ne 0 ] ; then cat $tempfile ; fi
|
||||||
rm $tempfile
|
rm $tempfile
|
||||||
return $returnCurl
|
return $returnCurl
|
||||||
|
}
|
||||||
|
|
||||||
|
function conditionalNotification {
|
||||||
|
local event=$1
|
||||||
|
local text=$2
|
||||||
|
local emoji=$3
|
||||||
|
|
||||||
|
case "$event" in
|
||||||
|
ONLINE)
|
||||||
|
method=${methodOnline[*]}
|
||||||
|
;;
|
||||||
|
ONBATT)
|
||||||
|
method=${methodOnbatt[*]}
|
||||||
|
;;
|
||||||
|
LOWBATT)
|
||||||
|
method=${methodLowbatt[*]}
|
||||||
|
;;
|
||||||
|
FSD)
|
||||||
|
method=${methodFsd[*]}
|
||||||
|
;;
|
||||||
|
SHUTDOWN)
|
||||||
|
method=${methodShutdown[*]}
|
||||||
|
;;
|
||||||
|
COMMOK|COMMBAD|REPLBATT|NOCOMM)
|
||||||
|
method=${methodComm[*]}
|
||||||
|
;;
|
||||||
|
SERVERONLINE)
|
||||||
|
method=${methodServerOnline[*]}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Error : this event is not managed" 1>&2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "${method[*]}"
|
||||||
|
if [[ " ${method[*]} " =~ " mail " ]] ; then
|
||||||
|
sendMail "$subjectMail" "$text"
|
||||||
|
fi
|
||||||
|
if [[ " ${method[*]} " =~ " pushbullet " ]] ; then
|
||||||
|
sendPushBullet "$pushbulletSubject" "$text"
|
||||||
|
fi
|
||||||
|
if [[ " ${method[*]} " =~ " pushover " ]] ; then
|
||||||
|
sendPushover "$pushoverSubject" "$text"
|
||||||
|
fi
|
||||||
|
if [[ " ${method[*]} " =~ " telegram " ]] ; then
|
||||||
|
sendTelegram "$text" "$telegramSubject" "$emoji"
|
||||||
|
fi
|
||||||
|
if [[ " ${method[*]} " =~ " sms " ]] ; then
|
||||||
|
sendSms "$text"
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user