Module: check_mk
Branch: master
Commit: 141e25f12fc9032111bf599e48c6b0e08bc37922
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=141e25f12fc903…
Author: Andreas <ab(a)mathias-kettner.de>
Date: Thu Jun 21 14:38:33 2018 +0200
6233 FIX Wato Web-API: Fixed broken service discovery for cluster hosts
Change-Id: I7aa595bd87721c6cab1122e764705c544711f4e5
---
.werks/6233 | 11 +++++++++++
web/plugins/webapi/webapi.py | 23 ++++++++++++++++++++++-
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/.werks/6233 b/.werks/6233
new file mode 100644
index 0000000..bd8f224
--- /dev/null
+++ b/.werks/6233
@@ -0,0 +1,11 @@
+Title: Wato Web-API: Fixed broken service discovery for cluster hosts
+Level: 1
+Component: wato
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1529584680
+
+
diff --git a/web/plugins/webapi/webapi.py b/web/plugins/webapi/webapi.py
index fe047f6..02291c7 100644
--- a/web/plugins/webapi/webapi.py
+++ b/web/plugins/webapi/webapi.py
@@ -1065,7 +1065,28 @@ def action_discover_services(request):
host = watolib.Host.host(hostname)
host_attributes = host.effective_attributes()
- counts, failed_hosts =
watolib.check_mk_automation(host_attributes.get("site"), "inventory",
[ "@scan", mode ] + [hostname])
+
+ if host.is_cluster():
+ # This is currently the only way to get some actual discovery statitics.
+ # Start a dry-run -> Get statistics
+ # Do an actual discovery on the nodes -> data is written
+ result = watolib.check_mk_automation(host_attributes.get("site"),
"try-inventory", ["@scan"] + [hostname])
+ counts = {"new": 0, "old": 0}
+ for entry in result:
+ if entry[0] in counts:
+ counts[entry[0]] += 1
+
+ counts = {hostname: (counts["new"],
+ 0, # this info is not available for clusters
+ counts["old"],
+ counts["new"] + counts["old"])}
+
+ # A cluster cannot fail, just the nodes. This information is currently discarded
+ failed_hosts = None
+ watolib.check_mk_automation(host_attributes.get("site"),
"inventory", [ "@scan", mode ] + host.cluster_nodes())
+ else:
+ counts, failed_hosts =
watolib.check_mk_automation(host_attributes.get("site"), "inventory",
[ "@scan", mode ] + [hostname])
+
if failed_hosts:
if not host.discovery_failed():
host.set_discovery_failed()