88# #####################
99# SCRIPT VARIABLES #
1010# #####################
11- SNAPSCRIPTVERSION=" 3.4" # DEV9
11+ SNAPSCRIPTVERSION=" 3.4" # DEV10
1212
1313# Read SnapRAID version
1414SNAPRAIDVERSION=" $( snapraid -V | sed -e ' s/snapraid v\(.*\)by.*/\1/' ) "
@@ -40,7 +40,7 @@ function main(){
4040 mklog " WARN: Please update your config file to the latest version. The current file is not compatible with this script!"
4141 SUBJECT=" [WARNING] - Configuration Error $EMAIL_SUBJECT_PREFIX "
4242 NOTIFY_OUTPUT=" $SUBJECT "
43- notify_warning
43+ notify_warning " fatal "
4444 exit 1;
4545 fi
4646
@@ -112,7 +112,7 @@ function main(){
112112 mklog " WARN: SnapRAID binary not found in PATH. Please check if SnapRAID is installed correctly and found in the PATH environment values of your system."
113113 SUBJECT=" [WARNING] - SnapRAID binary not found in PATH $EMAIL_SUBJECT_PREFIX "
114114 NOTIFY_OUTPUT=" $SUBJECT "
115- notify_warning
115+ notify_warning " fatal "
116116 exit 1
117117fi
118118
122122 mklog " WARN: The script has detected SnapRAID is already running. Please check the status of the previous SnapRAID job before running this script again."
123123 SUBJECT=" [WARNING] - SnapRAID already running $EMAIL_SUBJECT_PREFIX "
124124 NOTIFY_OUTPUT=" $SUBJECT "
125- notify_warning
125+ notify_warning " fatal "
126126 exit 1;
127127 else
128128 echo " SnapRAID is not running, proceeding."
158158 SUBJECT=" [WARNING] - SnapRAID configuration file not found!"
159159 FORMATTED_CONF=" \` $SNAPRAID_CONF \` "
160160 NOTIFY_OUTPUT=" $SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist."
161- notify_warning
161+ notify_warning " fatal "
162162 exit 1;
163163 fi
164164 fi
180180 echo " Stopping the script because the previous SnapRAID sync did not complete correctly."
181181 SUBJECT=" [WARNING] - Previous SnapRAID sync did not complete correctly."
182182 NOTIFY_OUTPUT=" $SUBJECT "
183- notify_warning
184- if [ " $EMAIL_ADDRESS " ]; then
185- trim_log < " $TMP_OUTPUT " | send_mail
186- fi
183+ notify_warning " fatal"
187184 exit 1;
188185
189186 elif [ $SNAPRAID_STATUS -eq 2 ]; then
190187 # Handle unknown status
191188 echo " Stopping the script due to unknown SnapRAID status. Please run 'snapraid status' on your host for more information."
192189 SUBJECT=" [WARNING] - SnapRAID unknown status"
193190 NOTIFY_OUTPUT=" $SUBJECT "
194- notify_warning
195- if [ " $EMAIL_ADDRESS " ]; then
196- trim_log < " $TMP_OUTPUT " | send_mail
197- fi
191+ notify_warning " fatal"
198192 exit 1;
199193 fi
200194
245239 echo " Exiting script. [$( date) ]"
246240 SUBJECT=" [WARNING] - Unable to continue with SYNC/SCRUB job(s). Check DIFF job output. $EMAIL_SUBJECT_PREFIX "
247241 NOTIFY_OUTPUT=" $SUBJECT "
248- notify_warning
242+ notify_warning " fatal "
249243 exit 1;
250244 fi
251245 if [ $IGNORE_PATTERN ]; then
414408 else
415409 # or send a short mail
416410 trim_log < " $TMP_OUTPUT " | send_mail
417- fi
411+ fi
418412 fi
419413
420414 # Save and rotate logs if enabled
@@ -445,7 +439,7 @@ function sanity_check() {
445439 # Add a topline to email body
446440 SUBJECT=" [WARNING] - Parity file ($i ) not found! $EMAIL_SUBJECT_PREFIX "
447441 NOTIFY_OUTPUT=" $SUBJECT "
448- notify_warning
442+ notify_warning " fatal "
449443 exit 1;
450444 fi
451445 done
@@ -463,7 +457,7 @@ function sanity_check() {
463457 # Add a topline to email body
464458 SUBJECT=" [WARNING] - Content file ($i ) not found! $EMAIL_SUBJECT_PREFIX "
465459 NOTIFY_OUTPUT=" $SUBJECT "
466- notify_warning
460+ notify_warning " fatal "
467461 exit 1;
468462 fi
469463 done
@@ -914,39 +908,45 @@ function notify_success(){
914908 }
915909
916910function notify_warning(){
911+ local MODE=" ${1:- nonfatal} " # default to nonfatal if not specified
912+
917913 if [ " $HEALTHCHECKS " -eq 1 ]; then
918914 curl -fsS -m 5 --retry 3 -o /dev/null " $HEALTHCHECKS_URL$HEALTHCHECKS_ID " /fail --data-raw " $NOTIFY_OUTPUT "
919915 fi
916+
920917 if [ " $TELEGRAM " -eq 1 ]; then
921918 curl -fsS -m 5 --retry 3 -o /dev/null -X POST \
922919 -H ' Content-Type: application/json' \
923920 -d ' {"chat_id": "' " $TELEGRAM_CHAT_ID " ' ", "text": "' " $NOTIFY_OUTPUT " ' "}' \
924921 https://api.telegram.org/bot" $TELEGRAM_TOKEN " /sendMessage
925922 fi
923+
926924 if [ " $DISCORD " -eq 1 ]; then
927- DISCORD_SUBJECT=$( echo " $NOTIFY_OUTPUT " | jq -Rs | cut -c 2- | rev | cut -c 2- | rev)
925+ DISCORD_SUBJECT=$( echo " $NOTIFY_OUTPUT " | jq -Rs | cut -c 2- | rev | cut -c 2- | rev)
928926 curl -fsS -m 5 --retry 3 -o /dev/null -X POST \
929927 -H ' Content-Type: application/json' \
930928 -d ' {"content": "' " $DISCORD_SUBJECT " ' "}' \
931929 " $DISCORD_WEBHOOK_URL "
932930 fi
933-
931+
934932 if [ " $APPRISE " -eq 1 ]; then
935- echo " Sending notification using Apprise service(s)."
936- for APPRISE_URL_U in " ${APPRISE_URL[@]} " ; do
937- if [ " $APPRISE_ATTACH " -eq 1 ]; then
938- " $APPRISE_BIN " -t " SnapRAID on $( hostname) " -b " $NOTIFY_OUTPUT " -a " $TMP_OUTPUT " " $APPRISE_URL_U "
939- else
940- " $APPRISE_BIN " -t " SnapRAID on $( hostname) " -b " $NOTIFY_OUTPUT " " $APPRISE_URL_U "
941- fi
942- done
933+ echo " Sending notification using Apprise service(s)."
934+ for APPRISE_URL_U in " ${APPRISE_URL[@]} " ; do
935+ if [ " $APPRISE_ATTACH " -eq 1 ]; then
936+ " $APPRISE_BIN " -t " SnapRAID on $( hostname) " -b " $NOTIFY_OUTPUT " -a " $TMP_OUTPUT " " $APPRISE_URL_U "
937+ else
938+ " $APPRISE_BIN " -t " SnapRAID on $( hostname) " -b " $NOTIFY_OUTPUT " " $APPRISE_URL_U "
939+ fi
940+ done
943941 fi
944-
945- if [ " $EMAIL_ADDRESS " ]; then
942+
943+ if [ " $EMAIL_ADDRESS " ] && [ " $MODE " == " fatal " ] ; then
946944 trim_log < " $TMP_OUTPUT " | send_mail
947945 fi
948- mklog " WARN: " $SUBJECT " "
949- }
946+
947+ mklog " WARN: $SUBJECT "
948+ }
949+
950950
951951function show_snapraid_info() {
952952 local command_output=$( $1 )
@@ -1209,7 +1209,7 @@ elif [ $result -eq 2 ]; then
12091209 SUBJECT=" [WARNING] - Multiple SnapRAID configuration files!"
12101210 FORMATTED_CONF=" \` $SNAPRAID_CONF \` "
12111211 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 " " ."
1212- notify_warning
1212+ notify_warning " fatal "
12131213 exit 1;
12141214
12151215else
@@ -1219,7 +1219,7 @@ else
12191219 SUBJECT=" [WARNING] - SnapRAID configuration file not found!"
12201220 FORMATTED_CONF=" \` $SNAPRAID_CONF \` "
12211221 NOTIFY_OUTPUT=" $SUBJECT The script cannot be run! Please check your settings, because the specified file $FORMATTED_CONF does not exist."
1222- notify_warning
1222+ notify_warning " fatal "
12231223 exit 1;
12241224fi
12251225}
@@ -1305,7 +1305,7 @@ check_root() {
13051305 mklog " ERROR: Script not run as root. Exiting."
13061306 SUBJECT=" [WARNING] - Script not run as root. Exiting. $EMAIL_SUBJECT_PREFIX "
13071307 NOTIFY_OUTPUT=" $SUBJECT "
1308- notify_warning
1308+ notify_warning " fatal "
13091309 exit 1
13101310 fi
13111311}
0 commit comments