Module: check_mk
Branch: master
Commit: 8b74aeba00f6e3baddf0b0f4d321ad765a7565af
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8b74aeba00f6e3…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Tue May 24 15:59:26 2016 +0200
3137 linux and solaris agent: mrpe checks now support option to append the cache age to
cached results
---
.werks/3137 | 13 +++++++++++++
ChangeLog | 1 +
agents/check_mk_agent.linux | 33 ++++++++++++++++++++++-----------
agents/check_mk_agent.solaris | 26 ++++++++++++++++++--------
4 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/.werks/3137 b/.werks/3137
new file mode 100644
index 0000000..64c3d3d
--- /dev/null
+++ b/.werks/3137
@@ -0,0 +1,13 @@
+Title: linux and solaris agent: mrpe checks now support option to append the cache age to
cached results
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.9i1
+Date: 1464098117
+Class: feature
+
+To setup mrpe checks that also display the age of the cache, use a line in mrpe.cfg like
this:
+LOAD (interval=360:appendage=1) /usr/bin/check_load
+
+interval specifies the maximum cache age in seconds (here: 6 minutes) and appendage=1
instructs the
+agent to append the cache age to the output.
diff --git a/ChangeLog b/ChangeLog
index 6b01b99..673fd3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -84,6 +84,7 @@
* 3135 skype, skype.xmpp_proxy, skype.conferencing, skype.sip_stack: added furter
metrics and adjusted default levels
* 3609 apc_rackpdu_power: now upper levels for electrical current are confiugurable
* 3136 windows agent: improved crash reporting...
+ * 3137 linux and solaris agent: mrpe checks now support option to append the cache
age to cached results...
* 3073 FIX: windows agent: relative paths to mrpe scripts are now treated as relative
to the agent installation directory...
* 3061 FIX: mk_jolokia: Fixed debugging of the agent plugin
* 3074 FIX: windows agent: fixed incorrect values for 32-bit performance counters
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 9ba058a..30afede 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -133,8 +133,10 @@ function run_cached () {
local NOW=$(date +%s)
local section=
local mrpe=0
+ local append_age=0
if [ "$1" = -s ] ; then local section="echo
'<<<$2:cached($NOW,$3)>>>' ; " ; shift ; fi
if [ "$1" = -m ] ; then local mrpe=1 ; shift ; fi
+ if [ "$1" = -a ] ; then local append_age=1 ; shift ; fi
local NAME=$1
local MAXAGE=$2
shift 2
@@ -156,17 +158,27 @@ function run_cached () {
fi
fi
+
# Check if cache file exists and is recent enough
if [ -s "$CACHEFILE" ] ; then
local MTIME=$(stat -c %Y "$CACHEFILE")
- if [ $((NOW - MTIME)) -le $MAXAGE ] ; then local USE_CACHEFILE=1 ; fi
+ local AGE=$((NOW - MTIME))
+ if [ $AGE -le $MAXAGE ] ; then local USE_CACHEFILE=1 ; fi
# Output the file in any case, even if it is
# outdated. The new file will not yet be available
- cat "$CACHEFILE"
+ if [ $append_age -eq 1 ] ; then
+ # insert the cached-string before the pipe (first -e)
+ # or, if no pipe found (-e t) append it (third -e),
+ # but only once and on the second line (2!b) (first line is section header,
+ # all further lines are long output)
+ cat "$CACHEFILE" | sed -e "2s/|/ (Cached:
${AGE}\/${MAXAGE}s)|/" -e t -e "2s/$/ (Cached: ${AGE}\/${MAXAGE}s)/"
+ else
+ cat "$CACHEFILE"
+ fi
fi
# Cache file outdated and new job not yet running? Start it
- if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ] ; then
+ if [ -z "$USE_CACHEFILE" ] && [ ! -e "$CACHEFILE.new" ] ;
then
# When the command fails, the output is throws away ignored
if [ $mrpe -eq 1 ] ; then
echo "set -o noclobber ; exec > \"$CACHEFILE.new\" || exit
1 ; run_mrpe $NAME $CMDLINE && mv \"$CACHEFILE.new\"
\"$CACHEFILE\" || rm -f \"$CACHEFILE\"
\"$CACHEFILE.new\"" | nohup bash >/dev/null 2>&1 &
@@ -792,23 +804,23 @@ then
while read descr cmdline
do
interval=
+ args="-m"
if [[ $cmdline =~ \(([^\)]*)\)[[:space:]](.*) ]]
then
parameters=${BASH_REMATCH[1]}
cmdline=${BASH_REMATCH[2]}
# split multiple parameter assignments
- IFS=':' read -a parlist <<< $parameters
- for par in "${parlist[@]}"
+ for par in $(echo $parameters | tr ":" "\n")
do
# split each assignment
key=$(echo $par | cut -d= -f1)
value=$(echo $par | cut -d= -f2)
- if [ "$key" = "interval" ]
- then
+ if [ "$key" = "interval" ] ; then
interval=$value
- # no other parameters supported currently
+ elif [ "$key" = "appendage" ] ; then
+ args="$args -a"
fi
done
fi
@@ -817,7 +829,7 @@ then
then
run_mrpe $descr "$cmdline"
else
- run_cached -m $descr $interval "$cmdline"
+ run_cached $args $descr $interval "$cmdline"
fi
done
fi
@@ -846,8 +858,7 @@ then
cmdline=${BASH_REMATCH[2]}
# split multiple parameter assignments
- IFS=':' read -a parlist <<< $parameters
- for par in "${parlist[@]}"
+ for par in $(echo $parameters | tr ":" "\n")
do
# split each assignment
IFS='=' read key value <<< $par
diff --git a/agents/check_mk_agent.solaris b/agents/check_mk_agent.solaris
index efd53c3..17ce30e 100755
--- a/agents/check_mk_agent.solaris
+++ b/agents/check_mk_agent.solaris
@@ -74,8 +74,10 @@ export -f run_mrpe
# Runs a command asynchronous by use of a cache file
function run_cached () {
local mrpe=0
+ local append_age=0
if [ "$1" = -s ] ; then local section="echo
'<<<$2>>>' ; " ; shift ; fi
if [ "$1" = -m ] ; then local mrpe=1 ; shift ; fi
+ if [ "$1" = -a ] ; then local append_age=1 ; shift ; fi
local NAME=$1
local MAXAGE=$2
shift 2
@@ -99,11 +101,19 @@ function run_cached () {
if [ $AGE -le $MAXAGE ] ; then local USE_CACHEFILE=1 ; fi
# Output the file in any case, even if it is
# outdated. The new file will not yet be available
- cat "$CACHEFILE"
+ if [ $append_age -eq 1 ] ; then
+ # insert the cached-string before the pipe (first -e)
+ # or, if no pipe found (-e t) append it (third -e),
+ # but only once and on the second line (2) (first line is section header,
+ # all further lines are long output)
+ cat "$CACHEFILE" | sed -e "2s/|/ (Cached:
${AGE}\/${MAXAGE}s)|/" -e t -e "2s/$/ (Cached: ${AGE}\/${MAXAGE}s)/"
+ else
+ cat "$CACHEFILE"
+ fi
fi
# Cache file outdated and new job not yet running? Start it
- if [ -z "$USE_CACHEFILE" -a ! -e "$CACHEFILE.new" ] ; then
+ if [ -z "$USE_CACHEFILE" ] && [ ! -e "$CACHEFILE.new" ] ;
then
if [ $mrpe -eq 1 ] ; then
echo "set -o noclobber ; exec > \"$CACHEFILE.new\" || exit
1 ; run_mrpe $NAME $CMDLINE && mv \"$CACHEFILE.new\"
\"$CACHEFILE\" || rm -f \"$CACHEFILE\"
\"$CACHEFILE.new\"" | nohup bash >/dev/null 2>&1 &
else
@@ -375,23 +385,23 @@ then
while read descr cmdline
do
interval=
+ args="-m"
if [[ $cmdline =~ \(([^\)]*)\)[[:space:]](.*) ]]
then
parameters=${BASH_REMATCH[1]}
cmdline=${BASH_REMATCH[2]}
# split multiple parameter assignments
- IFS=':' read -a parlist <<< $parameters
- for par in "${parlist[@]}"
+ for par in $(echo $parameters | tr ":" "\n")
do
# split each assignment
key=$(echo $par | cut -d= -f1)
value=$(echo $par | cut -d= -f2)
- if [ "$key" = "interval" ]
- then
+ if [ "$key" = "interval" ] ; then
interval=$value
- # no other parameters supported currently
+ elif [ "$key" = "appendage" ] ; then
+ args="$args -a"
fi
done
fi
@@ -400,7 +410,7 @@ then
then
run_mrpe $descr "$cmdline"
else
- run_cached -m $descr $interval "$cmdline"
+ run_cached $args $descr $interval "$cmdline"
fi
done
fi