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

icinga client: generate json with "jo"

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