Module: check_mk
Branch: master
Commit: 74786c1d9e1a5f3a7194bd78debbd73a3750203a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=74786c1d9e1a5f…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Mon Oct 2 15:27:31 2017 +0200
5378 FIX Make Windows section webservices backwards compatible
Version 1.4.0 'corrected' the naming of section wmi_webservices. Unfortunately,
this broke the backwards compatibility of old ini files that still call this
'webservices'. The fix maps the old name to the new one so that both old and new
ini files work. Moreover, the agent bakery was still writing ini files with the old name.
Now the agent bakery is also fixed.
Change-Id: Iecfe16c55a6fdfb0b47b1a939a30d11c4707bc92
---
.werks/5378 | 11 +++++++++++
agents/windows/Configurable.h | 15 +++++++++++----
agents/windows/SectionManager.cc | 21 ++++++++++++++++++---
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/.werks/5378 b/.werks/5378
new file mode 100644
index 0000000..e1bb0b6
--- /dev/null
+++ b/.werks/5378
@@ -0,0 +1,11 @@
+Title: Windows agent: Ensure backwards compatibility of section webservices
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cee
+Version: 1.5.0i1
+Date: 1506950547
+Class: fix
+
+Version 1.4.0 'corrected' the naming of section wmi_webservices. Unfortunately,
this broke the backwards compatibility of old ini files that still call this
'webservices'. The fix maps the old name to the new one so that both old and new
ini files work. Moreover, the agent bakery was still writing ini files with the old name.
Now the agent bakery is also fixed.
+
diff --git a/agents/windows/Configurable.h b/agents/windows/Configurable.h
index 3edc96e..936f273 100644
--- a/agents/windows/Configurable.h
+++ b/agents/windows/Configurable.h
@@ -203,17 +203,20 @@ template <typename ContainerT, typename BlockModeT =
BlockMode::Nop<ContainerT>,
typename AddModeT = AddMode::Append<ContainerT>>
class SplittingListConfigurable
: public ListConfigurable<ContainerT, BlockModeT, AddModeT> {
- char _split_char;
typedef ListConfigurable<ContainerT, BlockModeT, AddModeT> SuperT;
-
typedef typename ContainerT::value_type DataT;
+ typedef std::function<std::string(const std::string &)> MapFunction;
public:
SplittingListConfigurable(Configuration &config, const char *section,
const char *key, const WinApiAdaptor &winapi,
+ const MapFunction &mapFunction =
+ [](const std::string &s) { return s; },
char split_char = ' ')
- : SuperT(config, section, key, winapi), _split_char(split_char) {}
+ : SuperT(config, section, key, winapi)
+ , _mapFunction(mapFunction)
+ , _split_char(split_char) {}
virtual void feed(const std::string &key,
const std::string &value) override {
@@ -221,7 +224,7 @@ public:
std::stringstream str(value);
std::string item;
while (getline(str, item, _split_char)) {
- SuperT::feed(key, item);
+ SuperT::feed(key, _mapFunction(item));
}
}
@@ -233,6 +236,10 @@ public:
}
out << "\n";
}
+
+private:
+ const MapFunction _mapFunction;
+ char _split_char;
};
#endif // Configurable_h
diff --git a/agents/windows/SectionManager.cc b/agents/windows/SectionManager.cc
index 6e27d32..534430f 100644
--- a/agents/windows/SectionManager.cc
+++ b/agents/windows/SectionManager.cc
@@ -1,4 +1,5 @@
#include "SectionManager.h"
+#include <unordered_map>
#include "Configuration.h"
#include "Environment.h"
#include "sections/SectionCheckMK.h"
@@ -21,12 +22,26 @@
#include "sections/SectionWMI.h"
#include "sections/SectionWinperf.h"
+namespace {
+// Fix possible backwards incompatibility of section names by mapping
+// 'old' names to 'new' ones.
+std::string mapSectionName(const std::string §ionName) {
+ const std::unordered_map<std::string, std::string> mappedSectionNames = {
+ {"webservices", "wmi_webservices"}};
+ const auto it = mappedSectionNames.find(sectionName);
+ return it == mappedSectionNames.end() ? sectionName : it->second;
+}
+
+} // namespace
+
SectionManager::SectionManager(Configuration &config, Logger *logger,
const WinApiAdaptor &winapi)
: _ps_use_wmi(config, "ps", "use_wmi", false, winapi)
- , _enabled_sections(config, "global", "sections", winapi)
- , _disabled_sections(config, "global", "disabled_sections",
winapi)
- , _realtime_sections(config, "global", "realtime_sections",
winapi)
+ , _enabled_sections(config, "global", "sections", winapi,
mapSectionName)
+ , _disabled_sections(config, "global", "disabled_sections",
winapi,
+ mapSectionName)
+ , _realtime_sections(config, "global", "realtime_sections",
winapi,
+ mapSectionName)
, _script_local_includes(config, "local", "include", winapi)
, _script_plugin_includes(config, "plugin", "include", winapi)
, _winperf_counters(config, "winperf", "counters", winapi)