mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 03:20:12 -08:00
feat: Enhance backup notification system with formatted file lists and improved message handling
This commit is contained in:
@@ -202,12 +202,12 @@ send_notification() {
|
|||||||
[ "$status" == "error" ] && tags="${tags},errors"
|
[ "$status" == "error" ] && tags="${tags},errors"
|
||||||
[ "$status" == "warning" ] && tags="${tags},warnings"
|
[ "$status" == "warning" ] && tags="${tags},warnings"
|
||||||
|
|
||||||
# Enhanced message with additional context
|
# Clean message without newlines or timestamps for webhook
|
||||||
local enhanced_message="$message\n\nHost: $hostname\nTimestamp: $(date '+%Y-%m-%d %H:%M:%S')"
|
local webhook_message="$message"
|
||||||
|
|
||||||
curl -s \
|
curl -s \
|
||||||
-H "tags:${tags}" \
|
-H "tags:${tags}" \
|
||||||
-d "$enhanced_message" \
|
-d "$webhook_message" \
|
||||||
"$WEBHOOK_URL" 2>/dev/null || log_warning "Failed to send webhook notification"
|
"$WEBHOOK_URL" 2>/dev/null || log_warning "Failed to send webhook notification"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -227,6 +227,25 @@ send_notification() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Format backed up files list for notifications
|
||||||
|
format_backed_up_files() {
|
||||||
|
local files=("$@")
|
||||||
|
local count=${#files[@]}
|
||||||
|
|
||||||
|
if [ $count -eq 0 ]; then
|
||||||
|
echo "no files"
|
||||||
|
elif [ $count -eq 1 ]; then
|
||||||
|
echo "${files[0]}"
|
||||||
|
elif [ $count -eq 2 ]; then
|
||||||
|
echo "${files[0]} and ${files[1]}"
|
||||||
|
else
|
||||||
|
local last_file="${files[-1]}"
|
||||||
|
local other_files=("${files[@]:0:$((count-1))}")
|
||||||
|
local other_files_str=$(IFS=', '; echo "${other_files[*]}")
|
||||||
|
echo "${other_files_str}, and ${last_file}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Enhanced checksum calculation with caching
|
# Enhanced checksum calculation with caching
|
||||||
calculate_checksum() {
|
calculate_checksum() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
@@ -900,6 +919,7 @@ main() {
|
|||||||
|
|
||||||
local backup_errors=0
|
local backup_errors=0
|
||||||
local files_backed_up=0
|
local files_backed_up=0
|
||||||
|
local backed_up_files=() # Array to track successfully backed up files
|
||||||
local BACKUP_PATH="${BACKUP_ROOT}"
|
local BACKUP_PATH="${BACKUP_ROOT}"
|
||||||
|
|
||||||
# Ensure backup root directory exists
|
# Ensure backup root directory exists
|
||||||
@@ -970,6 +990,13 @@ main() {
|
|||||||
if verify_backup "$file" "$backup_file"; then
|
if verify_backup "$file" "$backup_file"; then
|
||||||
log_success "Verified: $(basename "$file")"
|
log_success "Verified: $(basename "$file")"
|
||||||
files_backed_up=$((files_backed_up + 1))
|
files_backed_up=$((files_backed_up + 1))
|
||||||
|
# Add friendly filename to backed up files list
|
||||||
|
case "$(basename "$file")" in
|
||||||
|
"com.plexapp.plugins.library.db") backed_up_files+=("library.db") ;;
|
||||||
|
"com.plexapp.plugins.library.blobs.db") backed_up_files+=("blobs.db") ;;
|
||||||
|
"Preferences.xml") backed_up_files+=("Preferences.xml") ;;
|
||||||
|
*) backed_up_files+=("$(basename "$file")") ;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
log_error "Verification failed: $(basename "$file")"
|
log_error "Verification failed: $(basename "$file")"
|
||||||
backup_errors=$((backup_errors + 1))
|
backup_errors=$((backup_errors + 1))
|
||||||
@@ -1118,7 +1145,8 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Send notification
|
# Send notification
|
||||||
send_notification "Backup Completed" "Successfully backed up $files_backed_up files" "success"
|
local files_list=$(format_backed_up_files "${backed_up_files[@]}")
|
||||||
|
send_notification "Backup Completed" "Successfully backed up $files_list" "success"
|
||||||
else
|
else
|
||||||
log_message "No files needed backup"
|
log_message "No files needed backup"
|
||||||
fi
|
fi
|
||||||
@@ -1148,7 +1176,8 @@ main() {
|
|||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
log_success "Enhanced backup completed successfully"
|
log_success "Enhanced backup completed successfully"
|
||||||
send_notification "Backup Success" "All $files_backed_up files backed up successfully in ${total_time}s" "success"
|
local files_list=$(format_backed_up_files "${backed_up_files[@]}")
|
||||||
|
send_notification "Backup Success" "$files_list backed up successfully in ${total_time}s" "success"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user