Module: check_mk
Branch: master
Commit: f819ad9db10549d91745ad6100d382a1f66df9bc
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f819ad9db10549…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 1 10:38:44 2019 +0100
Cleaned up logger setup functions a bit
Change-Id: I3031574a7160fb0b3d28f5fcf367401ed5172312
---
cmk/utils/log.py | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/cmk/utils/log.py b/cmk/utils/log.py
index 637d898..16c4ec1 100644
--- a/cmk/utils/log.py
+++ b/cmk/utils/log.py
@@ -124,7 +124,7 @@ def get_formatter(format_str="%(asctime)s [%(levelno)s] [%(name)s %(process)d] %
return _logging.Formatter(format_str)
-def setup_console_logging():
+def setup_console_logging(stream=None, formatter=None):
"""This method enables all log messages to be written to the console
without any additional information like date/time, logger-name. Just
the log line is written.
@@ -132,13 +132,13 @@ def setup_console_logging():
This can be used for existing command line applications which were
using sys.stdout.write() or print() before.
"""
+ if stream is None:
+ stream = sys.stdout
- handler = _logging.StreamHandler(stream=sys.stdout)
+ if formatter is None:
+ formatter = get_formatter("%(message)s")
- formatter = _logging.Formatter("%(message)s")
- handler.setFormatter(formatter)
-
- logger.addHandler(handler)
+ setup_logging_handler(stream, formatter)
def open_log(log_file_path, fallback_to=None):
@@ -164,13 +164,16 @@ def open_log(log_file_path, fallback_to=None):
return logfile
-def setup_logging_handler(stream):
+def setup_logging_handler(stream, formatter=None):
"""This method enables all log messages to be written to the given
stream file object. The messages are formated in Check_MK standard
logging format.
"""
+ if formatter is None:
+ formatter = get_formatter("%(asctime)s [%(levelno)s] [%(name)s] %(message)s")
+
handler = _logging.StreamHandler(stream=stream)
- handler.setFormatter(get_formatter("%(asctime)s [%(levelno)s] [%(name)s] %(message)s"))
+ handler.setFormatter(formatter)
del logger.handlers[:] # Remove all previously existing handlers
logger.addHandler(handler)
Module: check_mk
Branch: master
Commit: a766ec7104c9c5e920b1bb3134d26cc1b14b020b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a766ec7104c9c5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Feb 1 09:24:24 2019 +0100
Fix cleanup of dangling symlinks (fix raw edition update from 1.5)
Change-Id: I980eb2bf419e1cc7d622d3fc5be789af2af68676
---
omd/packages/omd/hooks/CORE | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/omd/packages/omd/hooks/CORE b/omd/packages/omd/hooks/CORE
index 1942129..9a94b0f 100755
--- a/omd/packages/omd/hooks/CORE
+++ b/omd/packages/omd/hooks/CORE
@@ -32,15 +32,15 @@ case "$1" in
;;
set)
# cleanup the former selection
- if [ -e $OMD_ROOT/etc/apache/conf.d/shinken.conf ] ; then
+ if [ -h $OMD_ROOT/etc/apache/conf.d/shinken.conf ] ; then
rm -f $OMD_ROOT/etc/apache/conf.d/shinken.conf
fi
- if [ -e $OMD_ROOT/etc/apache/conf.d/nagios.conf ] ; then
+ if [ -h $OMD_ROOT/etc/apache/conf.d/nagios.conf ] ; then
rm -f $OMD_ROOT/etc/apache/conf.d/nagios.conf
fi
# NOTE: Although we don't ship Icinga anymore, we leave this to make
# sure there is no dangling symlink and keep Apache happy.
- if [ -e $OMD_ROOT/etc/apache/conf.d/icinga.conf ] ; then
+ if [ -h $OMD_ROOT/etc/apache/conf.d/icinga.conf ] ; then
rm -f $OMD_ROOT/etc/apache/conf.d/icinga.conf
fi
if [ "$2" != "cmc" ] ; then
Module: check_mk
Branch: master
Commit: 889d142b8bfbdab49c24dfd1485d445d322e523d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=889d142b8bfbda…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 31 22:15:28 2019 +0100
Add detailed output to new discovery log detail box
* Buffer the output produced during the "try-inventory" automation call
and send it as part of the resulting data structure to the discovery
background job
* The job will write the output to the background job output file and
show it to the user in the detail box
Note for the future: We should rework the automation calls to either
work inline or at least create a better interface that we don't need
hacks like this one.
CMK-1556
Change-Id: I51895ddd9cf7e2d665fb17de6bce05220884d890
---
cmk/gui/plugins/webapi/webapi.py | 2 +-
cmk/gui/wato/pages/services.py | 10 ++++++----
cmk_base/automations/check_mk.py | 24 ++++++++++++++++++++++++
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/cmk/gui/plugins/webapi/webapi.py b/cmk/gui/plugins/webapi/webapi.py
index 3ebf3a9..edcf55c 100644
--- a/cmk/gui/plugins/webapi/webapi.py
+++ b/cmk/gui/plugins/webapi/webapi.py
@@ -1054,7 +1054,7 @@ class APICallOther(APICallCollection):
result = watolib.check_mk_automation(
host_attributes.get("site"), "try-inventory", ["@scan"] + [hostname])
counts = {"new": 0, "old": 0}
- for entry in result:
+ for entry in result["check_table"]:
if entry[0] in counts:
counts[entry[0]] += 1
diff --git a/cmk/gui/wato/pages/services.py b/cmk/gui/wato/pages/services.py
index f0bbe1e..8a627cb 100644
--- a/cmk/gui/wato/pages/services.py
+++ b/cmk/gui/wato/pages/services.py
@@ -31,6 +31,7 @@ import json
import traceback
import time
import pprint
+import sys
from hashlib import sha256
from typing import NamedTuple, Text, List, Optional # pylint: disable=unused-import
@@ -408,8 +409,9 @@ class ServiceDiscoveryBackgroundJob(WatoBackgroundJob):
def _perform_service_scan(self, request):
"""The try-inventory automation refreshes the Check_MK internal cache and makes the new
information available to the next try-inventory call made by get_result()."""
- check_mk_automation(request.host.site_id(), "try-inventory",
- self._get_automation_options(request))
+ result = check_mk_automation(request.host.site_id(), "try-inventory",
+ self._get_automation_options(request))
+ sys.stdout.write(result["output"])
def _perform_automatic_refresh(self, request):
_counts, _failed_hosts = check_mk_automation(
@@ -446,14 +448,14 @@ class ServiceDiscoveryBackgroundJob(WatoBackgroundJob):
# time for all data of a host. The data sources should be able to provide this information
# somehow.
check_table_created = time.time()
- check_table = check_mk_automation(
+ result = check_mk_automation(
request.host.site_id(), "try-inventory",
["@noscan", "@raiseerrors", request.host.name()])
return DiscoveryResult(
job_status=job_status,
check_table_created=check_table_created,
- check_table=check_table,
+ check_table=result["check_table"],
)
def _check_table_file_path(self):
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index 553f00d..b9b8cfc 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -31,6 +31,8 @@ import subprocess
import sys
import time
import shutil
+import cStringIO
+import contextlib
import cmk.utils.paths
import cmk.utils.debug
@@ -125,12 +127,34 @@ class AutomationDiscovery(DiscoveryAutomation):
automations.register(AutomationDiscovery())
+# Python 3? use contextlib.redirect_stdout
+(a)contextlib.contextmanager
+def redirect_output(where):
+ """Redirects stdout/stderr to the given file like object"""
+ prev_stdout, prev_stderr = sys.stdout, sys.stderr
+ prev_stdout.flush()
+ prev_stderr.flush()
+ sys.stdout = sys.stderr = where
+ try:
+ yield where
+ finally:
+ where.flush()
+ sys.stdout, sys.stderr = prev_stdout, prev_stderr
+
+
class AutomationTryDiscovery(Automation):
cmd = "try-inventory" # TODO: Rename!
needs_config = True
needs_checks = True # TODO: Can we change this?
def execute(self, args):
+ cmk.utils.log.set_verbosity(2)
+
+ with redirect_output(cStringIO.StringIO()) as buf:
+ result = self._execute_discovery(args)
+ return {"output": buf.getvalue(), "check_table": result}
+
+ def _execute_discovery(self, args):
use_caches = False
do_snmp_scan = False
if args[0] == '@noscan':
Module: check_mk
Branch: master
Commit: 45fa21cc7b2dafc450596ec98026f5298be07f13
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=45fa21cc7b2daf…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 31 21:38:43 2019 +0100
Improved service discovery result message
* Shows when the job has finished which the page is currently showing
the state messages for
* Add a foldable "Job details" area which may be used to get diagnose
information about the job execution
CMK-1556
Change-Id: Ic1a5d63dd0501f44e987e5706e466c6f03c53cdd
---
cmk/gui/wato/pages/services.py | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/cmk/gui/wato/pages/services.py b/cmk/gui/wato/pages/services.py
index be30996..f0bbe1e 100644
--- a/cmk/gui/wato/pages/services.py
+++ b/cmk/gui/wato/pages/services.py
@@ -530,6 +530,9 @@ class ModeAjaxServiceDiscovery(WatoWebApiMode):
job_title = discovery_result.job_status.get("title", _("Service discovery"))
duration_txt = cmk.utils.render.Age(discovery_result.job_status["duration"])
+ finished_time = discovery_result.job_status["started"] + discovery_result.job_status[
+ "duration"]
+ finished_txt = cmk.utils.render.date_and_time(finished_time)
if discovery_result.job_status["state"] == JobStatus.state_running:
return _("%s running for %s") % (job_title, duration_txt)
@@ -540,10 +543,12 @@ class ModeAjaxServiceDiscovery(WatoWebApiMode):
messages = []
if discovery_result.job_status["state"] == JobStatus.state_stopped:
- messages.append(_("%s was stopped after %s") % (job_title, duration_txt))
+ messages.append(
+ _("%s was stopped after %s at %s.") % (job_title, duration_txt, finished_txt))
elif discovery_result.job_status["state"] == JobStatus.state_finished:
- messages.append(_("%s finished after %s") % (job_title, duration_txt))
+ messages.append(
+ _("%s finished after %s at %s.") % (job_title, duration_txt, finished_txt))
cmk_check_entries = [
e for e in discovery_result.check_table if DiscoveryState.is_discovered(e[0])
@@ -553,7 +558,20 @@ class ModeAjaxServiceDiscovery(WatoWebApiMode):
if no_data:
messages.append(_("No data for discovery available. Please perform a full scan."))
else:
- messages.append(_("Found no services yet. Try to perform a full scan."))
+ messages.append(_("Found no services yet. To retry please execute a full scan."))
+
+ with html.plugged():
+ html.begin_foldable_container(
+ treename="service_discovery",
+ id_="options",
+ isopen=False,
+ title=_("Job details"),
+ indent=False)
+ html.open_div(class_="log_output", style="height: 400px;", id_="progress_log")
+ html.pre("\n".join(discovery_result.job_status["loginfo"]["JobProgressUpdate"]))
+ html.close_div()
+ html.end_foldable_container()
+ messages.append(html.drain())
if messages:
return " ".join(messages)