- Remove consecutive breach tracking for statement queue (immediate alerts) - Consolidate script initialization into init_script() function - Remove unused helper functions (send_ok, run_as_hana_user, get_mount_point) - Flatten sld_watchdog.sh structure by removing main() wrapper - Remove state directory and lock directory configuration from hana.conf - Simplify alert messages to include threshold values This continues the simplification effort from previous commits by removing stateful tracking mechanisms and streamlining the monitoring logic for easier maintenance.
65 lines
2.0 KiB
Bash
65 lines
2.0 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# SAP HANA Disk Space Monitoring Script
|
|
# Checks disk usage for configured directories
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
|
SCRIPT_NAME="hana_disk"
|
|
|
|
# Load configuration
|
|
source "${SCRIPT_DIR}/hana.conf"
|
|
source "${SCRIPT_DIR}/hana_lib.sh"
|
|
|
|
# Acquire lock
|
|
if ! acquire_lock "$SCRIPT_NAME"; then
|
|
exit 1
|
|
fi
|
|
trap 'release_lock "$SCRIPT_NAME"' EXIT
|
|
|
|
log_message "$SCRIPT_NAME" "Starting disk usage check..."
|
|
|
|
# Track overall status
|
|
ALERT_COUNT=0
|
|
TOTAL_DIRS=0
|
|
|
|
for dir in "${DIRECTORIES_TO_MONITOR[@]}"; do
|
|
TOTAL_DIRS=$((TOTAL_DIRS + 1))
|
|
|
|
# Check if directory exists
|
|
if [ ! -d "$dir" ]; then
|
|
log_message "$SCRIPT_NAME" "WARNING: Directory '$dir' not found. Skipping."
|
|
send_alert "$SCRIPT_NAME" "HANA Disk Warning" "Directory '$dir' not found."
|
|
ALERT_COUNT=$((ALERT_COUNT + 1))
|
|
continue
|
|
fi
|
|
|
|
# Get disk usage percentage
|
|
usage=$(get_disk_usage_percentage "$dir")
|
|
|
|
if [ -z "$usage" ] || [ "$usage" -eq 0 ]; then
|
|
log_message "$SCRIPT_NAME" "WARNING: Could not determine disk usage for '$dir'. Skipping."
|
|
continue
|
|
fi
|
|
|
|
log_message "$SCRIPT_NAME" "Directory ${dir} is at ${usage}%"
|
|
|
|
# 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."
|
|
send_alert "$SCRIPT_NAME" "HANA Disk" "Disk usage for ${dir} is at ${usage}% (threshold: ${DISK_USAGE_THRESHOLD}%)."
|
|
ALERT_COUNT=$((ALERT_COUNT + 1))
|
|
else
|
|
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."
|
|
|
|
# Exit with status based on alerts
|
|
if [ "$ALERT_COUNT" -gt 0 ]; then
|
|
exit 1
|
|
fi
|
|
exit 0
|