Module: check_mk
Branch: master
Commit: aba03cf7739664913fb35dfdb1dc8a8df8018a54
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aba03cf7739664…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Tue Jan 23 16:47:49 2018 +0100
5702 Allow spaces in Windows eventlog name
Add support for Windows eventlogs whose names contain spaces. Previously, such
eventlog names could not be handled as the first space-separated word was
interpreted to be the complete name.
---
.werks/5702 | 14 ++++++
agents/windows/build_version | 2 +-
agents/windows/sections/SectionEventlog.cc | 2 +-
agents/windows/sections/SectionEventlog.h | 21 +++++----
agents/windows/stringutil.cc | 3 +-
agents/windows/test/stringutilTest.cc | 69 +++++++++++++++++++++++++++++-
6 files changed, 98 insertions(+), 13 deletions(-)
diff --git a/.werks/5702 b/.werks/5702
new file mode 100644
index 0000000..a045f53
--- /dev/null
+++ b/.werks/5702
@@ -0,0 +1,14 @@
+Title: Allow spaces in Windows eventlog name
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i3
+Date: 1518165429
+Class: feature
+
+Add support for Windows eventlogs whose names contain spaces. Previously, such
+eventlog names could not be handled as the first space-separated word was
+interpreted to be the complete name.
+
+
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 09dcc41..64d570b 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3090
+3092
diff --git a/agents/windows/sections/SectionEventlog.cc
b/agents/windows/sections/SectionEventlog.cc
index 916769a..ab6b44f 100644
--- a/agents/windows/sections/SectionEventlog.cc
+++ b/agents/windows/sections/SectionEventlog.cc
@@ -285,7 +285,7 @@ uint64_t SectionEventlog::outputEventlog(std::ostream &out, const
char *logname,
void SectionEventlog::registerEventlog(const char *logname) {
// check if we already know this one...
for (auto &state : _state) {
- if (state.name.compare(logname) == 0) {
+ if (ci_equal(state.name, logname)) {
state.newly_discovered = true;
return;
}
diff --git a/agents/windows/sections/SectionEventlog.h
b/agents/windows/sections/SectionEventlog.h
index 75340ff..f2ae38b 100644
--- a/agents/windows/sections/SectionEventlog.h
+++ b/agents/windows/sections/SectionEventlog.h
@@ -78,10 +78,9 @@ class EventlogConfigurable
: public ListConfigurable<eventlog_config_t,
BlockMode::Nop<eventlog_config_t>,
AddMode::PriorityAppend<eventlog_config_t>> {
- typedef ListConfigurable<eventlog_config_t,
- BlockMode::Nop<eventlog_config_t>,
- AddMode::PriorityAppend<eventlog_config_t>>
- SuperT;
+ using SuperT =
+ ListConfigurable<eventlog_config_t, BlockMode::Nop<eventlog_config_t>,
+ AddMode::PriorityAppend<eventlog_config_t>>;
public:
EventlogConfigurable(Configuration &config, const char *section,
@@ -92,11 +91,15 @@ public:
const std::string &value) override {
eventlog_config_entry entry =
from_string<eventlog_config_entry>(_winapi, value);
- std::istringstream str(var);
- std::string key;
- getline(str, key, ' ');
- getline(str, entry.name, ' ');
- entry.vista_api = (key == "logname");
+ const auto tokens = tokenize(var, " ");
+
+ if (tokens.size() < 2) {
+ std::cerr << "Invalid eventlog logname entry: '" <<
var << "'"
+ << std::endl;
+ }
+
+ entry.name = join(std::next(tokens.cbegin()), tokens.cend(), " ");
+ entry.vista_api = (tokens[0] == "logname");
add(entry);
}
};
diff --git a/agents/windows/stringutil.cc b/agents/windows/stringutil.cc
index 67e5060..3b06e5e 100644
--- a/agents/windows/stringutil.cc
+++ b/agents/windows/stringutil.cc
@@ -150,7 +150,8 @@ bool ci_compare_pred(unsigned char lhs, unsigned char rhs) {
}
bool ci_equal(const std::string &lhs, const std::string &rhs) {
- return std::equal(lhs.begin(), lhs.end(), rhs.begin(), ci_compare_pred);
+ return std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend(),
+ ci_compare_pred);
}
bool globmatch(const char *pattern, const char *astring) {
diff --git a/agents/windows/test/stringutilTest.cc
b/agents/windows/test/stringutilTest.cc
index 56c4ecc..fa66535 100644
--- a/agents/windows/test/stringutilTest.cc
+++ b/agents/windows/test/stringutilTest.cc
@@ -13,10 +13,16 @@ TEST(wa_stringutilTest, tokenize_Eventlog_Application_state_valid) {
ASSERT_EQ(expected, tokenize(input, "\\|"));
}
+TEST(wa_stringutilTest, tokenize_wstring_Eventlog_Application_state_valid) {
+ const wstring input{L"Application|19881"};
+ const vector<wstring> expected{L"Application", L"19881"};
+ ASSERT_EQ(expected, tokenize(input, L"\\|"));
+}
+
TEST(wa_stringutilTest, tokenize_Eventlog_Application_state_missing_value) {
const string input{"Application|"};
const vector<string> expected{"Application"};
- ASSERT_EQ(expected, tokenize(input, "\\|"));
+ ASSERT_EQ(expected, tokenize(input, {"\\|"}));
}
TEST(wa_stringutilTest,
@@ -32,12 +38,43 @@ TEST(wa_stringutilTest, tokenize_logfile_state_valid) {
ASSERT_EQ(expected, tokenize(input, "\\|"));
}
+// Note intentional mixture of tabs and spaces.
TEST(wa_stringutilTest, tokenize_whitespace_separator) {
const string input{"This is an example sentence."};
const vector<string> expected{"This", "is", "an",
"example", "sentence."};
ASSERT_EQ(expected, tokenize(input, "\\s+"));
}
+// Note intentional mixture of tabs and spaces.
+TEST(wa_stringutilTest, tokenizePossiblyQuoted_no_quoted) {
+ const string input{"This is an example sentence."};
+ const vector<string> expected{"This", "is", "an",
"example", "sentence."};
+ ASSERT_EQ(expected, tokenizePossiblyQuoted(input));
+}
+
+// Note intentional mixture of tabs and spaces.
+TEST(wa_stringutilTest, tokenizePossiblyQuoted_double_quoted) {
+ const string input{"\"This is an\" \"example
sentence.\""};
+ const vector<string> expected{"\"This is an\"",
+ "\"example sentence.\""};
+ ASSERT_EQ(expected, tokenizePossiblyQuoted(input));
+}
+
+// Note intentional mixture of tabs and spaces.
+TEST(wa_stringutilTest, tokenizePossiblyQuoted_single_quoted) {
+ const string input{"'This is an' 'example sentence.'"};
+ const vector<string> expected{"'This is an'",
+ "'example sentence.'"};
+ ASSERT_EQ(expected, tokenizePossiblyQuoted(input));
+}
+
+// Note intentional mixture of tabs and spaces.
+TEST(wa_stringutilTest, tokenizePossiblyQuoted_mixed_double_single_non_quoted) {
+ const string input{"This 'is an' \"example
sentence.\""};
+ const vector<string> expected{"This", "'is an'",
"\"example sentence.\""};
+ ASSERT_EQ(expected, tokenizePossiblyQuoted(input));
+}
+
TEST(wa_stringutilTest, join_strings_space_separator) {
const vector<string> input{"This", "is", "an",
"example", "sentence."};
const string expected{"This is an example sentence."};
@@ -152,3 +189,33 @@ TEST(wa_stringutilTest,
isPathRelative_relative_with_whitespace_quotes_unix) {
const std::string path{"\"foo bar/baz\""};
ASSERT_TRUE(isPathRelative(path)) << path << " recognized as
relative";
}
+
+TEST(wa_stringutilTest, ci_equal__equal_cases_equal) {
+ const std::string s1{"asdfgh"};
+ const std::string s2{s1};
+ ASSERT_TRUE(ci_equal(s1, s2));
+}
+
+TEST(wa_stringutilTest, ci_equal__equal_cases_unequal) {
+ const std::string s1{"asdfgh§$"};
+ const std::string s2{"aSdFgH§$"};
+ ASSERT_TRUE(ci_equal(s1, s2));
+}
+
+TEST(wa_stringutilTest, ci_equal__unequal_first_shorter) {
+ const std::string s1{"asdfgh"};
+ const std::string s2{"aSdFgH§$"};
+ ASSERT_FALSE(ci_equal(s1, s2));
+}
+
+TEST(wa_stringutilTest, ci_equal__unequal_first_longer) {
+ const std::string s1{"asdfgh§$"};
+ const std::string s2{"aSdFgH"};
+ ASSERT_FALSE(ci_equal(s1, s2));
+}
+
+TEST(wa_stringutilTest, ci_equal__unequal) {
+ const std::string s1{"asdfg$"};
+ const std::string s2{"aSdFgH"};
+ ASSERT_FALSE(ci_equal(s1, s2));
+}