Skip to content

Commit b991ef5

Browse files
authored
Improve notification code
Move some code used to send emails on warnings to the function notify_warning Saves some lines and makes the code more less cluttered
1 parent bde3482 commit b991ef5

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

snapraid-aio-script.sh

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ source "$CONFIG_FILE"
3333
SUBJECT="[WARNING] - Configuration Error $EMAIL_SUBJECT_PREFIX"
3434
NOTIFY_OUTPUT="$SUBJECT"
3535
notify_warning
36-
if [ "$EMAIL_ADDRESS" ]; then
37-
trim_log < "$TMP_OUTPUT" | send_mail
38-
fi
3936
exit 1;
4037
fi
4138

@@ -107,9 +104,6 @@ function main(){
107104
SUBJECT="[WARNING] - SnapRAID already running $EMAIL_SUBJECT_PREFIX"
108105
NOTIFY_OUTPUT="$SUBJECT"
109106
notify_warning
110-
if [ "$EMAIL_ADDRESS" ]; then
111-
trim_log < "$TMP_OUTPUT" | send_mail
112-
fi
113107
exit 1;
114108
else
115109
echo "SnapRAID is not running, proceeding."
@@ -146,10 +140,6 @@ function main(){
146140
FORMATTED_CONF="\`$SNAPRAID_CONF\`"
147141
NOTIFY_OUTPUT="$SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist."
148142
notify_warning
149-
if [ "$EMAIL_ADDRESS" ]; then
150-
trim_log < "$TMP_OUTPUT" | send_mail
151-
fi
152-
exit 1;
153143
fi
154144
fi
155145

@@ -206,9 +196,6 @@ function main(){
206196
SUBJECT="[WARNING] - Unable to continue with SYNC/SCRUB job(s). Check DIFF job output. $EMAIL_SUBJECT_PREFIX"
207197
NOTIFY_OUTPUT="$SUBJECT"
208198
notify_warning
209-
if [ "$EMAIL_ADDRESS" ]; then
210-
trim_log < "$TMP_OUTPUT" | send_mail
211-
fi
212199
exit 1;
213200
fi
214201
if [ $IGNORE_PATTERN ]; then
@@ -403,9 +390,6 @@ function sanity_check() {
403390
SUBJECT="[WARNING] - Parity file ($i) not found! $EMAIL_SUBJECT_PREFIX"
404391
NOTIFY_OUTPUT="$SUBJECT"
405392
notify_warning
406-
if [ "$EMAIL_ADDRESS" ]; then
407-
trim_log < "$TMP_OUTPUT" | send_mail
408-
fi
409393
exit 1;
410394
fi
411395
done
@@ -424,9 +408,6 @@ function sanity_check() {
424408
SUBJECT="[WARNING] - Content file ($i) not found! $EMAIL_SUBJECT_PREFIX"
425409
NOTIFY_OUTPUT="$SUBJECT"
426410
notify_warning
427-
if [ "$EMAIL_ADDRESS" ]; then
428-
trim_log < "$TMP_OUTPUT" | send_mail
429-
fi
430411
exit 1;
431412
fi
432413
done
@@ -882,6 +863,9 @@ function notify_warning(){
882863
-d '{"content": "'"$DISCORD_SUBJECT"'"}' \
883864
"$DISCORD_WEBHOOK_URL"
884865
fi
866+
if [ "$EMAIL_ADDRESS" ]; then
867+
trim_log < "$TMP_OUTPUT" | send_mail
868+
fi
885869
}
886870

887871
function show_snapraid_info() {
@@ -1070,9 +1054,6 @@ elif [ $result -eq 2 ]; then
10701054
FORMATTED_CONF="\`$SNAPRAID_CONF\`"
10711055
NOTIFY_OUTPUT="$SUBJECT Stopping the script due to multiple SnapRAID configuration files. Please choose one config file and update your settings in the script-config file at ""$CONFIG_FILE""."
10721056
notify_warning
1073-
if [ "$EMAIL_ADDRESS" ]; then
1074-
trim_log < "$TMP_OUTPUT" | send_mail
1075-
fi
10761057
exit 1;
10771058

10781059
else
@@ -1083,9 +1064,6 @@ else
10831064
FORMATTED_CONF="\`$SNAPRAID_CONF\`"
10841065
NOTIFY_OUTPUT="$SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist."
10851066
notify_warning
1086-
if [ "$EMAIL_ADDRESS" ]; then
1087-
trim_log < "$TMP_OUTPUT" | send_mail
1088-
fi
10891067
exit 1;
10901068
fi
10911069
}

0 commit comments

Comments
 (0)