Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
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
IML Open Source
icinga-checks
Commits
08b52234
Commit
08b52234
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
rewrite check using cronstatus.sh
parent
93271f92
No related branches found
No related tags found
1 merge request
!40
5731 simplify cronjob check
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_cronstatus
+51
-133
51 additions, 133 deletions
check_cronstatus
with
51 additions
and
133 deletions
check_cronstatus
+
51
−
133
View file @
08b52234
...
@@ -22,166 +22,84 @@
...
@@ -22,166 +22,84 @@
# 2020-02-28 v1.3 ah,ds ouput with separated error jobs and OK jobs
# 2020-02-28 v1.3 ah,ds ouput with separated error jobs and OK jobs
# 2020-03-05 v1.4 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-03-05 v1.4 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2022-02-28 v1.5 <axel.hahn@iml.unibe.ch> fix output of error counter
# 2022-02-28 v1.5 <axel.hahn@iml.unibe.ch> fix output of error counter
# 2022-08-23 v2.0 <axel.hahn@iml.unibe.ch> simplify it: use cronstatus.sh (it has exitcode >0 on errors now)
# ======================================================================
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
LOGDIR
=
/var/tmp/cronlogs
errfile
=
/tmp/cronjob_status.
$$
.err
failfile
=
/tmp/cronjob_status.
$$
.fails
outputOk
=
/tmp/cronjob_status_out_ok.
$$
.txt
outputError
=
/tmp/cronjob_status_out_error.
$$
.txt
typeset
-i
iMaxAge
=
`
date
+%s
`
typeset
-i
iJobs
=
0
typeset
-i
iErrJobs
=
0
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPVERSION
=
2.0
statusScript
=
/opt/cronwrapper/cronstatus.sh
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#
FUNCTIONS
#
functions
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# get a value from logfile (everything behind "="
function
showHelp
(){
# param: label
cat
<<
EOF
# global: $logfile
______________________________________________________________________
function
getLogValue
(){
grep
"^
$1
="
$logfile
|
cut
-f
2-
-d
"="
}
$self_APPNAME
v
$self_APPVERSION
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
# ----------------------------------------------------------------------
Show status of all Cronjobs using Axels Cronwrapper
# MAIN
https://github.com/axelhahn/cronwrapper
# ----------------------------------------------------------------------
iJobs
=
`
ls
-1
$LOGDIR
/
*
log 2>/dev/null | fgrep
-v
"/__"
| fgrep
".log"
|
wc
-l
`
The last run of each job is verified to these conditions:
- exitcode was 0
- last run is younger than given TTL
if
[
$iJobs
-eq
0
]
;
then
ph.abort
"SKIP: no cronjobs with cronwrapper were found"
fi
# ----------------------------------------------------------------------
SYNTAX:
# check all logs
$(
basename
$0
)
[-h] [SCRIPT]
# ----------------------------------------------------------------------
ls
-1t
$LOGDIR
/
*
log | fgrep
-v
"/__"
|
while
read
logfile
do
iJobs
=
$iJobs
+1
typeset
-i
iErr
=
0
sTmpOutfile
=
$outputOk
server
=
`
basename
$logfile
|
cut
-f
1
-d
"_"
`
jobname
=
`
basename
$logfile
|
cut
-f
2
-d
"_"
|
sed
"s#
\.
log##"
`
sPre
=
" "
sCmd
=
`
getLogValue SCRIPTNAME
`
sLastStart
=
`
getLogValue SCRIPTSTARTTIME
`
typeset
-i
iJobExpire
=
`
getLogValue JOBEXPIRE
`
typeset
-i
rc
=
`
getLogValue
'SCRIPTRC'
|
head
-1
`
typeset
-i
iEcectime
=
`
getLogValue
'SCRIPTEXECTIME'
|
head
-1
|
cut
-f
1
-d
" "
`
sTTL
=
`
getLogValue
'SCRIPTTTL'
`
# ----- check return code
statusRc
=
'OK'
if
[
$rc
-ne
0
]
;
then
iErr
=
$iErr
+1
statusRc
=
'ERROR'
fi
# ----- check ttl value
OPTIONS:
typeset
-i
iTTL
=
$sTTL
typeset
-i
iTTLsec
=
0
iTTL
=
$iTTL
iTTLsec
=
$iTTL
*
60
ttlstatus
=
"OK"
if
[
-z
$sTTL
]
;
then
iErr
=
$iErr
+1
statusTtl
=
"ERROR: ttl value is empty"
else
# human readable ttl in min/ hours/ days
statusTtl
=
"
$iTTL
min"
if
[
$iTTL
-gt
60
]
;
then
iTTL
=
$iTTL
/60
;
statusTtl
=
"
$sTTL
-
$iTTL
h"
if
[
$iTTL
-gt
24
]
;
then
iTTL
=
$iTTL
/24
;
statusTtl
=
"
$sTTL
-
$iTTL
d"
fi
fi
if
[
$iTTLsec
-lt
$iEcectime
]
;
then
iErr
=
$iErr
+1
statusTtl
=
"ERROR:
$iTTL
min =
$iTTLsec
s - is too low; exec time is
$iEcectime
s - set a higher TTL for this cronjob"
iErr
=
$iErr
+1
else
statusTtl
=
"
$statusTtl
OK"
fi
fi
# ----- check expire
statusExpire
=
"
`
date
-d
@
$iJobExpire
'+%Y-%m-%d %H:%M:%S'
`
"
if
[
$iJobExpire
-lt
$iMaxAge
]
;
then
statusExpire
=
"
${
statusExpire
}
ERROR"
iErr
=
$iErr
+1
else
statusExpire
=
"
${
statusExpire
}
OK"
fi
# ----- show jobdetail and put to OK file or error file
sTmpOutfile
=
$outputOk
test
$iErr
-gt
0
&&
sTmpOutfile
=
$outputError
(
echo
echo
---
$logfile
echo
"
${
sPre
}${
sCmd
}
"
echo
"
${
sPre
}
last start:
${
sLastStart
}
"
echo
"
${
sPre
}
returncode:
${
rc
}
${
statusRc
}
"
echo
"
${
sPre
}
duration:
${
iEcectime
}
s"
echo
"
${
sPre
}
ttl:
${
statusTtl
}
"
echo
"
${
sPre
}
expires:
${
iJobExpire
}
${
statusExpire
}
"
if
[
$iErr
-gt
0
]
;
then
-h or --help show this help.
echo
"
${
sPre
}
CHECK FAILED"
iErrJobs
=
$iErrJobs
+1
echo
"
$logfile
"
>
$errfile
getLogValue SCRIPTLABEL
>>
$failfile
fi
)>>
$sTmpOutfile
done
PARAMETERS:
SCRIPT optional: custom status script
default:
$statusScript
EOF
}
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
#
output
#
MAIN
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
if
[
-f
$errfile
]
;
then
# --- check param -h
iErrJobs
=
$(
wc
-l
$errfile
|
cut
-f
1
-d
" "
)
case
"
$1
"
in
echo
"ERROR:
$iErrJobs
of
$iJobs
jobs [
`
cat
$failfile
|
sed
':a;N;$!ba;s/\n/, /g'
`
] have a problem"
"--help"
|
"-h"
)
echo
showHelp
echo
"********** Jobs with problems:"
exit
0
cat
$outputError
;;
echo
*
)
echo
esac
echo
"********** OK:"
cat
$outputOk
rm
-f
$errfile
$failfile
$outputError
else
echo
"OK:
$iJobs
cronjob(s) run fine"
cat
$outputOk
fi
test
"
$1
"
&&
statusScript
=
"
$1
"
# --- exit
if
[
!
-x
"
${
statusScript
}
"
]
;
then
if
[
$iErrJobs
-ne
0
]
;
then
ph.setStatus
"unknown"
ph.setStatus
"critical
"
ph.status Cronjob status - script not found/ not executable:
"
${
statusScript
}
"
else
else
ph.setStatus
"ok"
fi
rm
-f
$outputOk
out
=
$(
$statusScript
)
rc
=
$?
if
[
$rc
-ne
0
]
;
then
ph.setStatus
"critical"
else
ph.setStatus
"ok"
fi
ph.status Cronjob status
$(
echo
"
$out
"
|
tail
-1
)
echo
"
$out
"
|
sed
-r
"s/
\x
1B
\[
([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"
fi
ph.exit
ph.exit
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
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