Module: check_mk
Branch: master
Commit: 05302d41d9742004d1c62f4edfa9fbaa30358c36
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=05302d41d97420…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Dec 12 08:04:18 2018 +0100
azure.include: minor improvements
* allow showing other attributes
* add formatter for milli seconds
* nicely format levels text
Change-Id: Ife553db1cebe4cf54b981f8a3da1805c8b69b351
---
checks/azure.include | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/checks/azure.include b/checks/azure.include
index 54b2ed8..d3c134b 100644
--- a/checks/azure.include
+++ b/checks/azure.include
@@ -26,15 +26,17 @@
import json
-def azure_iter_informative_attrs(resource):
+def azure_iter_informative_attrs(resource, include_keys=('location',)):
+ def cap(s): # not quite what str.title() does
+ return s[0].upper() + s[1:]
- loc = resource.get('location')
- if loc is not None:
- yield 'Location', loc
+ for key in include_keys:
+ if key in resource:
+ yield cap(key), resource[key]
for key, value in resource.get('tags', {}).iteritems():
if not key.startswith("hidden-"):
- yield key[0].upper() + key[1:], value
+ yield cap(key), value
def check_azure_metric(resource,
@@ -61,6 +63,7 @@ def check_azure_metric(resource,
formatter = {
"percent": get_percent_human_readable,
"bytes": get_bytes_human_readable,
+ "milli_seconds": lambda ms: "%d ms" % ms
}.get(metric.unit, str)
text = "%s: %s" % (display_name, formatter(value))
@@ -71,7 +74,7 @@ def check_azure_metric(resource,
elif warn_lower is not None and value <= warn_lower:
l_state = 1
if l_state != 0:
- text += " (warn/crit below %s/%s)" % (warn_lower, crit_lower)
+ text += " (warn/crit below %s/%s)" % (formatter(warn_lower),
formatter(crit_lower))
warn, crit = levels or (None, None)
if crit is not None and value >= crit:
@@ -79,7 +82,7 @@ def check_azure_metric(resource,
elif warn is not None and value >= warn:
u_state = 1
if u_state != 0:
- text += " (warn/crit at %s/%s)" % (warn, crit)
+ text += " (warn/crit at %s/%s)" % (formatter(warn), formatter(crit))
return max(l_state, u_state), text, [(cmk_key, value, warn, crit, minv, maxv)]