Module: check_mk
Branch: master
Commit: d3c7f49ca6a0e4e037ff9c250561dd94cb548294
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d3c7f49ca6a0e4…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Dec 13 15:06:47 2017 +0100
5253 Linux check_mk_agent: now able to execute plugins for real time checks
The file <tt>/etc/check_mk/real_time_checks.cfg</tt> now supports the
parameter
<tt>RTC_PLUGINS</tt> which allows the configuration of plugins to be also
executed
as real time checks.
For example
F:
RTC_PLUGINS+="apache_status"
RTC_PLUGINS+="lvm"
This executes both plugins as real time checks (1sec resolution) as well as standard
check_mk check.
Change-Id: I45967b6ae67d913b95e7a9eda3ad212dd8b10a62
---
.werks/5253 | 22 ++++++++++++++++++++++
agents/check_mk_agent.linux | 42 ++++++++++++++++++++++++++++++++++++------
2 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/.werks/5253 b/.werks/5253
new file mode 100644
index 0000000..1035b4f
--- /dev/null
+++ b/.werks/5253
@@ -0,0 +1,22 @@
+Title: Linux check_mk_agent: now able to execute plugins for real time checks
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1513173632
+Class: feature
+
+The file <tt>/etc/check_mk/real_time_checks.cfg</tt> now supports the
parameter
+<tt>RTC_PLUGINS</tt> which allows the configuration of plugins to be also
executed
+as real time checks.
+
+
+For example
+F:
+RTC_PLUGINS+="apache_status"
+RTC_PLUGINS+="lvm"
+
+This executes both plugins as real time checks (1sec resolution) as well as standard
check_mk check.
+
+
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 6fec1cd..b1a544d 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -85,6 +85,12 @@ if [ "$ENCRYPTED" == "yes" ] ; then
fi
+RTC_PLUGINS=""
+if [ -e $MK_CONFDIR/real_time_checks.cfg ]; then
+ . $MK_CONFDIR/real_time_checks.cfg
+fi
+
+
#
# CHECK SECTIONS
#
@@ -204,13 +210,19 @@ function run_real_time_checks()
PIDFILE=$MK_VARDIR/real_time_checks.pid
echo $$ > $PIDFILE
- . $MK_CONFDIR/real_time_checks.cfg
if [ "$PASSPHRASE" != "" ] ; then
# new mechanism to set the passphrase has priority
RTC_SECRET=$PASSPHRASE
fi
+ if [ "$ENCRYPTED_RT" != "no" ] ; then
+ PROTOCOL=00
+ else
+ PROTOCOL=99
+ fi
+
+
while true; do
# terminate when pidfile is gone or other Real-Time Check process started or
configured timeout
if [ ! -e $PIDFILE ] || [ $(<$PIDFILE) -ne $$ ] || [ $RTC_TIMEOUT -eq 0 ];
then
@@ -218,11 +230,6 @@ function run_real_time_checks()
fi
for SECTION in $RTC_SECTIONS; do
- if [ "$ENCRYPTED_RT" != "no" ] ; then
- PROTOCOL=00
- else
- PROTOCOL=99
- fi
# Be aware of maximum packet size. Maybe we need to check the size of the
section
# output and do some kind of nicer error handling.
# 2 bytes: protocol version, 10 bytes: timestamp, rest: encrypted data
@@ -237,6 +244,29 @@ function run_real_time_checks()
} | dd bs=9999 iflag=fullblock 2>/dev/null >/dev/udp/$REMOTE/$RTC_PORT
done
+
+ # Plugins
+ if cd $PLUGINSDIR ; then
+ for PLUGIN in $RTC_PLUGINS; do
+ if [ ! -f $PLUGIN ] ; then
+ continue
+ fi
+
+ # Be aware of maximum packet size. Maybe we need to check the size of the
section
+ # output and do some kind of nicer error handling.
+ # 2 bytes: protocol version, 10 bytes: timestamp, rest: encrypted data
+ # dd is used to concatenate the output of all commands to a single
write/block => udp packet
+ { echo -n $PROTOCOL ;
+ date +%s | tr -d '\n' ;
+ if [ "$ENCRYPTED_RT" != "no" ] ; then
+ export RTC_SECRET=$RTC_SECRET ; ./$PLUGIN | openssl enc
-aes-256-cbc -pass env:RTC_SECRET -nosalt ;
+ else
+ ./$PLUGIN;
+ fi
+ } | dd bs=9999 iflag=fullblock 2>/dev/null
>/dev/udp/$REMOTE/$RTC_PORT
+ done
+ fi
+
sleep 1
RTC_TIMEOUT=$((RTC_TIMEOUT-1))
done