[checkmk-commits] WK6676: WATO API get_hosttags now also returns the builtin tags

Andreas Boesl ab at mathias-kettner.de
Thu Nov 8 11:40:27 CET 2018


Module: check_mk
Branch: master
Commit: 4b669935011e0ceb84a4d38404fd568e6223bc6a
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4b669935011e0ceb84a4d38404fd568e6223bc6a

Author: Andreas Boesl <ab at mathias-kettner.de>
Date:   Thu Nov  8 11:29:40 2018 +0100

WK6676: WATO API get_hosttags now also returns the builtin tags

Change-Id: If1ef247f6952fc52ee941c6b3b015013ad9f26e7

---

 .werks/6676                      | 13 +++++++++++++
 cmk/gui/plugins/webapi/webapi.py | 16 ++++++++++++----
 cmk/gui/watolib.py               | 18 +++++++++++++++++-
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/.werks/6676 b/.werks/6676
new file mode 100644
index 0000000..e83aa62
--- /dev/null
+++ b/.werks/6676
@@ -0,0 +1,13 @@
+Title: WATO API get_hosttags now also returns the builtin tags
+Level: 1
+Component: wato
+Class: feature
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1541587658
+
+In addition to the already returned keys <tt>aux_tags</tt>, <tt>tag_groups</tt> and <tt>configuration_hash</tt>,
+the API call now also returns key <tt>builtin</tt> which includes the unmodifiable tags.
+This <tt>builtin</tt> key is not part of the configuration_hash checksum, since you cannot change these settings anyway.
diff --git a/cmk/gui/plugins/webapi/webapi.py b/cmk/gui/plugins/webapi/webapi.py
index 6af1172..eaa4c54 100644
--- a/cmk/gui/plugins/webapi/webapi.py
+++ b/cmk/gui/plugins/webapi/webapi.py
@@ -772,14 +772,22 @@ class APICallHosttags(APICallCollection):
         hosttags_config = watolib.HosttagsConfiguration()
         hosttags_config.load()
 
-        response = hosttags_config.get_dict_format()
-        add_configuration_hash(response, response)  # Looks strange, but is OK
+        hosttags_dict = hosttags_config.get_dict_format()
 
-        return response
+        # The configuration hash is computed for the configurable hosttags
+        add_configuration_hash(hosttags_dict, hosttags_dict) # Looks strange, but is OK
+
+        hosttags_dict["builtin"] = self._get_builtin_tags_configuration()
+        return hosttags_dict
+
+    def _get_builtin_tags_configuration(self):
+        builtin_tags_config = watolib.BuiltinHosttagsConfiguration()
+        builtin_tags_config.parse_config((watolib.builtin_host_tags, watolib.builtin_aux_tags))
+        return builtin_tags_config.get_dict_format()
 
     def _set(self, request):
         validate_request_keys(
-            request, required_keys=["tag_groups", "aux_tags"], optional_keys=["configuration_hash"])
+            request, required_keys=["tag_groups", "aux_tags"], optional_keys=["configuration_hash", "builtin"])
 
         hosttags_config = watolib.HosttagsConfiguration()
         hosttags_config.load()
diff --git a/cmk/gui/watolib.py b/cmk/gui/watolib.py
index d36fa7d..aa77d87 100644
--- a/cmk/gui/watolib.py
+++ b/cmk/gui/watolib.py
@@ -6928,7 +6928,10 @@ class AuxtagList(object):
     def append(self, aux_tag):
         if is_builtin_aux_tag(aux_tag.id):
             raise MKUserError("tag_id", _("You can not override a builtin auxiliary tag."))
+        self._append(aux_tag)
 
+
+    def _append(self, aux_tag):
         if self.has_aux_tag(aux_tag):
             raise MKUserError("tag_id", _("This tag id does already exist in the list "
                                           "of auxiliary tags."))
@@ -6973,6 +6976,10 @@ class AuxtagList(object):
         return response
 
 
+class BuiltinAuxtagList(AuxtagList):
+    def append(self, aux_tag):
+        self._append(aux_tag)
+
 
 class GroupedHosttag(Hosttag):
     def __init__(self, data = None):
@@ -7031,7 +7038,7 @@ class HosttagGroup(object):
 
     def _parse_legacy_format(self, group_info):
         self._initialize()
-        group_id, group_title, tag_list = group_info
+        group_id, group_title, tag_list = group_info[:3]
 
         self.id = group_id
         self.topic, self.title = HosttagsConfiguration.parse_hosttag_title(group_title)
@@ -7164,7 +7171,10 @@ class HosttagsConfiguration(object):
     def insert_tag_group(self, tag_group):
         if is_builtin_host_tag_group(tag_group.id):
             raise MKUserError("tag_id", _("You can not override a builtin tag group."))
+        self._insert_tag_group(tag_group)
+
 
+    def _insert_tag_group(self, tag_group):
         self.tag_groups.append(tag_group)
         self._validate_group(tag_group)
 
@@ -7299,7 +7309,13 @@ class HosttagsConfiguration(object):
         return result
 
 
+class BuiltinHosttagsConfiguration(HosttagsConfiguration):
+    def _initialize(self):
+        self.tag_groups   = []
+        self.aux_tag_list = BuiltinAuxtagList()
 
+    def insert_tag_group(self, tag_group):
+        self._insert_tag_group(tag_group)
 
 #.
 #   .--Hooks---------------------------------------------------------------.



More information about the checkmk-commits mailing list