- 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
59 lines
2.3 KiB
Bash
59 lines
2.3 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# SAP HANA Process Monitoring Script
|
|
# Checks if all HANA processes are in GREEN state
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
|
SCRIPT_NAME="hana_processes"
|
|
|
|
# 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 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_alert "$SCRIPT_NAME" "HANA Monitor Error" "sapcontrol not found or not executable at ${SAPCONTROL_PATH}"
|
|
exit 1
|
|
fi
|
|
|
|
# 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_alert "$SCRIPT_NAME" "HANA Monitor Error" "sapcontrol command failed. Exit code: ${sapcontrol_status}"
|
|
exit 1
|
|
fi
|
|
|
|
# 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_alert "$SCRIPT_NAME" "HANA Process" "One or more HANA processes are not GREEN. Problem processes: ${non_green_processes}"
|
|
exit 1
|
|
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."
|