Module: check_mk
Branch: master
Commit: 178d0d495532c6c63a91e8bd74b57c5dcc8e77d5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=178d0d495532c6…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Jan 30 16:48:42 2019 +0100
azure: Better handle (authorization) errors
We can now see them in the azure_agent_info service.
Change-Id: I851f2b38528d926291335dfb12f1b7bf78694f8a
---
agents/special/agent_azure | 25 +++++++++++++++----------
checks/azure_agent_info | 3 +++
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/agents/special/agent_azure b/agents/special/agent_azure
index b0bad53..03f3120 100755
--- a/agents/special/agent_azure
+++ b/agents/special/agent_azure
@@ -216,14 +216,6 @@ def parse_arguments(argv):
return args
-def _add_hint(msg):
- if "does not have authorization to perform action" in msg:
- hint = "Make sure you have a proper role asigned to your client!"
- else:
- return msg
- return "%s\nHINT: %s\n" % (msg, hint)
-
-
# The following *Config objects provide a Configuration instance as described in
# CMK-513 (comment-12620).
# For now the passed commandline arguments are used to create it.
@@ -588,6 +580,20 @@ def write_groups(resources):
Section('agent_info', group).write()
+def write_exception_to_agent_info_section(exception):
+ # those exeptions are quite noisy. try to make them more concise:
+ msg = str(exception).split('Trace ID')[0]
+ msg = msg.split(':', 2)[-1].strip(' ,')
+
+ if "does not have authorization to perform action" in msg:
+ msg += "HINT: Make sure you have a proper role asigned to your
client!"
+
+ value = json.dumps((2, msg))
+ section = Section('agent_info')
+ section.add(('agent-bailout', value))
+ section.write()
+
+
def main(argv=None):
args = parse_arguments(argv or sys.argv[1:])
@@ -613,8 +619,7 @@ def main(argv=None):
section.write()
except () if args.debug else Exception as exc:
- sys.stderr.write(_add_hint(str(exc)))
- return 1
+ write_exception_to_agent_info_section(exc)
return 0
diff --git a/checks/azure_agent_info b/checks/azure_agent_info
index 1d295db..9007ffe 100644
--- a/checks/azure_agent_info
+++ b/checks/azure_agent_info
@@ -78,6 +78,9 @@ def discovery_azure_agent_info(_parsed):
def check_azure_agent_info(_no_item, params, parsed):
+ for status, text in parsed.get('agent-bailout', []):
+ yield status, text
+
reads = parsed.get('remaining-reads')
# this is only reported for the Datasource Host, so None
# is ignored.