Module: check_mk
Branch: master
Commit: 2128a8ec00fb469ac485866c4b82f6f63c283e17
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2128a8ec00fb46…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Tue Mar 13 14:41:37 2018 +0100
Win-agent: const correctness fixes
Make _show_header and _nested members immutable. They are known at
(Section) object initialization time, so there is no real need to change
them afterwards.
---
agents/windows/Section.cc | 10 +++-------
agents/windows/Section.h | 9 +++------
agents/windows/SectionManager.cc | 26 ++++++++++++--------------
agents/windows/build_version | 2 +-
agents/windows/sections/SectionGroup.cc | 15 +++++----------
agents/windows/sections/SectionGroup.h | 6 +++---
agents/windows/sections/SectionPluginGroup.cc | 6 +-----
agents/windows/sections/SectionSkype.cc | 3 +--
agents/windows/sections/SectionSpool.cc | 4 +---
9 files changed, 30 insertions(+), 51 deletions(-)
diff --git a/agents/windows/Section.cc b/agents/windows/Section.cc
index d11ca5a..7583eef 100644
--- a/agents/windows/Section.cc
+++ b/agents/windows/Section.cc
@@ -52,17 +52,13 @@ double current_time(const WinApiAdaptor &winapi) {
Section::Section(const std::string &outputName, const std::string &configName,
const Environment &env, Logger *logger,
- const WinApiAdaptor &winapi)
+ const WinApiAdaptor &winapi, bool show_header /* = true */)
: _outputName(outputName)
, _configName(configName)
, _env(env)
, _logger(logger)
- , _winapi(winapi) {}
-
-Section *Section::withHiddenHeader(bool hidden) {
- _show_header = !hidden;
- return this;
-}
+ , _winapi(winapi)
+ , _show_header(show_header) {}
Section *Section::withRealtimeSupport() {
_realtime_support = true;
diff --git a/agents/windows/Section.h b/agents/windows/Section.h
index 57ccf94..53ac129 100644
--- a/agents/windows/Section.h
+++ b/agents/windows/Section.h
@@ -47,12 +47,10 @@ double current_time(const WinApiAdaptor &winapi);
} // namespace section_helpers
class Section {
- friend class SectionGroup;
-
public:
Section(const std::string &outputName, const std::string &configName,
- const Environment &env, Logger *logger,
- const WinApiAdaptor &winapi);
+ const Environment &env, Logger *logger, const WinApiAdaptor &winapi,
+ bool show_header = true);
virtual ~Section() = default;
@@ -61,7 +59,6 @@ public:
return this;
}
- Section *withHiddenHeader(bool hidden = true);
Section *withRealtimeSupport();
virtual void postprocessConfig() {}
@@ -101,7 +98,7 @@ protected:
const WinApiAdaptor &_winapi;
private:
- bool _show_header{true};
+ const bool _show_header;
char _separator{' '};
bool _realtime_support{false};
};
diff --git a/agents/windows/SectionManager.cc b/agents/windows/SectionManager.cc
index 6ab5d47..c4620c8 100644
--- a/agents/windows/SectionManager.cc
+++ b/agents/windows/SectionManager.cc
@@ -154,19 +154,18 @@ void SectionManager::loadStaticSections(Configuration &config,
->withObject(L"Win32_PerfRawData_NETFramework_NETCLRMemory")
->withToggleIfMissing());
- addSection(
- (new SectionGroup("wmi_cpuload", "wmi_cpuload", _env,
_logger, _winapi))
- ->withToggleIfMissing()
- ->withNestedSubtables()
- ->withSubSection(
- (new SectionWMI("system_perf", "system_perf", _env,
_logger,
- _winapi))
- ->withObject(L"Win32_PerfRawData_PerfOS_System"))
- ->withSubSection(
- (new SectionWMI("computer_system", "computer_system",
_env,
- _logger, _winapi))
- ->withObject(L"Win32_ComputerSystem"))
- ->withSeparator(','));
+ addSection((new SectionGroup("wmi_cpuload", "wmi_cpuload", _env,
_logger,
+ _winapi, true, true))
+ ->withToggleIfMissing()
+ ->withSubSection(
+ (new SectionWMI("system_perf", "system_perf",
_env,
+ _logger, _winapi))
+
->withObject(L"Win32_PerfRawData_PerfOS_System"))
+ ->withSubSection(
+ (new SectionWMI("computer_system",
"computer_system",
+ _env, _logger, _winapi))
+ ->withObject(L"Win32_ComputerSystem"))
+ ->withSeparator(','));
addSection(
(new SectionGroup("msexch", "msexch", _env, _logger,
_winapi))
@@ -207,7 +206,6 @@ void SectionManager::loadStaticSections(Configuration &config,
_winapi))
->withObject(
L"Win32_PerfRawData_MSExchangeRpcClientAccess_MSExchangeRpcClientAccess"))
- ->withHiddenHeader()
->withSeparator(','));
addSection(new SectionSkype(_env, _logger, _winapi));
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 98ee87f..01e0503 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3166
+3168
diff --git a/agents/windows/sections/SectionGroup.cc
b/agents/windows/sections/SectionGroup.cc
index 1103dde..db55929 100644
--- a/agents/windows/sections/SectionGroup.cc
+++ b/agents/windows/sections/SectionGroup.cc
@@ -28,10 +28,11 @@
SectionGroup::SectionGroup(const std::string &outputName,
const std::string &configName,
const Environment &env, Logger *logger,
- const WinApiAdaptor &winapi)
- : Section(outputName, configName, env, logger, winapi) {
- withHiddenHeader();
-}
+ const WinApiAdaptor &winapi,
+ bool nested /* = false */,
+ bool show_header /* = false */)
+ : Section(outputName, configName, env, logger, winapi, show_header)
+ , _nested(nested) {}
SectionGroup *SectionGroup::withSubSection(Section *section) {
_subsections.push_back(std::unique_ptr<Section>(section));
@@ -48,12 +49,6 @@ SectionGroup *SectionGroup::withToggleIfMissing() {
return this;
}
-SectionGroup *SectionGroup::withNestedSubtables() {
- withHiddenHeader(false);
- _nested = true;
- return this;
-}
-
bool SectionGroup::produceOutputInner(std::ostream &out, const
std::optional<std::string> &remoteIP) {
Debug(_logger) << "SectionGroup::produceOutputInner";
time_t now = time(nullptr);
diff --git a/agents/windows/sections/SectionGroup.h
b/agents/windows/sections/SectionGroup.h
index 42350f0..08c0b1b 100644
--- a/agents/windows/sections/SectionGroup.h
+++ b/agents/windows/sections/SectionGroup.h
@@ -43,8 +43,8 @@ class SectionGroup : public Section {
public:
SectionGroup(const std::string &outputName, const std::string &configName,
const Environment &env, Logger *logger,
- const WinApiAdaptor &winapi);
- SectionGroup *withNestedSubtables();
+ const WinApiAdaptor &winapi, bool nested = false, bool show_header =
false);
+
/**
* add a section that will be printed as part of this group
**/
@@ -67,7 +67,7 @@ private:
std::vector<std::unique_ptr<Section>> _dependent_subsections;
bool _toggle_if_missing{false};
bool _fail_if_missing{false};
- bool _nested{false};
+ const bool _nested;
time_t _disabled_until{0};
};
diff --git a/agents/windows/sections/SectionPluginGroup.cc
b/agents/windows/sections/SectionPluginGroup.cc
index b3a2cd9..d58d838 100644
--- a/agents/windows/sections/SectionPluginGroup.cc
+++ b/agents/windows/sections/SectionPluginGroup.cc
@@ -376,7 +376,7 @@ SectionPluginGroup::SectionPluginGroup(
script_statistics_t &script_statistics, Logger *logger,
const WinApiAdaptor &winapi, const std::string &user)
: Section(typeToSection(type), typeToSection(type), config.getEnvironment(),
- logger, winapi)
+ logger, winapi, type != PLUGIN) // plugin -> no collective header
, _path(path)
, _type(type)
, _user(user)
@@ -390,10 +390,6 @@ SectionPluginGroup::SectionPluginGroup(
, _retry_count(config, typeToSection(type), "retry_count", _winapi)
, _execution_mode(config, typeToSection(type), "execution", _winapi)
, _script_statistics(script_statistics) {
- if (type == PLUGIN) {
- // plugins don't have a "collective" header
- withHiddenHeader();
- }
}
SectionPluginGroup::~SectionPluginGroup() { _containers.clear(); }
diff --git a/agents/windows/sections/SectionSkype.cc
b/agents/windows/sections/SectionSkype.cc
index b986f56..b6bdcf7 100644
--- a/agents/windows/sections/SectionSkype.cc
+++ b/agents/windows/sections/SectionSkype.cc
@@ -30,10 +30,9 @@
SectionSkype::SectionSkype(const Environment &env, Logger *logger,
const WinApiAdaptor &winapi)
- : SectionGroup("skype", "skype", env, logger, winapi)
+ : SectionGroup("skype", "skype", env, logger, winapi, true, true)
, _nameNumberMap(_logger, _winapi) {
withToggleIfMissing();
- withNestedSubtables();
withSeparator(',');
for (const std::string &counterName :
diff --git a/agents/windows/sections/SectionSpool.cc
b/agents/windows/sections/SectionSpool.cc
index 8a74e47..f4b1fdb 100644
--- a/agents/windows/sections/SectionSpool.cc
+++ b/agents/windows/sections/SectionSpool.cc
@@ -34,9 +34,7 @@ namespace fs = std::experimental::filesystem;
SectionSpool::SectionSpool(const Environment &env, Logger *logger,
const WinApiAdaptor &winapi)
- : Section("spool", "spool", env, logger, winapi) {
- withHiddenHeader();
-}
+ : Section("spool", "spool", env, logger, winapi, false) {}
bool SectionSpool::produceOutputInner(std::ostream &out, const
std::optional<std::string> &) {
Debug(_logger) << "SectionSpool::produceOutputInner";