diff --git a/check_journallog b/check_journallog index 0f6f13e83e3655e66e1dbf711ead1cdabe552ca1..6652b6ac5913759825068bcbf665d31e29b28ec5 100755 --- a/check_journallog +++ b/check_journallog @@ -9,11 +9,12 @@ # # ---------------------------------------------------------------------- # 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 -export self_APPVERSION=0.1 +export self_APPVERSION=1.0 tmpfile=/tmp/last_journallog_line_${USER}.txt @@ -29,6 +30,7 @@ $( ph.showImlHelpHeader ) Show number of lines in journallog per min. A strong change of the written lines per min COULD indicate a problem. +It requires sudo permission on /bin/journalctl The status is ... - unknown - if journalctl is not available @@ -84,21 +86,24 @@ typeset -i iCriticalLimit=$( ph.getValueWithParam 0 c "$@") lastLine=$( cat "$tmpfile" 2>/dev/null ) if [ -z "$lastLine" ]; then ph.setStatus unknown - ph.status "Initializing ... storing last line of jorunallog ..." - journalctl -n 1 | tail -1 > "$tmpfile" + if ! sudo -n journalctl --version >/dev/null 2>&1; then + 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 - # mydate is "Okt 12 16:23:36" - # mydate=$( cut -f 1-3 -d " " <<< "$lastLine" ) - - # 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" - + # Remark: parsing of date from journallog entry can fail because of + # language specific monthes or no date on multi line entries + # Thats why we take the timestamp of the 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" ) - data=$( sudo journalctl --since "$ts" ) + data=$( sudo -n journalctl --since "$ts" ) # detect last seen position and count lines from there typeset -i iTotal; iTotal=$( wc -l <<< "$data" ) @@ -132,8 +137,6 @@ else fi -# cat "$tmpfile" - ph.exit # ---------------------------------------------------------------------- diff --git a/docs/20_Checks/check_journallog.md b/docs/20_Checks/check_journallog.md index d59448853fb1ab87d389c95f3545011eb4bd91fe..1b5517bd1a04e1feb068f08f323206d221b879ca 100644 --- a/docs/20_Checks/check_journallog.md +++ b/docs/20_Checks/check_journallog.md @@ -20,7 +20,7 @@ icingaclient ALL=(ALL) NOPASSWD: /bin/journalctl ______________________________________________________________________ CHECK_JOURNALLOG -v0.1 +v1.0 (c) Institute for Medical Education - University of Bern Licence: GNU GPL 3 @@ -30,6 +30,7 @@ ______________________________________________________________________ Show number of lines in journallog per min. A strong change of the written lines per min COULD indicate a problem. +It requires sudo permission on /bin/journalctl The status is ... - unknown - if journalctl is not available @@ -61,7 +62,6 @@ EXAMPLES: Set warning level to 100 written lines per min but no critical limit. This check then never will send a critical status. - ``` ## Examples