Module: check_mk
Branch: master
Commit: d3e0eb5c74e8b6336987fad63b65cdef1a626a24
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d3e0eb5c74e8b6…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Wed Feb 28 11:42:32 2018 +0100
Win-agent: load eventlog offsets immediately
Reading eventlog offsets is not dependent on configuration, so it can be
done immediately when initalizing SectionEventlog. There is no need to
trigged it separately through emitConfigLoaded.
---
agents/windows/build_version | 2 +-
agents/windows/sections/SectionEventlog.cc | 38 ++++++++++++++----------------
agents/windows/sections/SectionEventlog.h | 5 +---
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 4471739..46b6da4 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3136
+3138
diff --git a/agents/windows/sections/SectionEventlog.cc
b/agents/windows/sections/SectionEventlog.cc
index be78919..2e5b6a7 100644
--- a/agents/windows/sections/SectionEventlog.cc
+++ b/agents/windows/sections/SectionEventlog.cc
@@ -123,6 +123,22 @@ inline bool hasPreviousState(eventlog_file_state &state) {
return uint64limits::max() != state.record_no;
}
+eventlog_hints_t loadEventlogOffsets(const std::string &statefile,
+ Logger *logger) {
+ eventlog_hints_t hints;
+ std::ifstream ifs(statefile);
+ std::string line;
+ while (std::getline(ifs, line)) {
+ try {
+ hints.push_back(parseStateLine(line));
+ } catch (const StateParseError &e) {
+ Error(logger) << e.what();
+ }
+ }
+
+ return hints;
+}
+
} // namespace
eventlog_hint_t parseStateLine(const std::string &line) {
@@ -187,28 +203,14 @@ SectionEventlog::SectionEventlog(Configuration &config, Logger
*logger,
: Section("logwatch", "logwatch", config.getEnvironment(),
logger, winapi)
, _send_initial(config, "logwatch", "sendall", false, winapi)
, _vista_api(config, "logwatch", "vista_api", false, winapi)
- , _config(config, "logwatch", "logname", winapi) {
+ , _config(config, "logwatch", "logname", winapi)
+ , _hints(loadEventlogOffsets(_env.eventlogStatefile(), logger)) {
// register a second key-name
config.reg("logwatch", "logfile", &_config);
}
SectionEventlog::~SectionEventlog() {}
-void SectionEventlog::loadEventlogOffsets(const std::string &statefile) {
- if (!_records_loaded) {
- std::ifstream ifs(statefile);
- std::string line;
- while (std::getline(ifs, line)) {
- try {
- _hints.push_back(parseStateLine(line));
- } catch (const StateParseError &e) {
- Error(_logger) << e.what();
- }
- }
- _records_loaded = true;
- }
-}
-
void SectionEventlog::saveEventlogOffsets(const std::string &statefile) {
std::ofstream ofs(statefile);
@@ -332,10 +334,6 @@ bool SectionEventlog::find_eventlogs(std::ostream &out) {
return success;
}
-void SectionEventlog::postprocessConfig() {
- loadEventlogOffsets(_env.eventlogStatefile());
-}
-
void SectionEventlog::readHintOffsets() {
// Special handling on startup (first_run)
// The last processed record number of each eventlog is stored in the
diff --git a/agents/windows/sections/SectionEventlog.h
b/agents/windows/sections/SectionEventlog.h
index 27cd255..e4d6415 100644
--- a/agents/windows/sections/SectionEventlog.h
+++ b/agents/windows/sections/SectionEventlog.h
@@ -129,8 +129,6 @@ public:
const WinApiAdaptor &winapi);
virtual ~SectionEventlog();
- virtual void postprocessConfig() override;
-
protected:
virtual bool produceOutputInner(std::ostream &out) override;
@@ -140,7 +138,6 @@ private:
bool hideContext);
void registerEventlog(const char *logname);
bool find_eventlogs(std::ostream &out);
- void loadEventlogOffsets(const std::string &statefile);
void saveEventlogOffsets(const std::string &statefile);
void readHintOffsets();
std::pair<EventlogLevel, bool> readConfig(
@@ -152,7 +149,7 @@ private:
Configurable<bool> _send_initial;
Configurable<bool> _vista_api;
EventlogConfigurable _config;
- eventlog_hints_t _hints;
+ const eventlog_hints_t _hints;
eventlog_state_t _state;
bool _records_loaded = false;
bool _first_run = true;