update monitor, echo errors to stderr
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user