Module: check_mk
Branch: master
Commit: df4da272c12144b62426924591869982aa773693
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=df4da272c12144…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Thu Apr 18 13:00:42 2019 +0200
6989 FIX Fix timestamp handling for events generated by rules expecting regular messages
Due to the event being rewritten at every new occurence in the case of expect rules,
the timestamp for the event's first occurence would always equal the one for the
last, making it useless. This has been fixed.
CMK-1843
Change-Id: Ie6bf99f19ae2bb31d1b4f6d99f62cdcc49601137
---
.werks/6989 | 13 +++++++++++++
cmk/ec/main.py | 7 ++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/.werks/6989 b/.werks/6989
new file mode 100644
index 0000000..c2d3def
--- /dev/null
+++ b/.werks/6989
@@ -0,0 +1,13 @@
+Title: Fix timestamp handling for events generated by rules expecting regular messages
+Level: 1
+Component: ec
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1555511063
+
+Due to the event being rewritten at every new occurence in the case of expect rules,
+the timestamp for the event's first occurence would always equal the one for the
+last, making it useless. This has been fixed.
diff --git a/cmk/ec/main.py b/cmk/ec/main.py
index 71d7add..26f86d0 100644
--- a/cmk/ec/main.py
+++ b/cmk/ec/main.py
@@ -1286,7 +1286,7 @@ class EventServer(ECServerThread):
merge_event["text"] = text
# Better rewrite (again). Rule might have changed. Also we have changed
# the text and the user might have his own text added via set_text.
- self.rewrite_event(rule, merge_event, {})
+ self.rewrite_event(rule, merge_event, {}, set_first=False)
self._history.add(merge_event, "COUNTFAILED")
else:
# Create artifical event from scratch. Make sure that all important
@@ -1685,7 +1685,7 @@ class EventServer(ECServerThread):
return result
# Rewrite texts and compute other fields in the event
- def rewrite_event(self, rule, event, groups):
+ def rewrite_event(self, rule, event, groups, set_first=True):
if rule["state"] == -1:
prio = event["priority"]
if prio >= 5:
@@ -1708,7 +1708,8 @@ class EventServer(ECServerThread):
if ("sl" not in event) or (rule["sl"]["precedence"] == "rule"):
event["sl"] = rule["sl"]["value"]
- event["first"] = event["time"]
+ if set_first:
+ event["first"] = event["time"]
event["last"] = event["time"]
if "set_comment" in rule:
event["comment"] = replace_groups(rule["set_comment"], event["text"], groups)
Module: check_mk
Branch: master
Commit: aca7b7eac4d27e9d343d3c72146ab71e5e299e80
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aca7b7eac4d27e…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Apr 17 13:08:32 2019 +0200
7402 check_mk_agent: Plugins cache age info in section header
For plugins running asynchronously the cache age information is now included in
the section header. Services corresponding to outdated plugin sections will
become stale.
Affected agents: AIX, freebsd, linux, openwrt, solaris
CMK-1313
Change-Id: I27e75d60d027160c3fa6462eb92b7626f93d8952
---
.werks/7402 | 12 ++++++++++++
agents/check_mk_agent.aix | 5 ++++-
agents/check_mk_agent.freebsd | 5 ++++-
agents/check_mk_agent.linux | 5 ++++-
agents/check_mk_agent.openwrt | 5 ++++-
agents/check_mk_agent.solaris | 5 ++++-
6 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/.werks/7402 b/.werks/7402
new file mode 100644
index 0000000..2368f92
--- /dev/null
+++ b/.werks/7402
@@ -0,0 +1,12 @@
+Title: check_mk_agent: Plugins cache age info in section header
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1555498273
+Class: feature
+
+For plugins running asynchronously the cache age information is now included in
+the section header. Services corresponding to outdated plugin sections will
+become stale.
diff --git a/agents/check_mk_agent.aix b/agents/check_mk_agent.aix
index a678c5c..a2c1b94 100755
--- a/agents/check_mk_agent.aix
+++ b/agents/check_mk_agent.aix
@@ -124,7 +124,10 @@ function run_cached {
if (( $MTIME < $MAXAGE )) ; then
USE_CACHE_FILE=1
fi
- cat $CACHE_FILE
+ CACHE_INFO=":cached($MTIME,$MAXAGE)"
+ # insert the cache info in the section header (^= after '!'),
+ # if none is present (^= before '!')
+ sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1'$CACHE_INFO'>>>/' "$CACHE_FILE"
fi
if [ -z "$USE_CACHE_FILE" -a ! -e "$CACHE_FILE.new" ]
then
diff --git a/agents/check_mk_agent.freebsd b/agents/check_mk_agent.freebsd
index e097643..f187bbd 100755
--- a/agents/check_mk_agent.freebsd
+++ b/agents/check_mk_agent.freebsd
@@ -97,7 +97,10 @@ function run_cached() {
if [ $((NOW - MTIME)) -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"
+ CACHE_INFO=":cached($MTIME,$MAXAGE)"
+ # insert the cache info in the section header (^= after '!'),
+ # if none is present (^= before '!')
+ sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1'$CACHE_INFO'>>>/' "$CACHEFILE"
fi
# Cache file outdated and new job not yet running? Start it
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index e774b9a..90c8c34 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -290,7 +290,10 @@ function run_cached () {
# all further lines are long output)
sed -e "2s/|/ (Cached: ${AGE}\/${MAXAGE}s)|/" -e t -e "2s/$/ (Cached: ${AGE}\/${MAXAGE}s)/" < "$CACHEFILE"
else
- cat "$CACHEFILE"
+ CACHE_INFO=":cached($MTIME,$MAXAGE)"
+ # insert the cache info in the section header (^= after '!'),
+ # if none is present (^= before '!')
+ sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1'$CACHE_INFO'>>>/' "$CACHEFILE"
fi
fi
diff --git a/agents/check_mk_agent.openwrt b/agents/check_mk_agent.openwrt
index 8deb826..5718e5d 100755
--- a/agents/check_mk_agent.openwrt
+++ b/agents/check_mk_agent.openwrt
@@ -165,7 +165,10 @@ run_cached () {
# 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"
+ CACHE_INFO=":cached($MTIME,$MAXAGE)"
+ # insert the cache info in the section header (^= after '!'),
+ # if none is present (^= before '!')
+ sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1'$CACHE_INFO'>>>/' "$CACHEFILE"
fi
fi
diff --git a/agents/check_mk_agent.solaris b/agents/check_mk_agent.solaris
index b3e843b..88e6a30 100755
--- a/agents/check_mk_agent.solaris
+++ b/agents/check_mk_agent.solaris
@@ -127,7 +127,10 @@ function run_cached () {
# 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"
+ CACHE_INFO=":cached($MTIME,$MAXAGE)"
+ # insert the cache info in the section header (^= after '!'),
+ # if none is present (^= before '!')
+ sed -e '/^<<<.*\(:cached(\).*>>>/!s/^<<<\([^>]*\)>>>$/<<<\1'$CACHE_INFO'>>>/' "$CACHEFILE"
fi
fi