From bb4b4ab5d56add429e9c8e60869a4cbda1e893b1 Mon Sep 17 00:00:00 2001 From: Tomi Eckert Date: Wed, 24 Sep 2025 18:04:14 +0200 Subject: [PATCH] update monitor, echo errors to stderr --- monitor/monitor.sh | 24 ++++++++++++------------ packages.conf | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/monitor/monitor.sh b/monitor/monitor.sh index f708b0d..6d947e5 100644 --- a/monitor/monitor.sh +++ b/monitor/monitor.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Version: 1.0.4 +# Version: 1.0.5 # ============================================================================= # SAP HANA Monitoring Script # @@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" CONFIG_FILE="${SCRIPT_DIR}/monitor.conf" if [ ! -f "$CONFIG_FILE" ]; then - echo "❌ Error: Configuration file not found at ${CONFIG_FILE}" + echo "❌ Error: Configuration file not found at ${CONFIG_FILE}" >&2 rm -f "$LOCK_FILE" exit 1 fi @@ -41,7 +41,7 @@ send_notification() { # --- HANA Process Status --- echo "⚙️ Checking HANA process status..." if [ ! -x "$SAPCONTROL_PATH" ]; then - echo "❌ Error: sapcontrol not found or not executable at ${SAPCONTROL_PATH}" + echo "❌ Error: sapcontrol not found or not executable at ${SAPCONTROL_PATH}" >&2 send_notification "HANA Monitor Error" "❌ Error: sapcontrol not found or not executable at ${SAPCONTROL_PATH}" exit 1 fi @@ -49,8 +49,8 @@ fi non_green_processes=$("${SAPCONTROL_PATH}" -nr "${HANA_INSTANCE_NR}" -function GetProcessList | tail -n +6 | grep -v 'GREEN') if [ -n "$non_green_processes" ]; then - echo "🚨 Alert: One or more HANA processes are not running!" - echo "$non_green_processes" + echo "🚨 Alert: One or more HANA processes are not running!" >&2 + echo "$non_green_processes" >&2 send_notification "HANA Process Alert" "🚨 Critical: One or more HANA processes are not GREEN. Problem processes: ${non_green_processes}" exit 1 # Exit early as other checks might fail fi @@ -60,13 +60,13 @@ echo "✅ Success! All HANA processes are GREEN." echo "ℹ️ Checking disk usage..." for dir in "${DIRECTORIES_TO_MONITOR[@]}"; do if [ ! -d "$dir" ]; then - echo "⚠️ Warning: Directory '$dir' not found. Skipping." + echo "⚠️ Warning: Directory '$dir' not found. Skipping." >&2 continue fi usage=$(df -h "$dir" | awk 'NR==2 {print $5}' | sed 's/%//') echo " - ${dir} is at ${usage}%" if (( $(echo "$usage > $DISK_USAGE_THRESHOLD" | bc -l) )); then - echo "🚨 Alert: ${dir} usage is at ${usage}% which is above the ${DISK_USAGE_THRESHOLD}% threshold." + echo "🚨 Alert: ${dir} usage is at ${usage}% which is above the ${DISK_USAGE_THRESHOLD}% threshold." >&2 send_notification "HANA Disk Alert" "🚨 Critical: Disk usage for ${dir} is at ${usage}%." fi done @@ -74,13 +74,13 @@ done # --- HANA Log Segment Monitoring --- echo "⚙️ Executing HANA SQL query..." if [ ! -x "$HDBSQL_PATH" ]; then - echo "❌ Error: hdbsql not found or not executable at ${HDBSQL_PATH}" + echo "❌ Error: hdbsql not found or not executable at ${HDBSQL_PATH}" >&2 send_notification "HANA Monitor Error" "❌ Error: hdbsql not found or not executable at ${HDBSQL_PATH}" exit 1 fi readarray -t sql_output < <("$HDBSQL_PATH" -U "$HANA_USER_KEY" -c ";" "$SQL_QUERY" 2>&1) if [ $? -ne 0 ]; then - echo "❌ Failure! The hdbsql command failed. Please check logs." + echo "❌ Failure! The hdbsql command failed. Please check logs." >&2 error_message=$(printf '%s\n' "${sql_output[@]}") send_notification "HANA Monitor Error" "❌ Failure! The hdbsql command failed. Details: ${error_message}" exit 1 @@ -107,19 +107,19 @@ echo "ℹ️ Truncated Segments: ${truncated_segments}" echo "ℹ️ Free Segments: ${free_segments}" if [ $total_segments -eq 0 ]; then - echo "⚠️ Warning: No log segments found. Skipping percentage checks." + echo "⚠️ Warning: No log segments found. Skipping percentage checks." >&2 exit 0 fi truncated_percentage=$((truncated_segments * 100 / total_segments)) if (( $(echo "$truncated_percentage > $TRUNCATED_PERCENTAGE_THRESHOLD" | bc -l) )); then - echo "🚨 Alert: ${truncated_percentage}% of log segments are 'Truncated'." + echo "🚨 Alert: ${truncated_percentage}% of log segments are 'Truncated'." >&2 send_notification "HANA Log Segment Alert" "🚨 Alert: ${truncated_percentage}% of HANA log segments are in 'Truncated' state." fi free_percentage=$((free_segments * 100 / total_segments)) if (( $(echo "$free_percentage < $FREE_PERCENTAGE_THRESHOLD" | bc -l) )); then - echo "🚨 Alert: Only ${free_percentage}% of log segments are 'Free'." + echo "🚨 Alert: Only ${free_percentage}% of log segments are 'Free'." >&2 send_notification "HANA Log Segment Alert" "🚨 Alert: Only ${free_percentage}% of HANA log segments are in 'Free' state." fi diff --git a/packages.conf b/packages.conf index 2b37781..f4e1957 100644 --- a/packages.conf +++ b/packages.conf @@ -9,7 +9,7 @@ declare -A SCRIPT_PACKAGES # The version should match the "# Version: x.x.x" line in the main script file. SCRIPT_PACKAGES["Aurora Suite"]="1.1.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/aurora/aurora.conf" SCRIPT_PACKAGES["Backup Suite"]="1.0.5|https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/backup/backup.conf" -SCRIPT_PACKAGES["Monitor Suite"]="1.0.4|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf" +SCRIPT_PACKAGES["Monitor Suite"]="1.0.5|https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.sh https://git.technopunk.space/tomi/Scripts/raw/branch/main/monitor/monitor.conf" SCRIPT_PACKAGES["Key Manager"]="1.2.1|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hdb_keymanager.sh" SCRIPT_PACKAGES["File Cleaner"]="1.1.0|https://git.technopunk.space/tomi/Scripts/raw/branch/main/clean.sh" SCRIPT_PACKAGES["HANA Tool"]="1.4.2|https://git.technopunk.space/tomi/Scripts/raw/branch/main/hanatool.sh"