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

add check_journallog

parent 6e7b34be
No related branches found
No related tags found
1 merge request!185add check_journallog
#!/bin/bash
# ======================================================================
#
# Check count of written entries in journallog
#
# requirements:
# - journalctl
#
# ----------------------------------------------------------------------
# 2023-10-12 v0.1 <axel.hahn@unibe.ch> initial version
# ======================================================================
. $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=0.1
tmpfile=/tmp/last_journallog_line_${USER}.txt
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help text
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
$( ph.showImlHelpHeader )
Show number of lines in journallog per min.
A strong change of the written lines per min COULD indicate a problem.
The status is ...
- unknown - if journalctl is not available
- if the script is started the 1st time and stores the last
line of the journallog
- ok - when showing written tnries per min
- warning/ critical - when giving -c and -w parameter values
This plugin sends performancedata.
SYNTAX:
$_self [-h] [-w WARN_LIMIT] [-c CRITICAL_LIMIT]
OPTIONS:
-h this help
-w VALUE warning level (default: 0)
-c VALUE critical level (default: 0)
PARAMETERS:
None.
EXAMPLES:
$_self show count of newly written log entries
$_self -w 100 -c 200
Set warning level to 100 written lines per min and
critical to 200.
$_self -w 100
Set warning level to 100 written lines per min but
no critical limit. This check then never will send a
critical status.
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# handle params
ph.hasParamoption "h" "$@"; bOptHelp=$?
if [ $bOptHelp -eq 0 ]; then
showHelp
exit 0
fi
ph.require journalctl
typeset -i iWarnLimit=$( ph.getValueWithParam 0 w "$@")
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 > "$tmpfile"
else
ts=$( cut -f 1-3 -d " " <<< "$lastLine" )
typeset -i iAge; iAge=$( ph.getFileAge "$tmpfile" )
data=$( journalctl --since "$ts" )
# for next run: insert last handled line
tail -1 <<< "$data" > "$tmpfile"
# detect last seen position and count lines from there
typeset -i iTotal; iTotal=$( wc -l <<< "$data" )
typeset -i iFrom; iFrom=$( grep -Fn "$lastLine" <<< "$data" | head -1 | cut -f 1 -d ':' )
typeset -i iLines; iLines=$iTotal-$iFrom
typeset -i iLinespermin; iLinespermin=$iLines*60/$iAge
if [ $iWarnLimit -gt 0 -a $iWarnLimit -le $iLinespermin ]; then
ph.setStatus "warning"
fi
if [ $iCriticalLimit -gt 0 -a $iCriticalLimit -le $iLinespermin ]; then
ph.setStatus "critical"
fi
ph.perfadd "lines-per-min" "${iLinespermin}"
# output
ph.status "Journallog stored $iLinespermin lines per min"
sLimits=""
test $iWarnLimit -gt 0 && sLimits+="WARNING at $iWarnLimit"
test $iWarnLimit -gt 0 || sLimits+="No warning level"
sLimits+="; "
test $iCriticalLimit -gt 0 && sLimits+="CRITICAL at $iCriticalLimit"
test $iCriticalLimit -gt 0 || sLimits+="No critical level "
echo "Limits: $sLimits"
# echo "Found $iLines new line(s) in the last $iAge sec"
fi
# cat "$tmpfile"
ph.exit
# ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment