Module: check_mk
Branch: master
Commit: 9bbcd0c0e661c32769ad3d0ae6db22bb67d873f0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9bbcd0c0e661c3…
Author: Sergey Kipnis <sk(a)mathias-kettner.de>
Date: Wed Apr 17 14:17:42 2019 +0200
[CMK-1970] - timeout for plugins set to 60
- lesser refactoring related to clang-format and headers
- a bit more detailed and valid logging
Change-Id: Iefe2b569ca09e6f03dac44c086dedce58521301a
---
agents/wnx/src/common/cfg_info.h | 34 ++++++++++++++-------------
agents/wnx/src/engine/cfg.h | 8 +++----
agents/wnx/src/engine/cma_core.cpp | 2 +-
agents/wnx/src/engine/eventlog/eventlogbase.h | 2 +-
agents/wnx/src/engine/groups.cpp | 20 +++++++---------
agents/wnx/src/engine/providers/plugins.cpp | 16 +++++--------
6 files changed, 37 insertions(+), 45 deletions(-)
diff --git a/agents/wnx/src/common/cfg_info.h b/agents/wnx/src/common/cfg_info.h
index acb134e..0b615f6 100644
--- a/agents/wnx/src/common/cfg_info.h
+++ b/agents/wnx/src/common/cfg_info.h
@@ -2,18 +2,14 @@
// Engine independent parameters
// No C++ file
#pragma once
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
#include <shlobj.h> // known path
#include <chrono>
#include <filesystem>
#include <string>
-#include "yaml-cpp/yaml.h"
-
#include "common/cfg_yaml.h"
+#include "yaml-cpp/yaml.h"
namespace XLOG {
// windows specific Event Log
@@ -36,6 +32,8 @@ enum EventClass {
} // namespace XLOG
+// in This section we have defaults for the configuration(YML/INI)
+// values are either plain ints or plain strings
namespace cma::cfg {
enum LogLevel { kLogBase = 0, kLogDebug = 1, kLogAll = 2 };
@@ -52,28 +50,32 @@ constexpr int kDefaultRealtimePort = 6559;
// #TODO CONFIRM VALUE:
constexpr int kMinimumCacheAge = 120;
-// #TODO CONFIRM VALUE:
+// Default Port for connection to client
constexpr uint16_t kMainPort = 6556;
-// #TODO CONFIRM VALUE:
-constexpr int kDefaultPluginTimeout = 11; // seconds
+// Default timeout for any plugin
+constexpr int kDefaultPluginTimeout = 60; // seconds
-// #TODO CONFIRM VALUE:
-constexpr int kDefaultWinPerfTimeout = 11; // seconds
+// Windows Wmi API timeout, decision from LWA
+constexpr int kDefaultWinPerfTimeout = 3; // seconds
-// #TODO CONFIRM VALUE:
+// #TODO Probably deprecated
constexpr int kDefaultAgentMaxWait = 15; // max time agent waits for a sections
-// #TODO CONFIRM VALUE:
-constexpr int kDefaultAgentMinWait = 5; // max time agent waits for a sections
+// This value is set when timeout was defined badly by ini/yml/user
+constexpr int kDefaultAgentMinWait = 10; // min safe timeout
-const char* const kDefaultLogFileName = "check_mk.log";
-const char* const kDefaultAppFileName = "check_mk_agent.exe";
-constexpr wchar_t kAppDataCompanyName[] = L"CheckMK";
+constexpr const char* const kDefaultLogFileName = "check_mk.log";
+constexpr const char* const kDefaultAppFileName = "check_mk_agent.exe";
constexpr char kDefaultEventLogName[] =
"CheckMK"; // name for windows event log
const wchar_t* const kAppDataAppName = L"Agent";
const wchar_t* const kDefaultConfigCacheFileName = L"check_mk.cached.yml";
+} // namespace cma::cfg
+
+// section with folder names, file names and some textual app defaults
+namespace cma::cfg {
+constexpr const wchar_t kAppDataCompanyName[] = L"CheckMK";
// defines default behavior of the main thread
constexpr bool IsOneShotMode() { return true; }
diff --git a/agents/wnx/src/engine/cfg.h b/agents/wnx/src/engine/cfg.h
index 38e45dc..18f41bd 100644
--- a/agents/wnx/src/engine/cfg.h
+++ b/agents/wnx/src/engine/cfg.h
@@ -6,13 +6,10 @@
#include "common/cfg_info.h"
#include "common/wtools.h"
-
-#include "yaml-cpp/yaml.h"
-
#include "logger.h"
-
#include "on_start.h"
#include "onlyfrom.h"
+#include "yaml-cpp/yaml.h"
namespace cma {
// set only when executable works as a service
@@ -965,7 +962,8 @@ public:
// API:
void loadFromMainConfig(const std::string GroupName);
- // #TODO gtest
+ // relative high level API to build intermediate data structures
+ // from raw data inside the class
CmdLineInfo buildCmdLine() const;
auto units() const {
diff --git a/agents/wnx/src/engine/cma_core.cpp b/agents/wnx/src/engine/cma_core.cpp
index b79e1ac..f86c698 100644
--- a/agents/wnx/src/engine/cma_core.cpp
+++ b/agents/wnx/src/engine/cma_core.cpp
@@ -610,7 +610,7 @@ std::vector<char> RunSyncPlugins(PluginMap& Plugins,
int& Count, int Timeout) {
if (entry.async()) continue;
- XLOG::d(XLOG_FUNC + " {}", entry.path().u8string());
+ XLOG::d.t(XLOG_FUNC + " {}", entry.path().u8string());
// C++ async black magic
results.emplace_back(std::async(
diff --git a/agents/wnx/src/engine/eventlog/eventlogbase.h
b/agents/wnx/src/engine/eventlog/eventlogbase.h
index e77f420..d2040b9 100644
--- a/agents/wnx/src/engine/eventlog/eventlogbase.h
+++ b/agents/wnx/src/engine/eventlog/eventlogbase.h
@@ -6,7 +6,7 @@
#include <memory>
#include <string>
-#include <fmt/format.h>
+#include "fmt/format.h"
#include "common/cfg_info.h"
#include "common/wtools.h"
diff --git a/agents/wnx/src/engine/groups.cpp b/agents/wnx/src/engine/groups.cpp
index 81c0a24..3d3e1a6 100644
--- a/agents/wnx/src/engine/groups.cpp
+++ b/agents/wnx/src/engine/groups.cpp
@@ -1,25 +1,19 @@
// Configuration Parameters for whole Agent
#include "stdafx.h"
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
#include <shellapi.h>
#include <shlobj.h> // known path
#include <filesystem>
#include <string>
+#include "cfg.h"
#include "common/cfg_info.h"
#include "common/wtools.h"
-
#include "tools/_raii.h" // on out
#include "tools/_tgt.h" // we need IsDebug
-
#include "yaml-cpp/yaml.h"
-#include "cfg.h"
-
namespace cma::cfg {
Global::Global() {
@@ -354,17 +348,19 @@ Plugins::CmdLineInfo Plugins::buildCmdLine() const {
files.erase(undefined, files.end());
// build command line
- for (const auto& f : files) {
- cli.cmd_line_ += L"\"";
- cli.cmd_line_ += f.c_str();
- cli.cmd_line_ += L"\" ";
+ for (const auto& file_name : files) {
+ cli.cmd_line_ += L"\"" + file_name + L"\" ";
}
if (cli.cmd_line_.empty()) {
- XLOG::l("Unexpected, but no plugins to execute");
+ XLOG::l("Unexpected, no plugins to execute");
return cli;
}
+
if (cli.cmd_line_.back() == L' ') cli.cmd_line_.pop_back();
+ XLOG::t.i("Expected to execute [{}] plugins '{}'", files.size(),
+ wtools::ConvertToUTF8(cli.cmd_line_));
+
return cli;
} // namespace cma::cfg
diff --git a/agents/wnx/src/engine/providers/plugins.cpp
b/agents/wnx/src/engine/providers/plugins.cpp
index abbaba1..e1288aa 100644
--- a/agents/wnx/src/engine/providers/plugins.cpp
+++ b/agents/wnx/src/engine/providers/plugins.cpp
@@ -2,25 +2,21 @@
// provides basic api to start and stop service
#include "stdafx.h"
+#include "providers/plugins.h"
+
#include <filesystem>
#include <regex>
#include <string>
#include <tuple>
-#include "fmt/format.h"
-
-#include "tools/_raii.h"
-#include "tools/_xlog.h"
-
-#include "common/wtools.h"
-
#include "cfg.h"
#include "cma_core.h"
+#include "common/wtools.h"
+#include "fmt/format.h"
#include "glob_match.h"
-
#include "logger.h"
-
-#include "providers/plugins.h"
+#include "tools/_raii.h"
+#include "tools/_xlog.h"
namespace cma::provider {