refactor(monitoring): simplify notification system and remove auto-cleanup

- Replace state-based notifications with direct alert functions
- Remove auto-cleanup functionality from disk monitoring and configuration
- Simplify lock acquisition/release across all monitoring scripts
- Add execute_hana_sql helper functions for consistent SQL execution
- Remove state file tracking in favor of direct file operations
- Standardize error handling with exit codes on critical failures
- Clean up hana.conf by removing unused auto-delete directory settings
This commit is contained in:
2026-03-12 21:52:49 +01:00
parent 5a92bc4e93
commit cf5b81889d
8 changed files with 183 additions and 391 deletions

View File

@@ -12,18 +12,16 @@ source "${SCRIPT_DIR}/hana.conf"
source "${SCRIPT_DIR}/hana_lib.sh"
# Acquire lock
LOCK_FILE=$(acquire_lock "$SCRIPT_NAME")
if [ $? -ne 0 ]; then
if ! acquire_lock "$SCRIPT_NAME"; then
exit 1
fi
trap 'release_lock "$LOCK_FILE"' EXIT
trap 'release_lock "$SCRIPT_NAME"' EXIT
log_message "$SCRIPT_NAME" "Starting disk usage check..."
# Track overall status
ALERT_COUNT=0
TOTAL_DIRS=0
CLEANUP_PERFORMED=0
for dir in "${DIRECTORIES_TO_MONITOR[@]}"; do
TOTAL_DIRS=$((TOTAL_DIRS + 1))
@@ -31,7 +29,7 @@ for dir in "${DIRECTORIES_TO_MONITOR[@]}"; do
# Check if directory exists
if [ ! -d "$dir" ]; then
log_message "$SCRIPT_NAME" "WARNING: Directory '$dir' not found. Skipping."
send_notification_if_changed "$SCRIPT_NAME" "disk_dir_not_found_${dir//\//_}" "HANA Disk Warning" "Directory '$dir' not found." "true" "DIR_NOT_FOUND"
send_alert "$SCRIPT_NAME" "HANA Disk Warning" "Directory '$dir' not found."
ALERT_COUNT=$((ALERT_COUNT + 1))
continue
fi
@@ -49,33 +47,15 @@ for dir in "${DIRECTORIES_TO_MONITOR[@]}"; do
# Check if usage exceeds threshold
if [ "$usage" -gt "$DISK_USAGE_THRESHOLD" ]; then
log_message "$SCRIPT_NAME" "ALERT: ${dir} usage is at ${usage}% which is above the ${DISK_USAGE_THRESHOLD}% threshold."
# Attempt auto-cleanup if enabled
if [ "$AUTO_CLEANUP_ENABLED" == "true" ]; then
log_message "$SCRIPT_NAME" "Attempting auto-cleanup for '${dir}'..."
mount_point=$(get_mount_point "$dir")
if auto_cleanup "$mount_point" "$MIN_FREE_SPACE_AFTER_CLEANUP"; then
CLEANUP_PERFORMED=$((CLEANUP_PERFORMED + 1))
new_usage=$(get_disk_usage_percentage "$dir")
log_message "$SCRIPT_NAME" "After cleanup, ${dir} usage is at ${new_usage}%"
usage=$new_usage
else
log_message "$SCRIPT_NAME" "Auto-cleanup failed or no files to clean for '${dir}'"
fi
fi
# Send notification with final usage after cleanup attempt
send_notification_if_changed "$SCRIPT_NAME" "disk_usage_${dir//\//_}" "HANA Disk" "Disk usage for ${dir} is at ${usage}%." "true" "${usage}%"
send_alert "$SCRIPT_NAME" "HANA Disk" "Disk usage for ${dir} is at ${usage}% (threshold: ${DISK_USAGE_THRESHOLD}%)."
ALERT_COUNT=$((ALERT_COUNT + 1))
else
# Send OK notification only if state changed from alert
send_notification_if_changed "$SCRIPT_NAME" "disk_usage_${dir//\//_}" "HANA Disk" "Disk usage for ${dir} is at ${usage}% (below threshold)." "false" "OK"
log_message "$SCRIPT_NAME" "OK: ${dir} usage is at ${usage}% (below threshold)."
fi
done
# Summary logging
log_message "$SCRIPT_NAME" "Disk check complete. Total: ${TOTAL_DIRS} dirs, ${ALERT_COUNT} alerts, ${CLEANUP_PERFORMED} cleanups performed."
log_message "$SCRIPT_NAME" "Disk check complete. Total: ${TOTAL_DIRS} dirs, ${ALERT_COUNT} alerts."
# Exit with status based on alerts
if [ "$ALERT_COUNT" -gt 0 ]; then