Module: check_mk
Branch: master
Commit: 37cc55f1008a2298d5dd00a4599249d23dec8045
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=37cc55f1008a22…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Thu Sep 21 13:04:13 2017 +0200
Clear some static variables in Windows agent
Change static variables to member variables in SectionEventlog. The
local static variables within member functions totally prevent unit
testing.
Change-Id: Id74816cf45411eb202c72b31909c7dea39e73362
---
agents/windows/sections/SectionEventlog.cc | 10 ++++------
agents/windows/sections/SectionEventlog.h | 2 ++
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/agents/windows/sections/SectionEventlog.cc
b/agents/windows/sections/SectionEventlog.cc
index e3735eb..f3db993 100644
--- a/agents/windows/sections/SectionEventlog.cc
+++ b/agents/windows/sections/SectionEventlog.cc
@@ -71,8 +71,7 @@ void SectionEventlog::parseStateLine(char *line) {
}
void SectionEventlog::loadEventlogOffsets(const std::string &statefile) {
- static bool records_loaded = false;
- if (!records_loaded) {
+ if (!_records_loaded) {
FILE *file = fopen(statefile.c_str(), "r");
if (file) {
char line[256];
@@ -81,7 +80,7 @@ void SectionEventlog::loadEventlogOffsets(const std::string
&statefile) {
}
fclose(file);
}
- records_loaded = true;
+ _records_loaded = true;
}
}
@@ -297,13 +296,12 @@ bool SectionEventlog::produceOutputInner(std::ostream &out) {
// been processed. When started, the eventlog
// is skipped to the end. Historic messages are
// not been processed.
- static bool first_run = true;
if (find_eventlogs(out)) {
// Special handling on startup (first_run)
// The last processed record number of each eventlog is stored in the
// file eventstate.txt
- if (first_run && !*_send_initial) {
+ if (_first_run && !*_send_initial) {
for (eventlog_file_state &state : _state) {
bool found_hint = false;
for (eventlog_hint_t *hint : _hints) {
@@ -345,6 +343,6 @@ bool SectionEventlog::produceOutputInner(std::ostream &out) {
}
saveEventlogOffsets(_env.eventlogStatefile());
}
- first_run = false;
+ _first_run = false;
return true;
}
diff --git a/agents/windows/sections/SectionEventlog.h
b/agents/windows/sections/SectionEventlog.h
index e557291..c702e2e 100644
--- a/agents/windows/sections/SectionEventlog.h
+++ b/agents/windows/sections/SectionEventlog.h
@@ -67,6 +67,8 @@ class SectionEventlog : public Section {
eventlog_hints_t _hints;
eventlog_state_t _state;
+ bool _records_loaded = false;
+ bool _first_run = true;
public:
SectionEventlog(Configuration &config, Logger *logger,