Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows to use a script for notifications #83

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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
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://raw.githubusercontent.com/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
Loading