Module: check_mk
Branch: master
Commit: 0b6ce14d7c19367432d7bee55ddeba8b98595a73
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0b6ce14d7c1936…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sun Dec 16 10:24:31 2018 +0100
Made cmk.utils a component
* Moved previous cmk.utils stuff to cmk.utils.misc, but is still
accessible from cmk.utils.* for compatibility.
* Future: Move all "library" stuff that is meant to be usable from all
other components to cmk.utils. The goal is to have a cmk.* layer
which only contains the modules for the different components of
Check_MK.
Change-Id: I5cb4f6e3d0cffc35df4de0452f4d7a01a2d5a4c5
---
cmk/utils/__init__.py | 34 ++++++++++++++++++++++++++++++++++
cmk/{utils.py => utils/misc.py} | 0
2 files changed, 34 insertions(+)
diff --git a/cmk/utils/__init__.py b/cmk/utils/__init__.py
new file mode 100644
index 0000000..7f9b36d
--- /dev/null
+++ b/cmk/utils/__init__.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 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.
+
+# TODO: Kept for compatibility. Clean up call sites.
+# Or even better: move the functions from misc to a better place
+from cmk.utils.misc import (
+ make_utf8,
+ quote_shell_string,
+ pnp_cleanup,
+ cmp_config_paths,
+)
diff --git a/cmk/utils.py b/cmk/utils/misc.py
similarity index 100%
rename from cmk/utils.py
rename to cmk/utils/misc.py
Module: check_mk
Branch: master
Commit: f49a1e76ea5bd70c75bcc4623703e0efc5b721b4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f49a1e76ea5bd7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Dec 17 11:42:57 2018 +0100
Add new man page category for containerization
Change-Id: I466216696354d1d06e586c18ce6087ed1b70b5b2
---
checkman/docker_container_cpu | 2 +-
checkman/docker_container_diskstat | 2 +-
checkman/docker_container_mem | 2 +-
checkman/docker_container_status | 2 +-
checkman/docker_container_status.health | 2 +-
checkman/docker_node_disk_usage | 4 ++--
checkman/docker_node_info | 2 +-
checkman/docker_node_info.containers | 4 ++--
checkman/k8s_component_statuses | 4 ++--
checkman/k8s_conditions | 4 ++--
checkman/k8s_namespaces | 4 ++--
checkman/k8s_nodes | 4 ++--
checkman/k8s_persistent_volume_claims | 4 ++--
checkman/k8s_persistent_volumes | 4 ++--
checkman/k8s_resources.cpu | 4 ++--
checkman/k8s_resources.memory | 4 ++--
checkman/k8s_resources.pods | 4 ++--
checkman/k8s_roles | 4 ++--
checkman/k8s_storage_classes | 4 ++--
cmk/man_pages.py | 3 +++
20 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/checkman/docker_container_cpu b/checkman/docker_container_cpu
index 3a872e3..743ca75 100644
--- a/checkman/docker_container_cpu
+++ b/checkman/docker_container_cpu
@@ -1,6 +1,6 @@
title: Docker container CPU utilization
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
diff --git a/checkman/docker_container_diskstat b/checkman/docker_container_diskstat
index 6df80a0..21e1b40 100644
--- a/checkman/docker_container_diskstat
+++ b/checkman/docker_container_diskstat
@@ -1,6 +1,6 @@
title: Docker container disk throughput
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
diff --git a/checkman/docker_container_mem b/checkman/docker_container_mem
index 4ccb9e9..2d1151e 100644
--- a/checkman/docker_container_mem
+++ b/checkman/docker_container_mem
@@ -1,6 +1,6 @@
title: Docker container memory usage
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
diff --git a/checkman/docker_container_status b/checkman/docker_container_status
index 9789593..154ad23 100644
--- a/checkman/docker_container_status
+++ b/checkman/docker_container_status
@@ -1,6 +1,6 @@
title: Docker container status
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
diff --git a/checkman/docker_container_status.health b/checkman/docker_container_status.health
index 434d12f..83d861b 100644
--- a/checkman/docker_container_status.health
+++ b/checkman/docker_container_status.health
@@ -1,6 +1,6 @@
title: Docker container health
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
diff --git a/checkman/docker_node_disk_usage b/checkman/docker_node_disk_usage
index bb6dc2c..fcfe6ad 100644
--- a/checkman/docker_node_disk_usage
+++ b/checkman/docker_node_disk_usage
@@ -1,6 +1,6 @@
title: Docker node disk usage
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
@@ -8,4 +8,4 @@ description:
reclaimable size of containers, images, local volumes, and build cache.
inventory:
- One service per type (i.e. containers, images, volumen, build cache) is created.
\ No newline at end of file
+ One service per type (i.e. containers, images, volumen, build cache) is created.
diff --git a/checkman/docker_node_info b/checkman/docker_node_info
index b90895f..cd1f8c6 100644
--- a/checkman/docker_node_info
+++ b/checkman/docker_node_info
@@ -1,6 +1,6 @@
title: Docker Node Info
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
diff --git a/checkman/docker_node_info.containers b/checkman/docker_node_info.containers
index f797abe..67c7dfd 100644
--- a/checkman/docker_node_info.containers
+++ b/checkman/docker_node_info.containers
@@ -1,6 +1,6 @@
title: Docker Node Info Containers
agents: linux
-catalog: app/docker
+catalog: containerization/docker
license: GPL
distribution: check_mk
description:
@@ -9,4 +9,4 @@ description:
for each of these values.
inventory:
- One service is created.
\ No newline at end of file
+ One service is created.
diff --git a/checkman/k8s_component_statuses b/checkman/k8s_component_statuses
index 2d1d799..b71ce59 100644
--- a/checkman/k8s_component_statuses
+++ b/checkman/k8s_component_statuses
@@ -1,6 +1,6 @@
title: Kubernetes component status
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -12,4 +12,4 @@ inventory:
One service per component is created.
item:
- The name of the component.
\ No newline at end of file
+ The name of the component.
diff --git a/checkman/k8s_conditions b/checkman/k8s_conditions
index af804d0..c18318d 100644
--- a/checkman/k8s_conditions
+++ b/checkman/k8s_conditions
@@ -1,6 +1,6 @@
title: Kubernetes conditions
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -10,4 +10,4 @@ description:
{CRIT} otherwise {OK}.
inventory:
- One service is created for each condition and one for the readiness status.
\ No newline at end of file
+ One service is created for each condition and one for the readiness status.
diff --git a/checkman/k8s_namespaces b/checkman/k8s_namespaces
index 6bcb152..8a6f014 100644
--- a/checkman/k8s_namespaces
+++ b/checkman/k8s_namespaces
@@ -1,6 +1,6 @@
title: Kubernetes namespaces
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -11,4 +11,4 @@ inventory:
One service per namespace is created.
item:
- The name of the namespace.
\ No newline at end of file
+ The name of the namespace.
diff --git a/checkman/k8s_nodes b/checkman/k8s_nodes
index dac4da6..5bc6ac4 100644
--- a/checkman/k8s_nodes
+++ b/checkman/k8s_nodes
@@ -1,6 +1,6 @@
title: Kubernetes nodes
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -8,4 +8,4 @@ description:
It always returns {OK}.
inventory:
- One service is created.
\ No newline at end of file
+ One service is created.
diff --git a/checkman/k8s_persistent_volume_claims b/checkman/k8s_persistent_volume_claims
index bb77c91..3f738ea 100644
--- a/checkman/k8s_persistent_volume_claims
+++ b/checkman/k8s_persistent_volume_claims
@@ -1,6 +1,6 @@
title: Kubernetes persistent volume claims
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -12,4 +12,4 @@ inventory:
One service per persistent volume claim is created.
item:
- The name of the persistent volume claim.
\ No newline at end of file
+ The name of the persistent volume claim.
diff --git a/checkman/k8s_persistent_volumes b/checkman/k8s_persistent_volumes
index 5320ceb..93466e3 100644
--- a/checkman/k8s_persistent_volumes
+++ b/checkman/k8s_persistent_volumes
@@ -1,6 +1,6 @@
title: Kubernetes persistent volumes
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -11,4 +11,4 @@ inventory:
One service per persistent volume is created.
item:
- The name of the persistent volume.
\ No newline at end of file
+ The name of the persistent volume.
diff --git a/checkman/k8s_resources.cpu b/checkman/k8s_resources.cpu
index 98499d7..e5ce1ae 100644
--- a/checkman/k8s_resources.cpu
+++ b/checkman/k8s_resources.cpu
@@ -1,6 +1,6 @@
title: Kubernetes CPU resources
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -12,4 +12,4 @@ description:
for the CPU usage, i.e. the ratio between requested and allocatable CPU.
inventory:
- One service is created.
\ No newline at end of file
+ One service is created.
diff --git a/checkman/k8s_resources.memory b/checkman/k8s_resources.memory
index 733aeb6..2a33c60 100644
--- a/checkman/k8s_resources.memory
+++ b/checkman/k8s_resources.memory
@@ -1,6 +1,6 @@
title: Kubernetes memory resources
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -12,4 +12,4 @@ description:
for the Memory usage, i.e. the ratio between requested and allocatable Memory.
inventory:
- One service is created.
\ No newline at end of file
+ One service is created.
diff --git a/checkman/k8s_resources.pods b/checkman/k8s_resources.pods
index 750f3ba..4fc8181 100644
--- a/checkman/k8s_resources.pods
+++ b/checkman/k8s_resources.pods
@@ -1,6 +1,6 @@
title: Kubernetes pod resources
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -10,4 +10,4 @@ description:
for the Pod usage, i.e. the ratio between used and allocatable Pods.
inventory:
- One service is created.
\ No newline at end of file
+ One service is created.
diff --git a/checkman/k8s_roles b/checkman/k8s_roles
index e84c6f4..4a8e541 100644
--- a/checkman/k8s_roles
+++ b/checkman/k8s_roles
@@ -1,6 +1,6 @@
title: Kubernetes roles
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -11,4 +11,4 @@ inventory:
One service is per role created.
item:
- The name of the role.
\ No newline at end of file
+ The name of the role.
diff --git a/checkman/k8s_storage_classes b/checkman/k8s_storage_classes
index aa69a23..321c344 100644
--- a/checkman/k8s_storage_classes
+++ b/checkman/k8s_storage_classes
@@ -1,6 +1,6 @@
title: Kubernetes storage classes
agents: linux
-catalog: app/kubernetes
+catalog: containerization/kubernetes
license: GPL
distribution: check_mk
description:
@@ -11,4 +11,4 @@ inventory:
One service per storage class is created.
item:
- The name of the storage class.
\ No newline at end of file
+ The name of the storage class.
diff --git a/cmk/man_pages.py b/cmk/man_pages.py
index caf2ed3..e9c43a0 100644
--- a/cmk/man_pages.py
+++ b/cmk/man_pages.py
@@ -208,6 +208,9 @@ catalog_titles = {
"cloud" : "Cloud Based Environments",
"azure" : "Microsoft Azure",
"aws" : "Amazon Web Services",
+ "containerization" : "Containerization",
+ "docker" : "Docker",
+ "kubernetes" : "Kubernetes",
"agentless": "Networking checks without agent",
"generic" : "Generic check plugins",
"unsorted" : "Uncategorized",
Module: check_mk
Branch: master
Commit: 54c9c00b27f5127c4a1d85c16fa34ce1959d61c4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=54c9c00b27f512…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Dec 13 13:37:11 2018 +0100
Host attributes: Cleaned up host tag attribute class a bit
CMK-1421
Change-Id: Idb38827cccca0679b04d8be0db335f90f8448446
---
cmk/gui/plugins/wato/__init__.py | 1 +
cmk/gui/plugins/wato/builtin_attributes.py | 2 +-
cmk/gui/plugins/wato/utils/__init__.py | 1 +
cmk/gui/watolib.py | 53 ++++++++++++++++--------------
4 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/cmk/gui/plugins/wato/__init__.py b/cmk/gui/plugins/wato/__init__.py
index 0cf4541..3e4aa20 100644
--- a/cmk/gui/plugins/wato/__init__.py
+++ b/cmk/gui/plugins/wato/__init__.py
@@ -81,6 +81,7 @@ from cmk.gui.plugins.wato.utils import (
multifolder_host_rule_match_conditions,
multisite_dir,
NagiosTextAttribute,
+ NagiosValueSpecAttribute,
PluginCommandLine,
PredictiveLevels,
config_variable_group_registry,
diff --git a/cmk/gui/plugins/wato/builtin_attributes.py b/cmk/gui/plugins/wato/builtin_attributes.py
index a6d3794..f5c3602 100644
--- a/cmk/gui/plugins/wato/builtin_attributes.py
+++ b/cmk/gui/plugins/wato/builtin_attributes.py
@@ -55,7 +55,7 @@ from cmk.gui.valuespec import (
)
from cmk.gui.exceptions import MKUserError
-from . import (
+from cmk.gui.plugins.wato import (
declare_host_attribute,
SNMPCredentials,
IPMIParameters,
diff --git a/cmk/gui/plugins/wato/utils/__init__.py b/cmk/gui/plugins/wato/utils/__init__.py
index 52325f2..27b9592 100644
--- a/cmk/gui/plugins/wato/utils/__init__.py
+++ b/cmk/gui/plugins/wato/utils/__init__.py
@@ -117,6 +117,7 @@ from cmk.gui.watolib import (
folder_preserving_link,
ContactGroupsAttribute,
NagiosTextAttribute,
+ NagiosValueSpecAttribute,
ValueSpecAttribute,
ACTestCategories,
ACTest,
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index 1c0627e..54ab44b 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -3469,18 +3469,22 @@ class EnumAttribute(Attribute):
return html.var(varprefix + "attr_" + self.name(), self.default_value())
-# A selection dropdown for a host tag
class HostTagAttribute(Attribute):
- def __init__(self, tag_definition):
- # Definition is either triple or 4-tuple (with
- # dependency definition)
- tag_id, title, self._taglist = tag_definition
- name = "tag_" + tag_id
- if len(self._taglist) == 1:
- def_value = None
- else:
- def_value = self._taglist[0][0]
- Attribute.__init__(self, name, title, "", def_value)
+ """A selection dropdown for a host tag"""
+
+ def __init__(self, tag_id, title, tag_list):
+ self._taglist = tag_list
+ super(HostTagAttribute, self).__init__(
+ name="tag_" + tag_id,
+ title=title,
+ help_txt="",
+ default_value=self._default_tag_value(),
+ )
+
+ def _default_tag_value(self):
+ if not self.is_checkbox_tag():
+ return self._taglist[0][0]
+ return None
def is_checkbox_tag(self):
return len(self._taglist) == 1
@@ -3490,7 +3494,7 @@ class HostTagAttribute(Attribute):
# files the _() function must also be placed in the configuration files
# But don't localize empty strings - This empty string is connected to the header
# of the .mo file
- if len(self._taglist) == 1:
+ if self.is_checkbox_tag():
title = self._taglist[0][1]
if title:
title = _u(title)
@@ -3523,7 +3527,7 @@ class HostTagAttribute(Attribute):
if value != "" and value == tagvalue and secondary_tags:
value = value + "|" + "|".join(secondary_tags)
- if len(choices) == 1:
+ if self.is_checkbox_tag():
html.checkbox(
varname,
value != "",
@@ -3535,28 +3539,27 @@ class HostTagAttribute(Attribute):
def from_html_vars(self, varprefix):
varname = varprefix + "attr_" + self.name()
- if len(self._taglist) == 1:
+ if self.is_checkbox_tag():
if html.get_checkbox(varname):
return self._taglist[0][0]
return None
- else:
- # strip of secondary tags
- value = html.var(varname).split("|")[0]
- if not value:
- value = None
- return value
- # Special function for computing the setting of a specific
- # tag group from the total list of tags of a host
+ # strip of secondary tags
+ value = html.var(varname).split("|")[0]
+ if not value:
+ value = None
+ return value
+
def get_tag_value(self, tags):
+ """Special function for computing the setting of a specific
+ tag group from the total list of tags of a host"""
for entry in self._taglist:
if entry[0] in tags:
return entry[0]
return None
- # Return list of host tags to set (handles
- # secondary tags)
def get_tag_list(self, value):
+ """Return list of host tags to set (handles secondary tags)"""
for entry in self._taglist:
if entry[0] == value:
if len(entry) >= 3:
@@ -3851,7 +3854,7 @@ def declare_host_tag_attributes():
topic = _('Host tags')
declare_host_attribute(
- HostTagAttribute(entry[:3]),
+ HostTagAttribute(*entry[:3]),
show_in_table=False,
show_in_folder=True,
editable=attr_editable,
Module: check_mk
Branch: master
Commit: 8713f1d0c2aebcad9e378787e7e63331b87c8be8
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8713f1d0c2aebc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Dec 13 08:59:29 2018 +0100
Host attributes: Extracted some host attribute logic from configure_attributes()
* Moved host attribute topic listing and sorting to dedicated function
and added a test for the topics and their sorting
* Moved host attribute list, filtering and sorting to dedicated function
and added a test for the attributes of a topic and their sorting
CMK-1421
Change-Id: Iefe9890073cb37a4f25933aec05dfbad3c9888ac
---
cmk/gui/plugins/wato/utils/__init__.py | 67 ++++++++------------------------
cmk/gui/watolib.py | 36 +++++++++++++++++
tests/unit/cmk/gui/test_watolib.py | 71 ++++++++++++++++++++++++++++++++++
3 files changed, 124 insertions(+), 50 deletions(-)
diff --git a/cmk/gui/plugins/wato/utils/__init__.py b/cmk/gui/plugins/wato/utils/__init__.py
index 5dfeab2..52325f2 100644
--- a/cmk/gui/plugins/wato/utils/__init__.py
+++ b/cmk/gui/plugins/wato/utils/__init__.py
@@ -1568,65 +1568,33 @@ def configure_attributes(new,
if without_attributes is None:
without_attributes = []
- # show attributes grouped by topics, in order of their
- # appearance. If only one topic exists, do not show topics
- # Make sure, that the topics "Basic settings" and host tags
- # are always show first.
- # TODO: Clean this up! Implement some explicit sorting
- topics = [None]
- if config.host_tag_groups():
- topics.append(_("Address"))
- topics.append(_("Data sources"))
- topics.append(_("Host tags"))
-
- # The remaining topics are shown in the order of the
- # appearance of the attribute declarations:
- for attr, topic in watolib.all_host_attributes():
- if topic not in topics and attr.is_visible(for_what):
- topics.append(topic)
-
# Collect dependency mapping for attributes (attributes that are only
# visible, if certain host tags are set).
dependency_mapping_tags = {}
dependency_mapping_roles = {}
inherited_tags = {}
- # Hack to sort the address family host tag attribute above the IPv4/v6 addresses
- # TODO: Clean this up by implementing some sort of explicit sorting
- def sort_host_attributes(a, b):
- if a[0].name() == "tag_address_family":
- return -1
- return 0
-
volatile_topics = []
hide_attributes = []
- for topic in topics:
+ for topic, title in watolib.get_sorted_host_attribute_topics(for_what):
topic_is_volatile = True # assume topic is sometimes hidden due to dependencies
- if len(topics) > 1:
- if topic is None:
- title = _("Basic settings")
- else:
- title = _u(topic)
-
- if topic == _("Host tags"):
- topic_id = "wato_host_tags"
- elif topic == _("Address"):
- topic_id = "address"
- elif topic == _("Data sources"):
- topic_id = "data_sources"
- else:
- topic_id = None
- forms.header(
- title,
- isopen=topic in [None, _("Address"), _("Data sources")],
- table_id=topic_id,
- )
+ if topic == _("Host tags"):
+ topic_id = "wato_host_tags"
+ elif topic == _("Address"):
+ topic_id = "address"
+ elif topic == _("Data sources"):
+ topic_id = "data_sources"
+ else:
+ topic_id = None
- for attr, atopic in sorted(watolib.all_host_attributes(), cmp=sort_host_attributes):
- if atopic != topic:
- continue
+ forms.header(
+ title,
+ isopen=topic in [None, _("Address"), _("Data sources")],
+ table_id=topic_id,
+ )
+ for attr in watolib.get_sorted_host_attributes_by_topic(topic):
attrname = attr.name()
if attrname in without_attributes:
continue # e.g. needed to skip ipaddress in CSV-Import
@@ -1854,9 +1822,8 @@ def configure_attributes(new,
html.write_text(explanation)
html.close_div()
- if len(topics) > 1:
- if topic_is_volatile:
- volatile_topics.append((topic or _("Basic settings")).encode('utf-8'))
+ if topic_is_volatile:
+ volatile_topics.append((topic or _("Basic settings")).encode('utf-8'))
forms.end()
# Provide Javascript world with the tag dependency information
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index 7ea6af7..1c0627e 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -3896,6 +3896,42 @@ def collect_attributes(for_what, do_validate=True, varprefix=""):
return host
+def get_sorted_host_attribute_topics(for_what):
+ # show attributes grouped by topics, in order of their
+ # appearance. If only one topic exists, do not show topics
+ # Make sure, that the topics "Basic settings" and host tags
+ # are always show first.
+ # TODO: Clean this up! Implement some explicit sorting
+ topics = [None]
+ if config.host_tag_groups():
+ topics.append(_("Address"))
+ topics.append(_("Data sources"))
+ topics.append(_("Host tags"))
+
+ # The remaining topics are shown in the order of the
+ # appearance of the attribute declarations:
+ for attr, topic in all_host_attributes():
+ if topic not in topics and attr.is_visible(for_what):
+ topics.append(topic)
+
+ return [(t, _("Basic settings") if t is None else _u(t)) for t in topics]
+
+
+def get_sorted_host_attributes_by_topic(topic):
+ # Hack to sort the address family host tag attribute above the IPv4/v6 addresses
+ # TODO: Clean this up by implementing some sort of explicit sorting
+ def sort_host_attributes(a, b):
+ if a[0].name() == "tag_address_family":
+ return -1
+ return 0
+
+ attributes = []
+ for attr, atopic in sorted(all_host_attributes(), cmp=sort_host_attributes):
+ if atopic == topic:
+ attributes.append(attr)
+ return attributes
+
+
#.
# Persistenz: Speicherung der Werte
# - WATO speichert seine Variablen für main.mk in conf.d/wato/global.mk
diff --git a/tests/unit/cmk/gui/test_watolib.py b/tests/unit/cmk/gui/test_watolib.py
index e44a9e9..2528956 100644
--- a/tests/unit/cmk/gui/test_watolib.py
+++ b/tests/unit/cmk/gui/test_watolib.py
@@ -1664,3 +1664,74 @@ def test_register_check_parameters(monkeypatch):
rulespec_names = [r.name for r in watolib.g_rulespecs.get_by_group("static/netblabla")]
assert "static_checks:check_group_name" in rulespec_names
assert len(rulespec_names) == 1
+
+
+(a)pytest.mark.parametrize("for_what", [
+ "host",
+ "cluster",
+ "folder",
+ "host_search",
+ "bulk",
+])
+def test_host_attribute_topics(for_what):
+ expected = [
+ (None, u"Basic settings"),
+ (u'Address', u'Address'),
+ (u'Data sources', u'Data sources'),
+ (u'Host tags', u'Host tags'),
+ (u'Management Board', u'Management Board'),
+ ]
+
+ if for_what == "folder":
+ expected = [
+ (None, u"Basic settings"),
+ (u'Address', u'Address'),
+ (u'Data sources', u'Data sources'),
+ (u'Host tags', u'Host tags'),
+ (u'Network Scan', u'Network Scan'),
+ (u'Management Board', u'Management Board'),
+ ]
+
+ assert watolib.get_sorted_host_attribute_topics(for_what=for_what) == expected
+
+
+(a)pytest.mark.parametrize("for_what", [
+ "host",
+ "cluster",
+ "folder",
+ "host_search",
+ "bulk",
+])
+def test_host_attributes(for_what):
+ topics = {
+ None: [
+ 'contactgroups',
+ 'alias',
+ 'snmp_community',
+ 'parents',
+ 'site',
+ 'locked_by',
+ 'locked_attributes',
+ ],
+ "Address": [
+ 'ipaddress',
+ 'ipv6address',
+ 'additional_ipv4addresses',
+ 'additional_ipv6addresses',
+ ],
+ "Data sources": [],
+ "Management Board": [
+ 'management_address',
+ 'management_protocol',
+ 'management_snmp_community',
+ 'management_ipmi_credentials',
+ ],
+ "Network Scan": [
+ 'network_scan',
+ 'network_scan_result',
+ ],
+ }
+ for topic, _title in watolib.get_sorted_host_attribute_topics(for_what):
+ names = [a.name() for a in watolib.get_sorted_host_attributes_by_topic(topic)]
+ assert names == topics.get(topic,
+ []), "Expected attributes not specified for topic %r" % topic