From 7b067b740a543b77926bc48a7c558347cef9cced Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Mon, 13 Feb 2023 10:13:13 +0100
Subject: [PATCH] custom params per server

---
 director-cli.sh  |  3 ---
 icinga-cli.sh    | 29 +++++++++++++++--------------
 inc_functions.sh |  3 ++-
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/director-cli.sh b/director-cli.sh
index db6a855..2858ebe 100755
--- a/director-cli.sh
+++ b/director-cli.sh
@@ -62,9 +62,6 @@ typeset cfg_dryrun=false
       MY_IP=$(_getIpFrontend | head -1)
       MY_ZONE=
     fi
-    IDC_host__cachefile="${dir_data}/${MY_NAME}__host_at-director.txt"
-    IDC_service__cachefile="${dir_data}/${MY_NAME}__all_defined_services__at-director.txt"
-    IDC_svcathost__cachefile="${dir_data}/${MY_NAME}__services_on_host__at-director.txt"
     # ch="`dirname $0`/inc/confighandler.sh"
     ch="./inc/confighandler.sh"
   }
diff --git a/icinga-cli.sh b/icinga-cli.sh
index 5c6695f..9681d13 100755
--- a/icinga-cli.sh
+++ b/icinga-cli.sh
@@ -17,6 +17,7 @@
 # 2022-03-14  v0.10  ah  less output and add _elog to run as a service
 # 2022-07-08  v0.11  ah  check pipes in output and performance data
 # 2023-01-30  v0.12  ah  remove pipes with sed remove the pipe before performancedata
+# 2023-02-13  v0.13  ah  rename myHost to MY_NAME (like in director_cli)
 # ======================================================================
 
 
@@ -40,7 +41,7 @@ typeset -i debug=0
 logfile="${dir_logs}/execution.log"
 
 ch="$( dirname $0 )/inc/confighandler.sh"
-myHost=$(hostname -f)
+MY_NAME=$(hostname -f)
 
 # for loop mode only: max. random sleep time
 typeset -i sleeptime=30
@@ -95,10 +96,10 @@ function _getFileSnapshot(){
 function loopChecks(){
 
       # TODO-MEMORY-CHECK
-      # echo ${myHost} | egrep "^(kvm4|icinga)"
-      # echo ${myHost} | egrep "^(monitortest)"
+      # echo ${MY_NAME} | egrep "^(kvm4|icinga)"
+      # echo ${MY_NAME} | egrep "^(monitortest)"
       # if [ $? -ne 0 ]; then
-      #   echo "HARD EXIT - DO NOT EXECUTE ANY CHECK ON $myHost"
+      #   echo "HARD EXIT - DO NOT EXECUTE ANY CHECK ON $MY_NAME"
       #   exit 1
       # fi
 
@@ -198,7 +199,7 @@ function processAllChecks(){
 #   checkInterval
 # param  string  full path of a config file
 #
-function _parseCheckConfig(){
+function UNUSED_parseCheckConfig(){
   local _myconfig="$1"
 
   if [ ! -r "$_myconfig" ]; then
@@ -220,9 +221,9 @@ function _parseCheckConfig(){
 # actions for icinga host
 # param  string  action; "get" only
 function icingaHost(){
-  local _logPrefix="${myHost} :: API |"
-  local _apiRequest=objects/hosts/${myHost}
-  local _localCache=${dir_data}/host_${myHost}_deployed-at-icinga.txt
+  local _logPrefix="${MY_NAME} :: API |"
+  local _apiRequest=objects/hosts/${MY_NAME}
+  local _localCache=${dir_data}/host_${MY_NAME}_deployed-at-icinga.txt
   typeset -i local _iRefreshCache=120
 
   local sAction=$1
@@ -260,10 +261,10 @@ function icingaHost(){
 
 # for check on the beginning of the script:
 # execute a check only if the host exists on icinga2
-# global  string  myHost 
+# global  string  MY_NAME 
 # global  string  dir_data
 function icingaHostMustExist(){
-  _log "check if the host [${myHost}] exists on Icinga ..."
+  _log "check if the host [${MY_NAME}] exists on Icinga ..."
   icingaHost get
   if [ $? -ne 0 ]; then
     _echo $( http.getResponse )
@@ -271,7 +272,7 @@ function icingaHostMustExist(){
       _elog "ERROR: Unable to reach the Icinga node. Stopping script current monitoring actions."
       exit 1
     fi
-    _elog "ERROR: host object for ${myHost} is not available on Icinga service (yet) - Status: $(http.getStatuscode)"
+    _elog "ERROR: host object for ${MY_NAME} is not available on Icinga service (yet) - Status: $(http.getStatuscode)"
     _echo
     _echo "ABORTING"
     _echo
@@ -392,7 +393,7 @@ function processCheck(){
       # outputAsJson="$(jq -nR --arg data """${outputAsText}""" '$data')"
       commandAsJson="$(jq -nR --arg data """${myFullscript} $myparams""" '$data')"
       (
-        $ch --set      check_source      \"${myHost}\"
+        $ch --set      check_source      \"${MY_NAME}\"
         $ch --set      check_command     "${commandAsJson}"
         $ch --set      exit_status       $rc
         # $ch --set      plugin_output     "${outputAsJson}"
@@ -408,8 +409,8 @@ function processCheck(){
       slot="`_getName4Svcathost ${checkName} | sed 's# #%20#g'`"
 
       _log "${_logPrefix} starting POST of data to monitoring server"
-      _echo POST actions/process-check-result?service=${myHost}!${slot} "$data"
-      _APIcall POST actions/process-check-result?service=${myHost}!${slot} "$data"
+      _echo POST actions/process-check-result?service=${MY_NAME}!${slot} "$data"
+      _APIcall POST actions/process-check-result?service=${MY_NAME}!${slot} "$data"
       http.responseExport "$_response"
       if [ ! -w "$_response" ]; then
             _elog "${_logPrefix} ERROR: responsefile $_response is not writable."
diff --git a/inc_functions.sh b/inc_functions.sh
index e61265e..93e2482 100644
--- a/inc_functions.sh
+++ b/inc_functions.sh
@@ -111,7 +111,8 @@
     # max_check_attempts=3
 
     checkName=$(cat "$_myconfig" | grep ^checkname= | cut -f 2 -d "=" | sed 's# #_#g')
-    checkCommand=$(cat "$_myconfig" | grep ^command= | cut -f 2 -d "=")
+    checkCommand=$(cat "$_myconfig" | grep ^command_$MY_NAME= | cut -f 2 -d "=")
+    test -z "$checkCommand" && checkCommand=$(cat "$_myconfig" | grep ^command= | cut -f 2 -d "=")
     checkInterval=$(cat "$_myconfig" | grep ^interval= | cut -f 2 -d "=")
     checkIcon=$(cat "$_myconfig" | grep ^icon= | cut -f 2 -d "=")
     checkMaxAttempts=$(cat "$_myconfig" | grep ^max_check_attempts= | cut -f 2 -d "=")
-- 
GitLab