From d5fee7de4bf1a436acb40a22ef2cefa06dae6ccb Mon Sep 17 00:00:00 2001 From: Philipp Lemke Date: Wed, 13 Mar 2019 11:45:05 +0100 Subject: [PATCH 1/2] - Fix call NoNoneValueDict in set_hosttags - Extend doc string --- check_mk_web_api/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/check_mk_web_api/__init__.py b/check_mk_web_api/__init__.py index c6f4a0a..f490670 100644 --- a/check_mk_web_api/__init__.py +++ b/check_mk_web_api/__init__.py @@ -712,13 +712,17 @@ def get_hosttags(self): def set_hosttags(self, hosttags): """ Sets host tags + + As implemented by Check_MK, it is only possible to write the whole Host Tag Settings within an API-Call + You can use the #WebApi.get_hosttags to get the current Tags, modify them and write the dict back via set_hosttags + To ensure that no Tags are modified in the meantime you can use the configuration_hash key. + + e.g. 'configuration_hash': u'f31ea758a59473d15f378b692110996c' # Arguments - hosttags (dict): new host tags that will be set, have a look at return value of #WebApi.get_hosttags + hosttags (dict) with 2 mandatory keys: { 'aux_tags' : [], 'tag_groups' : [] } """ - data = NoNoneValueDict({ - hosttags - }) + data = NoNoneValueDict(hosttags) return self.make_request('set_hosttags', data=data) From 3046e5bedf9b522c717b7a64537451138728ec2d Mon Sep 17 00:00:00 2001 From: Philipp Lemke Date: Mon, 2 Aug 2021 22:12:12 +0200 Subject: [PATCH 2/2] catch Permission denied to prevent json exception --- check_mk_web_api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_mk_web_api/__init__.py b/check_mk_web_api/__init__.py index 2341508..9f89a7a 100644 --- a/check_mk_web_api/__init__.py +++ b/check_mk_web_api/__init__.py @@ -149,7 +149,7 @@ def make_request(self, action, query_params=None, data=None): body = response.read().decode() - if body.startswith('Authentication error:'): + if re.match('(^Authentication error:|^Permission denied: Invalid automation secret)', body): raise CheckMkWebApiAuthenticationException(body) if 'output_format' in query_params and query_params['output_format'] == 'python':