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

journallog: update sudo command; set v1.0

parent 3e88dade
No related branches found
No related tags found
1 merge request!188journallog: update sudo command; set v1.0
...@@ -9,11 +9,12 @@ ...@@ -9,11 +9,12 @@
# #
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# 2023-10-12 v0.1 <axel.hahn@unibe.ch> initial version # 2023-10-12 v0.1 <axel.hahn@unibe.ch> initial version
# 2023-10-13 v1.0 <axel.hahn@unibe.ch> update sudo command; set v1.0
# ====================================================================== # ======================================================================
. $( dirname $0 )/inc_pluginfunctions . $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=0.1 export self_APPVERSION=1.0
tmpfile=/tmp/last_journallog_line_${USER}.txt tmpfile=/tmp/last_journallog_line_${USER}.txt
...@@ -29,6 +30,7 @@ $( ph.showImlHelpHeader ) ...@@ -29,6 +30,7 @@ $( ph.showImlHelpHeader )
Show number of lines in journallog per min. Show number of lines in journallog per min.
A strong change of the written lines per min COULD indicate a problem. A strong change of the written lines per min COULD indicate a problem.
It requires sudo permission on /bin/journalctl
The status is ... The status is ...
- unknown - if journalctl is not available - unknown - if journalctl is not available
...@@ -84,21 +86,24 @@ typeset -i iCriticalLimit=$( ph.getValueWithParam 0 c "$@") ...@@ -84,21 +86,24 @@ typeset -i iCriticalLimit=$( ph.getValueWithParam 0 c "$@")
lastLine=$( cat "$tmpfile" 2>/dev/null ) lastLine=$( cat "$tmpfile" 2>/dev/null )
if [ -z "$lastLine" ]; then if [ -z "$lastLine" ]; then
ph.setStatus unknown ph.setStatus unknown
ph.status "Initializing ... storing last line of jorunallog ..." if ! sudo -n journalctl --version >/dev/null 2>&1; then
journalctl -n 1 | tail -1 > "$tmpfile" ph.status "User $USER has sudo permissions to execute journalctl."
ph.exit
else
#
# 1st run: initialize
#
ph.status "Initializing ... storing last line of jorunallog ..."
sudo -n journalctl -n 1 | tail -1 > "$tmpfile"
fi
else else
# mydate is "Okt 12 16:23:36" # Remark: parsing of date from journallog entry can fail because of
# mydate=$( cut -f 1-3 -d " " <<< "$lastLine" ) # language specific monthes or no date on multi line entries
# Thats why we take the timestamp of the tmpfile
# what works:
# date -d "12 sec ago" +"%Y-%m-%d %H:%I:%S"
# date -d "Oct 12 14:24:04" +"%Y-%m-%d %H:%M:%S"
typeset -i iAge; iAge=$( ph.getFileAge "$tmpfile" ) typeset -i iAge; iAge=$( ph.getFileAge "$tmpfile" )
# ts=$( date -d "${mydate}" +"%Y-%m-%d %H:%M:%S" )
ts=$( date -d "${iAge} sec ago" +"%Y-%m-%d %H:%M:%S" ) ts=$( date -d "${iAge} sec ago" +"%Y-%m-%d %H:%M:%S" )
data=$( sudo journalctl --since "$ts" ) data=$( sudo -n journalctl --since "$ts" )
# detect last seen position and count lines from there # detect last seen position and count lines from there
typeset -i iTotal; iTotal=$( wc -l <<< "$data" ) typeset -i iTotal; iTotal=$( wc -l <<< "$data" )
...@@ -132,8 +137,6 @@ else ...@@ -132,8 +137,6 @@ else
fi fi
# cat "$tmpfile"
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -20,7 +20,7 @@ icingaclient ALL=(ALL) NOPASSWD: /bin/journalctl ...@@ -20,7 +20,7 @@ icingaclient ALL=(ALL) NOPASSWD: /bin/journalctl
______________________________________________________________________ ______________________________________________________________________
CHECK_JOURNALLOG CHECK_JOURNALLOG
v0.1 v1.0
(c) Institute for Medical Education - University of Bern (c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3 Licence: GNU GPL 3
...@@ -30,6 +30,7 @@ ______________________________________________________________________ ...@@ -30,6 +30,7 @@ ______________________________________________________________________
Show number of lines in journallog per min. Show number of lines in journallog per min.
A strong change of the written lines per min COULD indicate a problem. A strong change of the written lines per min COULD indicate a problem.
It requires sudo permission on /bin/journalctl
The status is ... The status is ...
- unknown - if journalctl is not available - unknown - if journalctl is not available
...@@ -61,7 +62,6 @@ EXAMPLES: ...@@ -61,7 +62,6 @@ EXAMPLES:
Set warning level to 100 written lines per min but Set warning level to 100 written lines per min but
no critical limit. This check then never will send a no critical limit. This check then never will send a
critical status. critical status.
``` ```
## Examples ## Examples
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment