Module: check_mk
Branch: master
Commit: 51005873b8c351bf276e05052c10893f6c830b2b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=51005873b8c351…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Wed Feb 28 09:00:19 2018 +0100
Win-agent: split functions in SectionEventlog
* Let one function do one thing.
* Let one function do what it says it does and not 5 other things.
* Reduce complexity and improve readabilty by splitting functions.
---
agents/windows/build_version | 2 +-
agents/windows/sections/SectionEventlog.cc | 62 ++++++++++++++++++++----------
agents/windows/sections/SectionEventlog.h | 1 +
3 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 26770e3..4471739 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3134
+3136
diff --git a/agents/windows/sections/SectionEventlog.cc b/agents/windows/sections/SectionEventlog.cc
index e10bad2..be78919 100644
--- a/agents/windows/sections/SectionEventlog.cc
+++ b/agents/windows/sections/SectionEventlog.cc
@@ -110,6 +110,19 @@ inline std::ostream &operator<<(std::ostream &out,
return out << state.name << "|" << state.record_no;
}
+inline bool handleMissingLog(std::ostream &out,
+ const eventlog_file_state &state) {
+ bool missing = !state.newly_discovered;
+ if (missing) {
+ out << "[[[" << state.name << ":missing]]]\n";
+ }
+ return missing;
+}
+
+inline bool hasPreviousState(eventlog_file_state &state) {
+ return uint64limits::max() != state.record_no;
+}
+
} // namespace
eventlog_hint_t parseStateLine(const std::string &line) {
@@ -245,12 +258,8 @@ uint64_t SectionEventlog::outputEventlog(std::ostream &out, IEventLog &log,
std::tie(lastReadId, std::ignore) =
processEventLog(log, previouslyReadId, level, outputRecord);
}
- // Return the last entry number. We need to fetch the last record ID
- // separately if INT_MAX was used as seek offset and no new entries
- // were read.
- return (std::numeric_limits<uint64_t>::max() == lastReadId)
- ? log.getLastRecordId()
- : lastReadId;
+
+ return lastReadId;
}
// Keeps memory of an event log we have found. It
@@ -375,6 +384,29 @@ std::unique_ptr<IEventLog> SectionEventlog::openEventlog(
}
}
+void SectionEventlog::handleExistingLog(std::ostream &out,
+ eventlog_file_state &state) {
+ EventlogLevel level{EventlogLevel::Warn};
+ bool hideContext = false;
+ std::tie(level, hideContext) = readConfig(state);
+
+ if (level == EventlogLevel::Off) return;
+
+ if (const auto log = openEventlog(state.name, out)) {
+ if (hasPreviousState(state)) {
+ // The last processed eventlog record will serve as previous state
+ // (= saved offset) for the next call.
+ state.record_no =
+ outputEventlog(out, *log, state.record_no, level, hideContext);
+ } else {
+ // We just started monitoring this log. There was no previous state
+ // saved. Just save the last record, it will serve as saved previous
+ // state (= offset) for the next call.
+ state.record_no = log->getLastRecordId();
+ }
+ }
+}
+
// The output of this section is compatible with
// the logwatch agent for Linux and UNIX
bool SectionEventlog::produceOutputInner(std::ostream &out) {
@@ -389,22 +421,12 @@ bool SectionEventlog::produceOutputInner(std::ostream &out) {
readHintOffsets();
for (auto &state : _state) {
- if (!state.newly_discovered) // not here any more!
- out << "[[[" << state.name << ":missing]]]\n";
- else {
- EventlogLevel level{EventlogLevel::Warn};
- bool hideContext = false;
- std::tie(level, hideContext) = readConfig(state);
-
- if (level != EventlogLevel::Off) {
- const auto log = openEventlog(state.name, out);
- if (log) {
- state.record_no = outputEventlog(
- out, *log, state.record_no, level, hideContext);
- }
- }
+ if (!handleMissingLog(out, state)) {
+ handleExistingLog(out, state);
}
}
+ // The offsets are persisted in file after each run as we never know
+ // when the agent will be stopped.
saveEventlogOffsets(_env.eventlogStatefile());
}
_first_run = false;
diff --git a/agents/windows/sections/SectionEventlog.h b/agents/windows/sections/SectionEventlog.h
index 83490f0..27cd255 100644
--- a/agents/windows/sections/SectionEventlog.h
+++ b/agents/windows/sections/SectionEventlog.h
@@ -147,6 +147,7 @@ private:
const eventlog_file_state &state) const;
std::unique_ptr<IEventLog> openEventlog(const std::string &logname,
std::ostream &out) const;
+ void handleExistingLog(std::ostream &out, eventlog_file_state &state);
Configurable<bool> _send_initial;
Configurable<bool> _vista_api;
Module: check_mk
Branch: master
Commit: 24dd2fe61916e509332dcaaae6cff1f41526f1fd
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=24dd2fe61916e5…
Author: Andreas Umbreit <au(a)mathias-kettner.de>
Date: Mon Feb 26 16:18:46 2018 +0100
5274 FIX cmk-update-agent: prevent saving state file to wrong directory on windows
The Agent Updater would accidently save its cmk-update-agent.state to C:\etc if this directory was existant.
This could lead to an implausible update state. Virtually the Agent Updater would lose its registration information.
After an update or a manual reinstallation to a newly baked agent, a new registration might be required.
However, you might want to delete the cmk-update-agent.state located at C:\etc after the problem has been fixed.
Change-Id: Id0cb77eae411b6895be8d92c084ee6611f34563c
---
.werks/5274 | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/.werks/5274 b/.werks/5274
new file mode 100644
index 0000000..bcabab2
--- /dev/null
+++ b/.werks/5274
@@ -0,0 +1,15 @@
+Title: cmk-update-agent: prevent saving state file to wrong directory on windows
+Level: 1
+Component: agents
+Compatible: compat
+Edition: cee
+Version: 1.5.0i3
+Date: 1519657314
+Class: fix
+
+The Agent Updater would accidently save its cmk-update-agent.state to C:\etc if this directory was existant.
+This could lead to an implausible update state. Virtually the Agent Updater would lose its registration information.
+
+After an update or a manual reinstallation to a newly baked agent, a new registration might be required.
+
+However, you might want to delete the cmk-update-agent.state located at C:\etc after the problem has been fixed.
Module: check_mk
Branch: master
Commit: 97ac39ba934a87457a82a79fb26992705d3e85a6
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=97ac39ba934a87…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Feb 27 09:43:51 2018 +0100
5870 FIX Removed PYTHONPATH from site environment
The PYTHONPATH environment variable which was set by omd and .profile for all processes
in the site was confusing external Python based tools like for example gdb or the command
not found helpers of Ubuntu. This resulted in confusing stack traces.
The PYTHONPATH needed to be set in previous versions to make the python environment know
about the site specific python module paths (lib/python, local/lib/python). These paths
are now set using standard mechanisms of python (lib/python2.7/sitecustomize.py).
Change-Id: Ia9fefa38efa8f9e3bac0e51b5253defb754463a8
---
.werks/5870 | 16 ++++++++++++
omd/packages/maintenance/merge-crontabs | 1 -
omd/packages/mod_python/.f12 | 3 +--
omd/packages/mod_python/Makefile | 1 -
.../patches/0004-omd-add-python-path.dif | 30 ----------------------
omd/packages/omd/omd | 1 -
omd/packages/omd/skel/.profile | 1 -
omd/packages/python/Makefile | 1 +
omd/packages/python/sitecustomize.py | 18 +++++++++++++
9 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/.werks/5870 b/.werks/5870
new file mode 100644
index 0000000..e75c6a1
--- /dev/null
+++ b/.werks/5870
@@ -0,0 +1,16 @@
+Title: Removed PYTHONPATH from site environment
+Level: 1
+Component: omd
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1519720796
+Class: fix
+
+The PYTHONPATH environment variable which was set by omd and .profile for all processes
+in the site was confusing external Python based tools like for example gdb or the command
+not found helpers of Ubuntu. This resulted in confusing stack traces.
+
+The PYTHONPATH needed to be set in previous versions to make the python environment know
+about the site specific python module paths (lib/python, local/lib/python). These paths
+are now set using standard mechanisms of python (lib/python2.7/sitecustomize.py).
diff --git a/omd/packages/maintenance/merge-crontabs b/omd/packages/maintenance/merge-crontabs
index 4e5f463..e176cbe 100755
--- a/omd/packages/maintenance/merge-crontabs
+++ b/omd/packages/maintenance/merge-crontabs
@@ -23,7 +23,6 @@ BASH_ENV=%(omd_root)s/.profile
sys.stdout.write("OMD_ROOT=%s\n" % os.environ['OMD_ROOT'])
sys.stdout.write("OMD_SITE=%s\n" % os.environ['OMD_SITE'])
sys.stdout.write("PATH=%s\n" % os.environ['PATH'])
-sys.stdout.write("PYTHONPATH=%s\n" % os.environ['PYTHONPATH'])
sys.stdout.write("MAILTO=\"%s\"\n" % omd_config.get('CONFIG_ADMIN_MAIL', ''))
sys.stdout.write("# ------------------------------------------------------------\n")
diff --git a/omd/packages/mod_python/.f12 b/omd/packages/mod_python/.f12
index 3104327..a9216ef 100755
--- a/omd/packages/mod_python/.f12
+++ b/omd/packages/mod_python/.f12
@@ -5,7 +5,6 @@ SITE=${SITE:-$(cat ../../../.site 2>/dev/null || true)}
SITE=${SITE:-$(omd sites --bare | head -n 1)}
ROOT=/omd/sites/$SITE
-echo '#define OMD_VERSION "$(omd versions | grep default | cut -d' ' -f1)"' > mod_python-*/src/omd_version.h
-make -C mod_python-* clean all
+make -C mod_python-3.3.1 clean all
sudo make install OMD_ROOT=$ROOT
sudo omd restart $SITE apache
diff --git a/omd/packages/mod_python/Makefile b/omd/packages/mod_python/Makefile
index b54a2fa..4e8fd74 100644
--- a/omd/packages/mod_python/Makefile
+++ b/omd/packages/mod_python/Makefile
@@ -31,7 +31,6 @@ build: check-python
export LD_LIBRARY_PATH="$(PACKAGE_PYTHON_LD_LIBRARY_PATH)" ; \
cd $(DIR) ; \
./configure $(CONFIGUREOPTS) ; \
- echo '#define OMD_VERSION "$(OMD_VERSION)"' > src/omd_version.h ; \
$(MAKE) all
install:
diff --git a/omd/packages/mod_python/patches/0004-omd-add-python-path.dif b/omd/packages/mod_python/patches/0004-omd-add-python-path.dif
deleted file mode 100644
index 4f34132..0000000
--- a/omd/packages/mod_python/patches/0004-omd-add-python-path.dif
+++ /dev/null
@@ -1,30 +0,0 @@
---- mod_python-3.3.1/src/mod_python.c.orig 2006-11-09 07:21:23.000000000 +0100
-+++ mod_python-3.3.1/src/mod_python.c 2013-01-16 14:08:54.453232213 +0100
-@@ -26,6 +26,7 @@
- */
-
- #include "mod_python.h"
-+#include "omd_version.h"
-
- /* Server object for main server as supplied to python_init(). */
- static server_rec *main_server = NULL;
-@@ -103,6 +104,19 @@
- * >>> <initstring>
- * in the __main__ module to start up Python.
- */
-+
-+ /*
-+ * This has to be called before PyImport_ImportModule(MODULENAME) because
-+ * this extends the python path with the path to the OMD related mod_python
-+ * module. Without this patch there might occur several problem related to
-+ * duplicate imports of modules where some modules are located in the local/
-+ * hiearchy in OMD.
-+ *
-+ * FYI: MODULENAME is "mod_python.apache".
-+ */
-+ PyObject *sysPath = PySys_GetObject("path");
-+ PyObject *path = PyString_FromString("/omd/versions/" OMD_VERSION "/lib/python");
-+ int result = PyList_Insert(sysPath, 0, path);
-
- if (! ((m = PyImport_ImportModule(MODULENAME)))) {
- PyObject *path;
diff --git a/omd/packages/omd/omd b/omd/packages/omd/omd
index 8d9c7d3..4267038 100644
--- a/omd/packages/omd/omd
+++ b/omd/packages/omd/omd
@@ -2319,7 +2319,6 @@ def set_environment():
putenv("LD_LIBRARY_PATH", "%s/local/lib:%s/lib" % (g_sitedir, g_sitedir))
putenv("HOME", g_sitedir)
- putenv("PYTHONPATH", "%s/local/lib/python:%s/lib/python" % (g_sitedir, g_sitedir))
# allow user to define further environment variable in ~/etc/environment
envfile = g_sitedir + "/etc/environment"
diff --git a/omd/packages/omd/skel/.profile b/omd/packages/omd/skel/.profile
index 7ee3d55..86d8a2c 100644
--- a/omd/packages/omd/skel/.profile
+++ b/omd/packages/omd/skel/.profile
@@ -11,7 +11,6 @@ export PATH="$OMD_ROOT/lib/perl5/bin:$PATH"
export MODULEBUILDRC="$OMD_ROOT/.modulebuildrc"
export PERL_MM_OPT=INSTALL_BASE="$OMD_ROOT/local/lib/perl5/"
export MANPATH="$OMD_ROOT/share/man:$MANPATH"
-export PYTHONPATH="$OMD_ROOT/local/lib/python:$OMD_ROOT/lib/python"
export MAILRC="$OMD_ROOT/etc/mail.rc"
# Make the python requests module trust the CAs configured in Check_MK
diff --git a/omd/packages/python/Makefile b/omd/packages/python/Makefile
index 872f851..fcbba64 100644
--- a/omd/packages/python/Makefile
+++ b/omd/packages/python/Makefile
@@ -81,6 +81,7 @@ install: bin/gcc bin/g++
$(DESTDIR)$(OMD_ROOT)/bin/pydoc \
$(DESTDIR)$(OMD_ROOT)/bin/python2.7-config \
$(DESTDIR)$(OMD_ROOT)/bin/2to3
+ install -m 644 sitecustomize.py $(DESTDIR)$(OMD_ROOT)/lib/python2.7/
skel:
diff --git a/omd/packages/python/sitecustomize.py b/omd/packages/python/sitecustomize.py
new file mode 100644
index 0000000..6a6e6d6
--- /dev/null
+++ b/omd/packages/python/sitecustomize.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+# Make the site python know about the Check_MK specific python module paths
+
+import sys, os
+
+# Set the Check_MK version specific python module directory. This is
+# the location for the extra python modules shipped with Check_MK.
+version_path = os.path.dirname(os.path.dirname(sys.executable))
+sys.path.insert(0, version_path + "/lib/python")
+
+# Regular use case: When "omd" is being executed as root, we don't know
+# anything about the site -> Only set the version specific directory.
+omd_root = os.environ.get("OMD_ROOT")
+if omd_root:
+ # Set the site local python module directory. This is the place
+ # for extension modules of the user, for example installed manually
+ # or via pip.
+ sys.path.insert(0, omd_root + "/local/lib/python")
Module: check_mk
Branch: master
Commit: 82c34f5a93f4b1d7be7dd227413bb571e1bf875b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=82c34f5a93f4b1…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Feb 27 09:12:07 2018 +0100
Unconditionally import SNMP modules.
This saves only <200ms on startup when --snmptrap is not used, which is
basically nothing compared to loading the rest of the modules, the
configuration, and the status file. Furthermore, it complicates two things:
Extracting global statements into a main() function and type checking via
mypy. Both things could be worked around somehow, but this wouldn't exactly
result in the kind of code to be proud of... :-}
Change-Id: I5743ab999f02505c80f01e802dbcbf72bd0f2ede
---
bin/mkeventd | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index 3389cb7..c4b0df7 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -49,6 +49,19 @@ import traceback
import json
import pathlib2 as pathlib
+# Needed for receiving traps
+from pysnmp.entity import engine as snmp_engine
+from pysnmp.entity import config as snmp_config
+from pysnmp.entity.rfc3413 import ntfrcv as snmp_ntfrcv
+from pysnmp.proto.api import v2c as snmp_v2c, v1 as snmp_v1
+
+# Needed for trap translation
+from pysnmp.smi.builder import MibBuilder, DirMibSource
+from pysnmp.smi.view import MibViewController
+from pysnmp.smi.rfc1902 import ObjectType, ObjectIdentity
+from pysnmp.smi.error import SmiError
+from pyasn1.error import ValueConstraintError
+
import cmk
import cmk.ec.settings
import cmk.log
@@ -5037,20 +5050,6 @@ if __name__ == "__main__":
cmk.log.open_log(sys.stderr)
cmk.log.set_verbosity(settings.options.verbosity)
- if settings.options.snmptrap_udp is not None:
- # Needed for receiving traps
- from pysnmp.entity import engine as snmp_engine
- from pysnmp.entity import config as snmp_config
- from pysnmp.entity.rfc3413 import ntfrcv as snmp_ntfrcv
- from pysnmp.proto.api import v2c as snmp_v2c, v1 as snmp_v1
-
- # Needed for trap translation
- from pysnmp.smi.builder import MibBuilder, DirMibSource
- from pysnmp.smi.view import MibViewController
- from pysnmp.smi.rfc1902 import ObjectType, ObjectIdentity
- from pysnmp.smi.error import SmiError
- from pyasn1.error import ValueConstraintError
-
settings.paths.log_file.value.parent.mkdir(parents=True, exist_ok=True)
if not settings.options.foreground:
cmk.log.open_log(str(settings.paths.log_file.value))