Module: check_mk
Branch: master
Commit: 3b159b27f905cd66902bc8f2f7d6d28d77079046
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3b159b27f905cd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 10 11:36:47 2019 +0200
Moved dynamic configuration link to host page
The dynamic configuration is currently a feature to configure hosts.
For this reason we moved the link to the hosts page of WATO.
Change-Id: I5dbc643d96dae2bd146433db0c531898366d6ac0
---
cmk/gui/wato/pages/folders.py | 5 +++++
tests/unit/cmk/gui/plugins/wato/utils/test_main_menu.py | 5 +----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/cmk/gui/wato/pages/folders.py b/cmk/gui/wato/pages/folders.py
index 03e1e8a..e4321c9 100644
--- a/cmk/gui/wato/pages/folders.py
+++ b/cmk/gui/wato/pages/folders.py
@@ -125,6 +125,11 @@ class ModeFolder(WatoMode):
html.context_button(
_("Search"), watolib.folder_preserving_link([("mode", "search")]), "search")
+ if config.user.may("wato.dcd_connections"):
+ html.context_button(
+ _("Dynamic configuration"),
+ watolib.folder_preserving_link([("mode", "dcd_connections")]), "dcd_connections")
+
def action(self):
if html.request.var("_search"): # just commit to search form
return
diff --git a/tests/unit/cmk/gui/plugins/wato/utils/test_main_menu.py b/tests/unit/cmk/gui/plugins/wato/utils/test_main_menu.py
index 146721f..edb3d99 100644
--- a/tests/unit/cmk/gui/plugins/wato/utils/test_main_menu.py
+++ b/tests/unit/cmk/gui/plugins/wato/utils/test_main_menu.py
@@ -1,6 +1,4 @@
-import pytest
-
-# Following import is used to trigger pluggin loading
+# Following import is used to trigger plugin loading
import cmk.gui.wato # pylint: disable=unused-import
import cmk.gui.plugins.wato.utils.main_menu as main_menu
@@ -8,7 +6,6 @@ import cmk.gui.plugins.wato.utils.main_menu as main_menu
def test_registered_modules():
module_names = [m.mode_or_url for m in main_menu.get_modules()]
assert module_names == [
- 'dcd_connections',
'agents',
'folder',
'tags',
Module: check_mk
Branch: master
Commit: d2a05dc798df4c976f1fb9512b6c49bcd482aadd
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d2a05dc798df4c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 10 09:33:43 2019 +0200
Fixed broken BI state filters
All filters are used by default since 1.6 in views just like it is
done in reports for a long time. Since then it is important that
the filters detect on their own whether or not they are active.
This is especially important for the filters that only use checkboxes
as values. In these filters all checkboxes can be unchecked which makes
the HTTP variables for this filter vanish. As a result the filter does
not know whether or not it has been used (with all checkboxes unchecked)
or it has not be used and should not filter.
To fix this problem there is now a hidden field which is always set when
the filter has been submitted with a form. This makes the filter know
whether or not to do it's work.
Also cleaned up the checkbox processing to use the generic
get_checkbox() logic.
CMK-1869
Change-Id: I0c2ceef836aa1e9ae9c4c115681020170973446d
---
cmk/gui/plugins/visuals/filters.py | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/cmk/gui/plugins/visuals/filters.py b/cmk/gui/plugins/visuals/filters.py
index e9cc5e5..2addd8b 100644
--- a/cmk/gui/plugins/visuals/filters.py
+++ b/cmk/gui/plugins/visuals/filters.py
@@ -3303,7 +3303,7 @@ class BIStatusFilter(Filter):
else:
self.code = what[0]
self.prefix = "bi%ss" % self.code
- vars_ = [self.prefix + str(x) for x in [-1, 0, 1, 2, 3]]
+ vars_ = ["%s%s" % (self.prefix, x) for x in [-1, 0, 1, 2, 3, "_filled"]]
if self.code == 'a':
vars_.append(self.prefix + "n")
Filter.__init__(self, info="aggr", htmlvars=vars_, link_columns=[])
@@ -3314,11 +3314,12 @@ class BIStatusFilter(Filter):
def double_height(self):
return self.column == "aggr_assumed_state"
+ def _filter_used(self):
+ return html.request.has_var(self.prefix + "_filled")
+
def display(self):
- if html.request.var("filled_in"):
- defval = ""
- else:
- defval = "on"
+ html.hidden_field(self.prefix + "_filled", "1", add_var=True)
+
for varend, text in [
('0', _('OK')),
('1', _('WARN')),
@@ -3332,17 +3333,12 @@ class BIStatusFilter(Filter):
if varend == 'n':
html.br()
var = self.prefix + varend
- html.checkbox(var, defval, label=text)
+ html.checkbox(var, defval=not self._filter_used(), label=text)
def filter_table(self, rows):
- if html.request.var("filled_in"):
- defval = ""
- else:
- defval = "on"
-
allowed_states = []
for i in ['0', '1', '2', '3', '-1', 'n']:
- if html.request.var(self.prefix + i, defval) == "on":
+ if html.get_checkbox(self.prefix + i):
if i == 'n':
s = None
else:
Module: check_mk
Branch: master
Commit: 4d92d3eb200203bfcd1c5c1c3ff27f2e1638d1e5
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4d92d3eb200203…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 10 09:18:45 2019 +0200
Extracted some code from show_view()
Change-Id: I586f31f5879ada52659c243a42605ecc8c442180
---
cmk/gui/views.py | 58 +++++++++++++++++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 22 deletions(-)
diff --git a/cmk/gui/views.py b/cmk/gui/views.py
index 8caae7a..19f1b5a 100644
--- a/cmk/gui/views.py
+++ b/cmk/gui/views.py
@@ -1224,9 +1224,6 @@ def show_view(view, view_renderer, only_count=False):
force_checkboxes = view.spec.get("force_checkboxes", False)
show_checkboxes = force_checkboxes or html.request.var('show_checkboxes', '0') == '1'
- # Always allow the users to specify all allowed filters using the URL
- use_filters = visuals.filters_allowed_for_infos(view.datasource.infos).values()
-
# Not all filters are really shown later in show_filter_form(), because filters which
# have a hardcoded value are not changeable by the user
show_filters = visuals.filters_of_visual(
@@ -1251,11 +1248,7 @@ def show_view(view, view_renderer, only_count=False):
# Another idea: We could change these views to non single context views, but then we would not
# be able to show the buttons to other host related views, which is also bad. So better stick
# with the current mode.
- if view.datasource.ident in [ "mkeventd_events", "mkeventd_history" ] \
- and "host" in view.spec["single_infos"] and view.spec["name"] != "ec_events_of_monhost":
- # Remove the original host name filter
- use_filters = [f for f in use_filters if f.ident != "host"]
-
+ if _is_ec_unrelated_host_view(view):
# Set the value for the event host filter
if not html.request.has_var("event_host"):
html.request.set_var("event_host", html.request.var("host"))
@@ -1270,20 +1263,8 @@ def show_view(view, view_renderer, only_count=False):
# Check that all needed information for configured single contexts are available
visuals.verify_single_contexts('views', view.spec, view.datasource.link_filters)
- # Prepare Filter headers for Livestatus
- # TODO: When this is used by the reporting then *all* filters are
- # active. That way the inventory data will always be loaded. When
- # we convert this to the visuals principle the we need to optimize
- # this.
- filterheaders = ""
- all_active_filters = [f for f in use_filters if f.available()]
- for filt in all_active_filters:
- try:
- header = filt.filter(view.datasource.table)
- except MKUserError as e:
- html.add_user_error(e.varname, e)
- continue
- filterheaders += header
+ all_active_filters = _get_all_active_filters(view)
+ filterheaders = _get_livestatus_filter_headers(view, all_active_filters)
# Fork to availability view. We just need the filter headers, since we do not query the normal
# hosts and service table, but "statehist". This is *not* true for BI availability, though (see later)
@@ -1405,6 +1386,23 @@ def show_view(view, view_renderer, only_count=False):
SorterEntry = namedtuple("SorterEntry", ["sorter", "negate", "join_key"])
+def _get_all_active_filters(view):
+ # Always allow the users to specify all allowed filters using the URL
+ use_filters = visuals.filters_allowed_for_infos(view.datasource.infos).values()
+
+ # See show_view() for more information about this hack
+ if _is_ec_unrelated_host_view(view):
+ # Remove the original host name filter
+ use_filters = [f for f in use_filters if f.ident != "host"]
+
+ return [f for f in use_filters if f.available()]
+
+
+def _is_ec_unrelated_host_view(view):
+ return view.datasource.ident in [ "mkeventd_events", "mkeventd_history" ] \
+ and "host" in view.spec["single_infos"] and view.spec["name"] != "ec_events_of_monhost"
+
+
def _get_needed_regular_columns(cells, sorters, datasource):
# BI availability needs aggr_tree
# TODO: wtf? a full reset of the list? Move this far away to a special place!
@@ -1433,6 +1431,22 @@ def _get_needed_regular_columns(cells, sorters, datasource):
return list(columns)
+# TODO: When this is used by the reporting then *all* filters are active.
+# That way the inventory data will always be loaded. When we convert this to the
+# visuals principle the we need to optimize this.
+def _get_livestatus_filter_headers(view, all_active_filters):
+ """Prepare Filter headers for Livestatus"""
+ filterheaders = ""
+ for filt in all_active_filters:
+ try:
+ header = filt.filter(view.datasource.table)
+ except MKUserError as e:
+ html.add_user_error(e.varname, e)
+ continue
+ filterheaders += header
+ return filterheaders
+
+
def _get_needed_join_columns(join_cells, sorters):
join_columns = columns_of_cells(join_cells)
Module: check_mk
Branch: master
Commit: 20805253fd8475692f9358e5a9788badb20fe3f4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=20805253fd8475…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 9 16:23:42 2019 +0200
7336 labels: New inventory script to discover generic host labels
A new HW/SW inventory script has been added that works on a generic "<<<labels>>>" section.
It is used to discover host labels from this section.
The first agent that produces this section is the Kubernetes special agent. It creates the
label sections for all kind of objects that are monitored by Check_MK. This makes Check_MK
automatically import the labels configured in Kubernetes. You can now use them to filter
your views, dashboards and in the future also create rules in WATO based on them.
Change-Id: Ifb6b7179a02ff5d400e24f28d8e12cbd132c58c3
---
.werks/7336 | 16 ++++++++++++++++
inventory/labels | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/.werks/7336 b/.werks/7336
new file mode 100644
index 0000000..1c2c562
--- /dev/null
+++ b/.werks/7336
@@ -0,0 +1,16 @@
+Title: labels: New inventory script to discover generic host labels
+Level: 2
+Component: inv
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1554819594
+Class: feature
+
+A new HW/SW inventory script has been added that works on a generic "<<<labels>>>" section.
+It is used to discover host labels from this section.
+
+The first agent that produces this section is the Kubernetes special agent. It creates the
+label sections for all kind of objects that are monitored by Check_MK. This makes Check_MK
+automatically import the labels configured in Kubernetes. You can now use them to filter
+your views, dashboards and in the future also create rules in WATO based on them.
diff --git a/inventory/labels b/inventory/labels
new file mode 100644
index 0000000..1a0c5e1
--- /dev/null
+++ b/inventory/labels
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2019 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# Example outputs:
+# <<<labels:sep(0)>>>
+# {"tier": "control-plane", "component": "kube-scheduler"}
+
+import json
+
+
+def inv_labels(info, discovered_host_labels):
+ for key, value in _parse_labels(info).items():
+ discovered_host_labels.add_label(key, value, plugin_name="labels")
+
+
+def _parse_labels(info):
+ return json.loads(info[0][0])
+
+
+inv_info['labels'] = {
+ "inv_function": inv_labels,
+}