diff --git a/icinga-cli.sh b/icinga-cli.sh index ffeed7d75bc4164244e3920a79ecb49854f1cd1e..bd65875a8abc8f410318096193f0fcd651a894b4 100755 --- a/icinga-cli.sh +++ b/icinga-cli.sh @@ -265,19 +265,19 @@ function icingaHostMustExist(){ _log "check if the host [${myHost}] exists on Icinga ..." icingaHost get if [ $? -ne 0 ]; then - http.getResponse + _echo $( http.getResponse ) if [ "$(http.getStatuscode)" = "000" ]; then _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)" - echo - echo "ABORTING" - echo - echo "To run checks ..." - echo "- you must create the host on director (check director-cli.sh --hr)" - echo "- the director must deploy the host to icinga daemon" - echo + _echo + _echo "ABORTING" + _echo + _echo "To run checks ..." + _echo "- you must create the host on director (check director-cli.sh --hr)" + _echo "- the director must deploy the host to icinga daemon" + _echo rm -f "${dir_data}"/service__check* 2>/dev/null exit 1 fi @@ -354,10 +354,10 @@ function processCheck(){ typeset -i local iTsEnd=`date +%s` # outPerfdata=`grep '|' $_outfile | cut -f 2 -d '|'` outPerfdata=`grep '|' $_outfile | rev | cut -f 1 -d '|' | rev` - echo - echo -------- check output: - cat $_outfile - echo + _echo + _echo -------- check output: + _echo $( cat $_outfile ) + _echo # echo -------- extracted performance data: # echo $outPerfdata # echo @@ -371,7 +371,7 @@ function processCheck(){ export CFGSTORAGE="${checkName}output" outputAsText="$(cat $_outfile)" - outputAsJson="$(jq -nR --arg data """${outputAsText}""" '$data')" + # outputAsJson="$(jq -nR --arg data """${outputAsText}""" '$data')" commandAsJson="$(jq -nR --arg data """${myFullscript} $myparams""" '$data')" ( $ch --set check_source \"${myHost}\" @@ -390,7 +390,7 @@ 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" + _echo POST actions/process-check-result?service=${myHost}!${slot} "$data" _APIcall POST actions/process-check-result?service=${myHost}!${slot} "$data" http.responseExport "$_response" if [ ! -w "$_response" ]; then @@ -408,9 +408,9 @@ function processCheck(){ else _log "${_logPrefix} WARNING: the check response was NOT sent to Icinga" _rc=$_rc+1 - echo - echo For Debugging: - $ch --show --json + _echo + _echo For Debugging: + _echo "$( $ch --show --json )" fi $ch --flush 2>/dev/null @@ -427,7 +427,7 @@ function processCheck(){ typeset -i local iCheckTime=$iCheckEnd-$iCheckStart _log "${_logPrefix} finished after $iCheckTime sec with returncode $_rc" - test $_rc -eq 0 || (echo; echo " >>> Check ${checkName} was not OK. See Output block above!"; echo; echo) + test $_rc -eq 0 || (_echo; _echo " >>> Check ${checkName} was not OK. See Output block above!"; _echo; _echo) } # ---------------------------------------------------------------------- # help diff --git a/inc_functions.sh b/inc_functions.sh index 2f5609fc8e4d08328a0858f51197f1551dead2e2..2b97b6927e6a86a11e1224cdab7fd1744538706c 100644 --- a/inc_functions.sh +++ b/inc_functions.sh @@ -5,6 +5,8 @@ # # ====================================================================== + isInteractiveShell=false + test -n "$PS1" && isInteractiveShell=true # .................................................................. # write debug output to STDERR @@ -47,6 +49,12 @@ _log "$*" } + # echo if there is an interactive shell + # params string(s) message to log + function _echo(){ + test $isInteractiveShell && echo $* + } + # ====================================================================== # # DATE AND TIME FUNCTIONS