Module: check_mk
Branch: master
Commit: 6265266f866f04aeca275150d0a5a0befd957d2c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6265266f866f04…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Wed Apr 25 13:41:10 2018 +0200
5923 FIX Windows: section MRPE was incorrectly formatted
The output of section MRPE was incorrectly formatted. A null character
at the end of the output string caused the output to be cut abruptly
and missing a newline character before the following section header.
Broken by commit 6503810d95eddff68cd9c7faabe8d64c15c5cc02 that was
included in releases 1.5.0i3 and 1.5.0b1.
---
.werks/5923 | 16 ++++++++++++++++
agents/windows/build_version | 2 +-
agents/windows/it/test_section_mrpe.py | 27 +++++++++++++++++++--------
agents/windows/sections/SectionMRPE.cc | 10 ++++++----
4 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/.werks/5923 b/.werks/5923
new file mode 100644
index 0000000..b0197f0
--- /dev/null
+++ b/.werks/5923
@@ -0,0 +1,16 @@
+Title: Windows: section MRPE was incorrectly formatted
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1524656219
+Class: fix
+
+The output of section MRPE was incorrectly formatted. A null character
+at the end of the output string caused the output to be cut abruptly
+and missing a newline character before the following section header.
+Broken by commit d0ae246003d630f80ad5ff3fbe469552738141a9 that was
+included in releases 1.5.0i3 and 1.5.0b1.
+
+
diff --git a/agents/windows/build_version b/agents/windows/build_version
index c5f1662..0080ae0 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3250
+3252
diff --git a/agents/windows/it/test_section_mrpe.py
b/agents/windows/it/test_section_mrpe.py
index a55614e..73de0ac 100644
--- a/agents/windows/it/test_section_mrpe.py
+++ b/agents/windows/it/test_section_mrpe.py
@@ -11,6 +11,7 @@ from remote import (actual_output, assert_subprocess, config,
remote_ip,
class Globals(object):
section = 'mrpe'
+ alone = True
pluginname = 'check_crit.bat'
param = 'foobar'
checkname = 'Dummy'
@@ -25,9 +26,13 @@ def testfile():
return os.path.basename(__file__)
-(a)pytest.fixture
-def testconfig(config):
- config.set('global', 'sections', Globals.section)
+(a)pytest.fixture(params=['alone'one', 'with_systemtime'])
+def testconfig(request, config):
+ Globals.alone = request.param == 'alone'
+ if Globals.alone:
+ config.set('global', 'sections', Globals.section)
+ else:
+ config.set('global', 'sections', '%s systemtime' %
Globals.section)
config.set('global', 'crash_debug', 'yes')
config.add_section(Globals.section)
if Globals.newline < 0:
@@ -43,11 +48,17 @@ def testconfig(config):
@pytest.fixture
def expected_output():
drive = r'[A-Z]:%s' % re.escape(os.sep)
- return [
- re.escape(r'<<<%s>>>' % Globals.section),
- r'\(%s\) %s 2 CRIT - This check is always critical' %
- (Globals.pluginname, Globals.checkname)
- ]
+ expected = [
+ re.escape(r'<<<%s>>>' % Globals.section),
+ r'\(%s\) %s 2 CRIT - This check is always critical' %
+ (Globals.pluginname, Globals.checkname)
+ ]
+ if not Globals.alone:
+ expected += [
+ re.escape(r'<<<systemtime>>>'),
+ r'\d+'
+ ]
+ return expected
@pytest.fixture(
diff --git a/agents/windows/sections/SectionMRPE.cc
b/agents/windows/sections/SectionMRPE.cc
index e222702..a4a7334 100644
--- a/agents/windows/sections/SectionMRPE.cc
+++ b/agents/windows/sections/SectionMRPE.cc
@@ -104,8 +104,7 @@ bool SectionMRPE::produceOutputInner(std::ostream &out,
try {
ExternalCmd command(modified_command, _env, _logger, _winapi);
Debug(_logger) << "Script started -> collecting data";
- string buffer;
- buffer.resize(8192);
+ string buffer(8192, '\0');
char *buf_start = &buffer[0];
char *pos = &buffer[0];
while (command.exitCode() == STILL_ACTIVE) {
@@ -114,10 +113,13 @@ bool SectionMRPE::produceOutputInner(std::ostream &out,
pos += read;
_winapi.Sleep(10);
}
- command.readStdout(pos, buffer.size() - (pos - buf_start), false);
-
+ DWORD read = command.readStdout(
+ pos, buffer.size() - (pos - buf_start), false);
+ pos += read;
+ buffer.resize(pos - buf_start);
rtrim(buffer);
ltrim(buffer);
+
// replace newlines
std::transform(buffer.cbegin(), buffer.cend(), buffer.begin(),
[](char ch) {