Module: check_mk
Branch: master
Commit: 4b558182d2c0d2cf077fb039cddf78243030b7c2
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4b558182d2c0d2…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed May 9 13:41:03 2018 +0200
6063 FIX Special agents: Remove unreplaced macros from special agent command lines
In previous versions the command lines of special agent calls like e.g. custom
data source programs could contain unreplaced macros in the format <tt>$_HOST_MACRO$</tt>
which were later inpterpreted as shell variables. In case there was no such variable in
the shell environment, the trailing <tt>$</tt> was left on the command line as single
character.
This could lead to some broken command line calls. We now do the replacement as usual.
After replacing all known macros, the command line is searched for left over $...$ macros
and remove the whole macro from the command line. This should make optional macro handling
a lot easier.
Change-Id: I83d4152af691ea7a764c9fd7f6c210f0c078a64e
---
.werks/6063 | 20 ++++++++++++++++++++
cmk_base/data_sources/programs.py | 8 ++++++++
tests/unit/cmk_base/test_data_sources_unit.py | 20 ++++++++++++++++++++
3 files changed, 48 insertions(+)
diff --git a/.werks/6063 b/.werks/6063
new file mode 100644
index 0000000..8187cb5
--- /dev/null
+++ b/.werks/6063
@@ -0,0 +1,20 @@
+Title: Special agents: Remove unreplaced macros from special agent command lines
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1525865298
+
+In previous versions the command lines of special agent calls like e.g. custom
+data source programs could contain unreplaced macros in the format <tt>$_HOST_MACRO$</tt>
+which were later inpterpreted as shell variables. In case there was no such variable in
+the shell environment, the trailing <tt>$</tt> was left on the command line as single
+character.
+
+This could lead to some broken command line calls. We now do the replacement as usual.
+After replacing all known macros, the command line is searched for left over $...$ macros
+and remove the whole macro from the command line. This should make optional macro handling
+a lot easier.
diff --git a/cmk_base/data_sources/programs.py b/cmk_base/data_sources/programs.py
index e3f49e4..8dd4f1f 100644
--- a/cmk_base/data_sources/programs.py
+++ b/cmk_base/data_sources/programs.py
@@ -29,6 +29,7 @@ import signal
import subprocess
import cmk.paths
+import cmk.regex
import cmk_base.console as console
import cmk_base.config as config
@@ -136,6 +137,7 @@ class DSProgramDataSource(ProgramDataSource):
cmd = self._translate_legacy_macros(cmd)
cmd = self._translate_host_macros(cmd)
+ cmd = self._cleanup_left_over_macros(cmd)
return cmd
@@ -157,6 +159,12 @@ class DSProgramDataSource(ProgramDataSource):
return core_config.replace_macros(cmd, macros)
+ def _cleanup_left_over_macros(self, cmd):
+ """Now after we have replaced all known macros remove all remaining macros in
+ the format $...$ to prevent shell expansion of them"""
+ return cmk.regex.regex(r"\$[a-zA-Z0-9_-]+\$").sub("", cmd)
+
+
class SpecialAgentDataSource(ProgramDataSource):
def __init__(self, hostname, ipaddress, special_agent_id, params):
diff --git a/tests/unit/cmk_base/test_data_sources_unit.py b/tests/unit/cmk_base/test_data_sources_unit.py
index 65503ef..10de607 100644
--- a/tests/unit/cmk_base/test_data_sources_unit.py
+++ b/tests/unit/cmk_base/test_data_sources_unit.py
@@ -34,3 +34,23 @@ def test_disable_data_source_cache_no_write(mocker):
disabled_checker = mocker.patch.object(source, "is_agent_cache_disabled")
assert source._write_cache_file("X") is None
disabled_checker.assert_called_once()
+
+
+def test_ds_command_line_expansion_legacy_macros():
+ source = cmk_base.data_sources.programs.DSProgramDataSource("hostname", "ipaddress", "echo '<IP> <HOST>'")
+ assert source._get_command_line() == "echo 'ipaddress hostname'"
+
+
+def test_ds_command_line_expansion_host_macros():
+ source = cmk_base.data_sources.programs.DSProgramDataSource("hostname", "ipaddress", "echo '$HOSTNAME$'")
+ assert source._get_command_line() == "echo 'hostname'"
+
+
+def test_ds_command_line_expansion_left_over_macros():
+ source = cmk_base.data_sources.programs.DSProgramDataSource("hostname", "ipaddress", "echo '$BLABLUB$'")
+ assert source._get_command_line() == "echo ''"
+
+
+def test_ds_command_line_expansion_skip_shell_variables():
+ source = cmk_base.data_sources.programs.DSProgramDataSource("hostname", "ipaddress", "echo '$BLABLUB$ $XXX'")
+ assert source._get_command_line() == "echo ' $XXX'"
Module: check_mk
Branch: master
Commit: 62e3e1665d42b94716d97ccec941efedad0c78fc
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62e3e1665d42b9…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed May 9 13:40:54 2018 +0200
6074 FIX postgres_sessions: Missing information about 'idle' or 'active' sessions means zero which is never shown
Change-Id: I16f8fb18a508c9b1a7efa0b8cbc04f97cfc7301a
---
.werks/6074 | 10 +++++++++
checks/postgres_sessions | 56 ++++++++++++++++++++++--------------------------
2 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/.werks/6074 b/.werks/6074
new file mode 100644
index 0000000..66d1506
--- /dev/null
+++ b/.werks/6074
@@ -0,0 +1,10 @@
+Title: postgres_sessions: Missing information about 'idle' or 'active' sessions means zero which is never shown
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1525865939
+Class: fix
+
+
diff --git a/checks/postgres_sessions b/checks/postgres_sessions
index 71044d4..ac7283e 100644
--- a/checks/postgres_sessions
+++ b/checks/postgres_sessions
@@ -45,11 +45,11 @@ def parse_postgres_sessions(info):
if line[0].startswith("[[[") and line[0].endswith("]]]"):
instance_name = line[0][3:-3].upper()
continue
- parsed.setdefault(instance_name, {})
+ instance = parsed.setdefault(instance_name, {})
if line[0].startswith("t"):
- parsed[instance_name]["total"] = int(line[1])
+ instance["total"] = int(line[1])
elif line[0].startswith("f"):
- parsed[instance_name]["running"] = int(line[1])
+ instance["running"] = int(line[1])
return parsed
@@ -58,35 +58,31 @@ def inventory_postgres_sessions(parsed):
def check_postgres_sessions(item, params, parsed):
- if item in parsed:
- idle = parsed[item]['total']
- running = parsed[item]['running']
- total = idle + running
- status = 0
- infos = []
- perfdata = []
- for value, what, format, unit in [
- ( total, "total", "%d", "" ),
- ( running, "running", "%d", "" )]:
- infos.append((format + " %s%s") % (value, what, unit))
- if what in params:
- warn, crit = params[what]
- if value >= crit:
- status = 2
- infos[-1] += "(!!)"
- elif value >= warn:
- status = max(status, 1)
- infos[-1] += "(!)"
- else:
- warn, crit = None, None
- perfdata.append((what, value, warn, crit))
+ if item not in parsed:
+ # In case of missing information we assume that the login into
+ # the database has failed and we simply skip this check. It won't
+ # switch to UNKNOWN, but will get stale.
+ raise MKCounterWrapped("Login into database failed")
- return (status, ", ".join(infos), perfdata)
+ data = parsed[item]
+ idle = data.get('total', 0)
+ running = data.get('running', 0)
+ total = idle + running
- # In case of missing information we assume that the login into
- # the database has failed and we simply skip this check. It won't
- # switch to UNKNOWN, but will get stale.
- raise MKCounterWrapped("Login into database failed")
+ for key, val in [
+ ("total", total),
+ ("running", running),
+ ]:
+ infotext = "%s: %s" % (key.title(), val)
+ warn, crit = params.get(key, (None, None))
+ state = 0
+ if crit is not None and val >= crit:
+ state = 2
+ elif warn is not None and val >= warn:
+ state = 1
+ if state:
+ infotext += " (warn/crit at %s/%s)" % (warn, crit)
+ yield state, infotext, [(key, val, warn, crit)]
check_info['postgres_sessions'] = {
Module: check_mk
Branch: master
Commit: be97eb61a545e17f94f3c7fc315ce52e24ce6868
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=be97eb61a545e1…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Wed May 9 12:59:46 2018 +0200
5925 FIX Use 10 min default timeout for Windows updates plugin
The plugin windows_updates.vbs has the tendency of running quite long.
The default execution timeout of 60s for Windows plugins is in most
cases not enough, resulting in the plugin being started every time
the Windows agent is contacted and always timing out after 60s without
delivering results. At its worst the plugin may cause high CPU load
repeated every minute.
Most users of windows_updates.vbs have been forced to configure a
timeout rule for the plugin in Agent Bakery. To simplify this process,
Agent Bakery now delivers windows_updates.vbs with a preconfigured
timeout of 10 minutes that should be enough for most users. The
already existing defaults for async execution and cache_age of 4 hours
were preserved.
---
.werks/5925 | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/.werks/5925 b/.werks/5925
new file mode 100644
index 0000000..448c0e1
--- /dev/null
+++ b/.werks/5925
@@ -0,0 +1,24 @@
+Title: Use 10 min default timeout for Windows updates plugin
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cee
+Version: 1.6.0i1
+Date: 1525863190
+Class: fix
+
+The plugin windows_updates.vbs has the tendency of running quite long.
+The default execution timeout of 60s for Windows plugins is in most
+cases not enough, resulting in the plugin being started every time
+the Windows agent is contacted and always timing out after 60s without
+delivering results. At its worst the plugin may cause high CPU load
+repeated every minute.
+
+Most users of windows_updates.vbs have been forced to configure a
+timeout rule for the plugin in Agent Bakery. To simplify this process,
+Agent Bakery now delivers windows_updates.vbs with a preconfigured
+timeout of 10 minutes that should be enough for most users. The
+already existing defaults for async execution and cache_age of 4 hours
+were preserved.
+
+