Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-passive-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source
icinga-passive-client
Commits
b84b89a2
Commit
b84b89a2
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
icinga client: generate json with "jo"
parent
f8f29f2c
No related branches found
No related tags found
1 merge request
!29
icinga client: generate json with "jo"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
icinga-cli.sh
+24
-28
24 additions, 28 deletions
icinga-cli.sh
with
24 additions
and
28 deletions
icinga-cli.sh
+
24
−
28
View file @
b84b89a2
...
@@ -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.1
5
"
_version
=
"0.1
6
"
_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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment