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

Merge branch 'update-confighandler' into 'master'

icinga client: generate json with "jo"

See merge request !29
parents efef426c b84b89a2
No related branches found
No related tags found
1 merge request!29icinga client: generate json with "jo"
......@@ -20,16 +20,20 @@
# 2023-02-13 v0.13 ah rename myHost to MY_NAME (like in director_cli)
# 2023-02-17 v0.14 ah add hostnamme into CFGSTORAGE
# 2023-02-17 v0.15 ah check inc_getconfig.sh exists and hostname -f has a value
# 2023-11-01 v0.16 ah generate json with "jo"
# ======================================================================
_product="ICINGA PASSIVE CLIENT"
_version="0.15"
_version="0.16"
_license="GNU GPL 3.0"
_copyright='(c) Institute for Medical Education * University of Bern'
typeset -i debug=0
which curl >/dev/null || exit 1
which jo >/dev/null || exit 1
# source config ...
_cfg="$( dirname $0 )/inc_getconfig.sh"
if [ ! -f "$_cfg" ]; then
......@@ -38,15 +42,8 @@ if [ ! -f "$_cfg" ]; then
fi
. "$_cfg"
# where to find check scripts ... first directory wins
# dir_plugins="/opt/imlmonitor/client/plugins/ /usr/lib64/nagios/plugins"
# dir_cfg="/etc/icinga2-passive-client"
# dir_data="/var/tmp/icinga2-passive-client"
# dir_logs="/var/log/icinga2-passive-client"
logfile="${dir_logs}/execution.log"
ch="$( dirname $0 )/inc/confighandler.sh"
MY_NAME=$(hostname -f)
if [ -z "$MY_NAME" ]; then
echo "ERROR: hostname is empty. Ensure that the command 'hostname -f' returns a fqdn."
......@@ -397,24 +394,24 @@ function processCheck(){
# --- send check result to Icinga
# fields of the object
# https://icinga.com/docs/icinga2/latest/doc/12-icinga2-api/#process-check-result
export CFGSTORAGE="${MY_NAME}-${checkName}output"
outputAsText="$(cat $_outfile)"
# outputAsJson="$(jq -nR --arg data """${outputAsText}""" '$data')"
commandAsJson="$(jq -nR --arg data """${myFullscript} $myparams""" '$data')"
(
$ch --set check_source \"${MY_NAME}\"
$ch --set check_command "${commandAsJson}"
$ch --set exit_status $rc
# $ch --set plugin_output "${outputAsJson}"
$ch --setfile plugin_output "${_outfile}"
$ch --set performance_data "\"${outPerfdata}\""
$ch --set ttl $checkInterval
$ch --set execution_start $iTsStart
$ch --set execution_end $iTsEnd
) 2>/dev/null
# $ch --json
data=`$ch --json 2>/dev/null`
local JSONPARAMS="
check_source=${MY_NAME}
check_command=${commandAsJson}
exit_status=$rc
ttl=$checkInterval
execution_start=$iTsStart
execution_end=$iTsEnd
performance_data="\"${outPerfdata}\""
plugin_output="\"$( cat "${_outfile}" )\""
"
data=$( eval jo -p -d. $JSONPARAMS )
slot="`_getName4Svcathost ${checkName} | sed 's# #%20#g'`"
......@@ -435,14 +432,13 @@ function processCheck(){
if [ $? -eq 0 ]; then
_log "${_logPrefix} rc=$rc - OK, response was sent to Icinga"
else
_elog "${_logPrefix} rc=$rc - WARNING: the check response was NOT sent to Icinga"
_elog "${_logPrefix} rc=$rc - WARNING: $(http.getStatuscode) the check response was NOT sent to Icinga"
_rc=$_rc+1
_echo
_echo For Debugging:
_echo "$( $ch --show --json )"
_log "$( $ch --show --json )"
_echo "$data"
_log "$data"
fi
$ch --flush 2>/dev/null
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment