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:
@@ -12,53 +12,47 @@ 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 HANA process status check..."
|
||||
|
||||
# Check if sapcontrol is available
|
||||
if [ ! -x "$SAPCONTROL_PATH" ]; then
|
||||
log_message "$SCRIPT_NAME" "ERROR: sapcontrol not found or not executable at ${SAPCONTROL_PATH}"
|
||||
send_notification_if_changed "$SCRIPT_NAME" "hana_sapcontrol_path" "HANA Monitor Error" "sapcontrol not found or not executable at ${SAPCONTROL_PATH}" "true" "SAPCONTROL_ERROR"
|
||||
send_alert "$SCRIPT_NAME" "HANA Monitor Error" "sapcontrol not found or not executable at ${SAPCONTROL_PATH}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get process list with improved error handling
|
||||
# Get process list
|
||||
process_list=$(su - "$HANA_USER" -c "${SAPCONTROL_PATH} -nr ${HANA_INSTANCE_NR} -function GetProcessList" 2>&1)
|
||||
sapcontrol_status=$?
|
||||
|
||||
if [ $sapcontrol_status -ne 0 ]; then
|
||||
log_message "$SCRIPT_NAME" "ERROR: sapcontrol command failed with exit code ${sapcontrol_status}"
|
||||
send_notification_if_changed "$SCRIPT_NAME" "hana_sapcontrol_command" "HANA Monitor Error" "sapcontrol command failed. Exit code: ${sapcontrol_status}" "true" "SAPCONTROL_COMMAND_FAILED"
|
||||
send_alert "$SCRIPT_NAME" "HANA Monitor Error" "sapcontrol command failed. Exit code: ${sapcontrol_status}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clear any previous sapcontrol error state
|
||||
send_notification_if_changed "$SCRIPT_NAME" "hana_sapcontrol_command" "HANA Process" "sapcontrol command successful." "false" "OK"
|
||||
|
||||
# Check for non-GREEN processes (skip header lines)
|
||||
non_green_processes=$(echo "$process_list" | tail -n +6 | grep -v 'GREEN' | grep -v '^$')
|
||||
|
||||
if [ -n "$non_green_processes" ]; then
|
||||
log_message "$SCRIPT_NAME" "ALERT: One or more HANA processes are not running!"
|
||||
log_message "$SCRIPT_NAME" "Problem processes: ${non_green_processes}"
|
||||
send_notification_if_changed "$SCRIPT_NAME" "hana_processes" "HANA Process" "One or more HANA processes are not GREEN. Problem processes: ${non_green_processes}" "true" "PROCESS_ALERT:${non_green_processes}"
|
||||
send_alert "$SCRIPT_NAME" "HANA Process" "One or more HANA processes are not GREEN. Problem processes: ${non_green_processes}"
|
||||
exit 1
|
||||
else
|
||||
# Verify we actually got process data
|
||||
green_processes=$(echo "$process_list" | tail -n +6 | grep 'GREEN')
|
||||
if [ -z "$green_processes" ]; then
|
||||
log_message "$SCRIPT_NAME" "WARNING: No process data found. SAP HANA may not be running."
|
||||
send_notification_if_changed "$SCRIPT_NAME" "hana_processes" "HANA Process" "No process data found. SAP HANA may not be running." "true" "NO_PROCESS_DATA"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
send_notification_if_changed "$SCRIPT_NAME" "hana_processes" "HANA Process" "All HANA processes are GREEN." "false" "OK"
|
||||
log_message "$SCRIPT_NAME" "SUCCESS: All HANA processes are GREEN."
|
||||
fi
|
||||
|
||||
# Verify we actually got process data
|
||||
green_processes=$(echo "$process_list" | tail -n +6 | grep 'GREEN')
|
||||
if [ -z "$green_processes" ]; then
|
||||
log_message "$SCRIPT_NAME" "WARNING: No process data found. SAP HANA may not be running."
|
||||
send_alert "$SCRIPT_NAME" "HANA Process" "No process data found. SAP HANA may not be running."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_message "$SCRIPT_NAME" "SUCCESS: All HANA processes are GREEN."
|
||||
log_message "$SCRIPT_NAME" "Process check complete."
|
||||
|
||||
Reference in New Issue
Block a user