From 1a97fd0d57bc3d7fdb8c63fa2d10c376ce5ca455 Mon Sep 17 00:00:00 2001 From: Gerd Stolz Date: Thu, 15 Oct 2026 14:17:52 +0200 Subject: [PATCH 1/2] Enhance sap_hana_instance_status to use instance user sapctrl tools don't have to be installed, however, the HANA instance user has a sapcontrol binary installed, try to use that first before trying the global absolut path which might not exist. --- agents/plugins/mk_sap_hana | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/agents/plugins/mk_sap_hana b/agents/plugins/mk_sap_hana index 59ba32072361..ad676d2db2b7 100755 --- a/agents/plugins/mk_sap_hana +++ b/agents/plugins/mk_sap_hana @@ -430,8 +430,19 @@ sap_hana_check_alerts() { sap_hana_instance_status() { local instance="$1" - result="$(/usr/sap/hostctrl/exe/sapcontrol -nr "${instance}" -function GetProcessList)" - echo "instanceStatus: $?" + local instance_user="$2" + local result + local rc + + # Prefer sapcontrol from the instance user's PATH if available, otherwise fall back + if [ -n "$instance_user" ] && su - "${instance_user}" -c 'command -v sapcontrol >/dev/null 2>&1'; then + result="$(su - "${instance_user}" -c "sapcontrol -nr \"${instance}\" -function GetProcessList" 2>&1)" + else + result="$(/usr/sap/hostctrl/exe/sapcontrol -nr \"${instance}\" -function GetProcessList 2>&1)" + fi + rc=$? + + echo "instanceStatus: $rc" sed -n '4,$p' <<<"${result}" | sed 's/, /;/g' } @@ -787,7 +798,7 @@ query_instance() { echo "<<>>" echo "$instance_name" - sap_hana_instance_status "$instance" + sap_hana_instance_status "$instance" "$instance_user" echo "<<>>" echo "$instance_name" From 3a024b15351bec9b4a24445bef2f033fb50b745d Mon Sep 17 00:00:00 2001 From: Gerd Stolz Date: Fri, 16 Oct 2026 10:59:16 +0200 Subject: [PATCH 2/2] Fix quoting in sapcontrol command execution Shellcheck SC2086 --- agents/plugins/mk_sap_hana | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/plugins/mk_sap_hana b/agents/plugins/mk_sap_hana index ad676d2db2b7..f52ca9d39928 100755 --- a/agents/plugins/mk_sap_hana +++ b/agents/plugins/mk_sap_hana @@ -438,7 +438,7 @@ sap_hana_instance_status() { if [ -n "$instance_user" ] && su - "${instance_user}" -c 'command -v sapcontrol >/dev/null 2>&1'; then result="$(su - "${instance_user}" -c "sapcontrol -nr \"${instance}\" -function GetProcessList" 2>&1)" else - result="$(/usr/sap/hostctrl/exe/sapcontrol -nr \"${instance}\" -function GetProcessList 2>&1)" + result="$(/usr/sap/hostctrl/exe/sapcontrol -nr \""${instance}\"" -function GetProcessList 2>&1)" fi rc=$?