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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source
icinga-passive-client
Commits
3e934951
Commit
3e934951
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
WIP: less output and add _elog to run as a service
parent
7144be7c
No related branches found
No related tags found
1 merge request
!4
abort on http 5xx error
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
icinga-cli.sh
+22
-28
22 additions, 28 deletions
icinga-cli.sh
inc_functions.sh
+10
-3
10 additions, 3 deletions
inc_functions.sh
with
32 additions
and
31 deletions
icinga-cli.sh
+
22
−
28
View file @
3e934951
...
...
@@ -14,6 +14,7 @@
# 2022-01-11 v0.7 ah shellcheck
# 2022-02-16 v0.8 ah add --cfg param
# 2022-03-04 v0.9 ah abort on http 5xx error
# 2022-03-14 v0.10 ah less output and add _elog to run as a service
# ======================================================================
...
...
@@ -110,10 +111,8 @@ function loopChecks(){
lockpid
=
$(
cat
"
${
lockfile
}
"
|
cut
-f
2
-d
"-"
|
cut
-f
4
-d
" "
|
grep
"[0-9]"
)
ps
-f
--pid
"
$lockpid
"
|
grep
"
$(
basename
$0
)
"
|
grep
loop
>
/dev/null
if
[
$?
-eq
0
]
;
then
_log
"ABORT: Loop seems to run already. See process with PID
$lockpid
"
echo
ps
-f
--pid
"
$lockpid
"
echo
_elog
"ABORT: Loop seems to run already. See process with PID
$lockpid
"
_elog
$(
ps
-f
--pid
"
$lockpid
"
)
exit
0
fi
fi
...
...
@@ -121,15 +120,15 @@ function loopChecks(){
_log
"---------- starting in a permanent loop"
echo
"Serviceloop started
$(
date
)
- process id
$$
"
>
"
${
lockfile
}
"
if
[
$?
-ne
0
]
;
then
_log
"ABORT: Lock file is not writable
${
lockfile
}
."
ls
-l
"
${
lockfile
}
"
_
e
log
"ABORT: Lock file is not writable
${
lockfile
}
."
_elog
$(
ls
-l
"
${
lockfile
}
"
)
;
exit
1
fi
_getFileSnapshot>
"
${
snapShotStart
}
"
if
[
$?
-ne
0
]
;
then
_log
"ABORT: Snapshot file is not writable
${
snapShotStart
}
."
ls
-l
"
${
snapShotStart
}
"
_
e
log
"ABORT: Snapshot file is not writable
${
snapShotStart
}
."
_elog
$(
ls
-l
"
${
snapShotStart
}
"
)
exit
1
fi
while
true
;
do
...
...
@@ -142,19 +141,17 @@ function loopChecks(){
_log
""
_getFileSnapshot>
$snapShotCurrent
if
[
$?
-ne
0
]
;
then
_log
"ABORT: Snapshot file is not writable
${
snapShotCurrent
}
."
ls
-l
"
${
snapShotCurrent
}
"
_
e
log
"ABORT: Snapshot file is not writable
${
snapShotCurrent
}
."
_elog
$(
ls
-l
"
${
snapShotCurrent
}
"
)
exit
1
fi
diff
$snapShotStart
$snapShotCurrent
>
/dev/null
if
[
$?
-ne
0
]
;
then
_log
"ABORT: Files were updated / overwritten. The loop must be restarted.
\n
`
diff
$snapShotStart
$snapShotCurrent
`
"
_
e
log
"ABORT: Files were updated / overwritten. The loop must be restarted.
\n
`
diff
$snapShotStart
$snapShotCurrent
`
"
exit
1
fi
icingaHostMustExist
processAllChecks
echo
echo
done
}
# ......................................................................
...
...
@@ -176,16 +173,13 @@ function processAllChecks(){
_log
""
_log
"------ looping over all checks"
getChecks
echo
for
myconfig
in
$(
getChecks
)
do
iCounter
=
$iCounter
+1
_log
"--- processing [
$iCounter
of
$iChecksTotal
]
$myconfig
"
processCheck
"
$myconfig
"
_log
""
echo
echo
----------------------------------------------------------------------
echo
done
typeset
-i
local
iLoopEnd
iLoopEnd
=
$(
_getUnixTs
)
...
...
@@ -207,7 +201,7 @@ function _parseCheckConfig(){
local
_myconfig
=
"
$1
"
if
[
!
-r
"
$_myconfig
"
]
;
then
echo
"ERROR: config file is not readable [
$_myconfig
]"
_elog
"ERROR: config file is not readable [
$_myconfig
]"
exit
1
fi
...
...
@@ -250,7 +244,7 @@ function icingaHost(){
http.setCacheFile
$_localCache
http.makeRequest GET
$_apiRequest
if
http.isServerError
>
/dev/null
;
then
echo
"CRITICAL ERROR: Icinga2 API request failed with a server error GET
$_apiRequest
"
_elog
"CRITICAL ERROR: Icinga2 API request failed with a server error GET
$_apiRequest
"
exit
1
fi
...
...
@@ -273,10 +267,10 @@ function icingaHostMustExist(){
if
[
$?
-ne
0
]
;
then
http.getResponse
if
[
"
$(
http.getStatuscode
)
"
=
"000"
]
;
then
_log
"ERROR: Unable to reach the Icinga node. Stopping script current monitoring actions."
_
e
log
"ERROR: Unable to reach the Icinga node. Stopping script current monitoring actions."
exit
1
fi
_log
"ERROR: host object for
${
myHost
}
is not available on Icinga service (yet) - Status:
$(
http.getStatuscode
)
"
_
e
log
"ERROR: host object for
${
myHost
}
is not available on Icinga service (yet) - Status:
$(
http.getStatuscode
)
"
echo
echo
"ABORTING"
echo
...
...
@@ -353,8 +347,8 @@ function processCheck(){
eval
$myFullscript
$myparams
>
$_outfile
rc
=
$?
if
[
!
-w
$_outfile
]
;
then
_log
"
${
_logPrefix
}
ERROR: output file
$_outfile
is not writable."
_log
"
${
_logPrefix
}
$(
ls
-ld
${
dir_data
}
$_outfile
)
"
_
e
log
"
${
_logPrefix
}
ERROR: output file
$_outfile
is not writable."
_
e
log
"
${
_logPrefix
}
$(
ls
-ld
${
dir_data
}
$_outfile
)
"
exit
1
fi
typeset
-i
local
iTsEnd
=
`
date
+%s
`
...
...
@@ -400,8 +394,8 @@ function processCheck(){
_APIcall POST actions/process-check-result?service
=
${
myHost
}
!
${
slot
}
"
$data
"
http.responseExport
"
$_response
"
if
[
!
-w
"
$_response
"
]
;
then
_log
"
${
_logPrefix
}
ERROR: responsefile
$_response
is not writable."
_log
"
${
_logPrefix
}
$(
ls
-ld
${
dir_data
}
$_response
)
"
_
e
log
"
${
_logPrefix
}
ERROR: responsefile
$_response
is not writable."
_
e
log
"
${
_logPrefix
}
$(
ls
-ld
${
dir_data
}
$_response
)
"
exit
1
fi
...
...
This diff is collapsed.
Click to expand it.
inc_functions.sh
+
10
−
3
View file @
3e934951
...
...
@@ -32,12 +32,19 @@
}
# ......................................................................
# logging output. writes timestamp and the given message to STDOUT
# and ${logfile}
# logging output. writes timestamp and the given message to ${logfile}
# params string(s) message to log
#
function
_log
(){
echo
"
`
date
`
|
$*
"
|
tee
-a
${
logfile
}
echo
"
`
date
`
|
$*
"
>>
${
logfile
}
}
# echo and logging output
# params string(s) message to log
#
function
_elog
(){
echo
"
$*
"
_log
"
$*
"
}
# ======================================================================
...
...
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