Module: check_mk
Branch: master
Commit: a3cbded2c40df3ad37efc15424fa0387ebee5cee
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a3cbded2c40df3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 17 10:31:39 2018 +0200
Revert "6063 FIX Special agents: Remove unreplaced macros from special agent command
lines"
This reverts commit 4b558182d2c0d2cf077fb039cddf78243030b7c2.
---
.werks/6063 | 20 --------------------
cmk_base/data_sources/programs.py | 8 --------
tests/unit/cmk_base/test_data_sources_unit.py | 20 --------------------
3 files changed, 48 deletions(-)
diff --git a/.werks/6063 b/.werks/6063
deleted file mode 100644
index 8187cb5..0000000
--- a/.werks/6063
+++ /dev/null
@@ -1,20 +0,0 @@
-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 8dd4f1f..e3f49e4 100644
--- a/cmk_base/data_sources/programs.py
+++ b/cmk_base/data_sources/programs.py
@@ -29,7 +29,6 @@ import signal
import subprocess
import cmk.paths
-import cmk.regex
import cmk_base.console as console
import cmk_base.config as config
@@ -137,7 +136,6 @@ class DSProgramDataSource(ProgramDataSource):
cmd = self._translate_legacy_macros(cmd)
cmd = self._translate_host_macros(cmd)
- cmd = self._cleanup_left_over_macros(cmd)
return cmd
@@ -159,12 +157,6 @@ 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 10de607..65503ef 100644
--- a/tests/unit/cmk_base/test_data_sources_unit.py
+++ b/tests/unit/cmk_base/test_data_sources_unit.py
@@ -34,23 +34,3 @@ 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'"