Skip to content
Snippets Groups Projects
Commit 9907f6f4 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

reduce output to use as service

parent f58801dd
No related branches found
No related tags found
1 merge request!5reduce output to use as service
...@@ -265,19 +265,19 @@ function icingaHostMustExist(){ ...@@ -265,19 +265,19 @@ function icingaHostMustExist(){
_log "check if the host [${myHost}] exists on Icinga ..." _log "check if the host [${myHost}] exists on Icinga ..."
icingaHost get icingaHost get
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
http.getResponse _echo $( http.getResponse )
if [ "$(http.getStatuscode)" = "000" ]; then if [ "$(http.getStatuscode)" = "000" ]; then
_elog "ERROR: Unable to reach the Icinga node. Stopping script current monitoring actions." _elog "ERROR: Unable to reach the Icinga node. Stopping script current monitoring actions."
exit 1 exit 1
fi fi
_elog "ERROR: host object for ${myHost} is not available on Icinga service (yet) - Status: $(http.getStatuscode)" _elog "ERROR: host object for ${myHost} is not available on Icinga service (yet) - Status: $(http.getStatuscode)"
echo _echo
echo "ABORTING" _echo "ABORTING"
echo _echo
echo "To run checks ..." _echo "To run checks ..."
echo "- you must create the host on director (check director-cli.sh --hr)" _echo "- you must create the host on director (check director-cli.sh --hr)"
echo "- the director must deploy the host to icinga daemon" _echo "- the director must deploy the host to icinga daemon"
echo _echo
rm -f "${dir_data}"/service__check* 2>/dev/null rm -f "${dir_data}"/service__check* 2>/dev/null
exit 1 exit 1
fi fi
...@@ -354,10 +354,10 @@ function processCheck(){ ...@@ -354,10 +354,10 @@ function processCheck(){
typeset -i local iTsEnd=`date +%s` typeset -i local iTsEnd=`date +%s`
# outPerfdata=`grep '|' $_outfile | cut -f 2 -d '|'` # outPerfdata=`grep '|' $_outfile | cut -f 2 -d '|'`
outPerfdata=`grep '|' $_outfile | rev | cut -f 1 -d '|' | rev` outPerfdata=`grep '|' $_outfile | rev | cut -f 1 -d '|' | rev`
echo _echo
echo -------- check output: _echo -------- check output:
cat $_outfile _echo $( cat $_outfile )
echo _echo
# echo -------- extracted performance data: # echo -------- extracted performance data:
# echo $outPerfdata # echo $outPerfdata
# echo # echo
...@@ -371,7 +371,7 @@ function processCheck(){ ...@@ -371,7 +371,7 @@ function processCheck(){
export CFGSTORAGE="${checkName}output" export CFGSTORAGE="${checkName}output"
outputAsText="$(cat $_outfile)" 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')" commandAsJson="$(jq -nR --arg data """${myFullscript} $myparams""" '$data')"
( (
$ch --set check_source \"${myHost}\" $ch --set check_source \"${myHost}\"
...@@ -390,7 +390,7 @@ function processCheck(){ ...@@ -390,7 +390,7 @@ function processCheck(){
slot="`_getName4Svcathost ${checkName} | sed 's# #%20#g'`" slot="`_getName4Svcathost ${checkName} | sed 's# #%20#g'`"
_log "${_logPrefix} starting POST of data to monitoring server" _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" _APIcall POST actions/process-check-result?service=${myHost}!${slot} "$data"
http.responseExport "$_response" http.responseExport "$_response"
if [ ! -w "$_response" ]; then if [ ! -w "$_response" ]; then
...@@ -408,9 +408,9 @@ function processCheck(){ ...@@ -408,9 +408,9 @@ function processCheck(){
else else
_log "${_logPrefix} WARNING: the check response was NOT sent to Icinga" _log "${_logPrefix} WARNING: the check response was NOT sent to Icinga"
_rc=$_rc+1 _rc=$_rc+1
echo _echo
echo For Debugging: _echo For Debugging:
$ch --show --json _echo "$( $ch --show --json )"
fi fi
$ch --flush 2>/dev/null $ch --flush 2>/dev/null
...@@ -427,7 +427,7 @@ function processCheck(){ ...@@ -427,7 +427,7 @@ function processCheck(){
typeset -i local iCheckTime=$iCheckEnd-$iCheckStart typeset -i local iCheckTime=$iCheckEnd-$iCheckStart
_log "${_logPrefix} finished after $iCheckTime sec with returncode $_rc" _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 # help
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# #
# ====================================================================== # ======================================================================
isInteractiveShell=false
test -n "$PS1" && isInteractiveShell=true
# .................................................................. # ..................................................................
# write debug output to STDERR # write debug output to STDERR
...@@ -47,6 +49,12 @@ ...@@ -47,6 +49,12 @@
_log "$*" _log "$*"
} }
# echo if there is an interactive shell
# params string(s) message to log
function _echo(){
test $isInteractiveShell && echo $*
}
# ====================================================================== # ======================================================================
# #
# DATE AND TIME FUNCTIONS # DATE AND TIME FUNCTIONS
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment