Module: check_mk
Branch: master
Commit: 1661668322a91bcd4478cae533667525b12727c7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1661668322a91b…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Tue Jan 19 13:39:43 2016 +0100
#2922 check_mk_agent.linux: mrpe sections can now be cached
---
.werks/2922 | 16 ++++++++++++++++
ChangeLog | 1 +
agents/check_mk_agent.linux | 28 +++++++++++++++++++++++++++-
3 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/.werks/2922 b/.werks/2922
new file mode 100644
index 0000000..b33ded2
--- /dev/null
+++ b/.werks/2922
@@ -0,0 +1,16 @@
+Title: check_mk_agent.linux: mrpe sections can now be cached
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i4
+Date: 1453198668
+Class: feature
+
+In the mrpe configuration (for linux systems only!) an optional parameter list can now be
specified
+between service description and commandline in the following format:
+description (interval=300) /command/line
+The only supported parameter for now is interval. This activates caching fo the mrpe
section and
+specifies the interval at which the cache should be refreshed.
+
+Existing mrpe configurations continue to work without change.
+This works only with the linux agent.
diff --git a/ChangeLog b/ChangeLog
index e315a64..e3e8626 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -85,6 +85,7 @@
* 2920 hr_cpu: this check can now also supports per-core features...
* 1322 solaris_prtdiag: New Check for Solaris Hardware State based on prtdiag
* 2921 printer_supply_ricoh: check now tries to handle negative readings properly...
+ * 2922 check_mk_agent.linux: mrpe sections can now be cached
* 2660 FIX: fixed windows agent using the wrong working directory...
* 2664 FIX: ps: Speedup in situation with many matching processes...
* 2661 FIX: windows agent: fixed incomplete process list...
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index b6f07e3..516d070 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -724,8 +724,34 @@ then
grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/mrpe.cfg" | \
while read descr cmdline
do
+ interval=
+ 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[@]}"
+ do
+ # split each assignment
+ IFS='=' read key value <<< $par
+ if [ "$key" = "interval" ]
+ then
+ interval=$value
+ # no other parameters supported currently
+ fi
+ done
+ fi
+
PLUGIN=${cmdline%% *}
- OUTPUT=$(eval "$cmdline")
+ if [ -z "$interval" ]
+ then
+ OUTPUT=$(eval "$cmdline")
+ else
+ OUTPUT=$(run_cached $descr $interval "$cmdline")
+ fi
+
echo -n "(${PLUGIN##*/}) $descr $? $OUTPUT" | tr \\n \\1
echo
done