Module: check_mk
Branch: master
Commit: a318bcf5e1243a81f503dc6cf1abe03d9e96b64d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a318bcf5e1243a…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri May 8 09:40:06 2015 +0200
#2264 WATO Web API: new function get_all_hosts (returns all host attributes)
---
.werks/2264 | 9 +++++++++
ChangeLog | 1 +
web/htdocs/wato.py | 16 ++++++++++++++++
web/plugins/webapi/webapi.py | 14 ++++++++++++++
4 files changed, 40 insertions(+)
diff --git a/.werks/2264 b/.werks/2264
new file mode 100644
index 0000000..d08b943
--- /dev/null
+++ b/.werks/2264
@@ -0,0 +1,9 @@
+Title: WATO Web API: new function get_all_hosts (returns all host attributes)
+Level: 1
+Component: wato
+Compatible: compat
+Version: 1.2.7i1
+Date: 1431070771
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index a642624..6c1a3ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -441,6 +441,7 @@
* 2136 Unify headers of Host/Service rules, EC rules and notification rules...
* 2176 One custom icon or action can be configured per process/service...
* 2250 Added download page for shipped agents and plugins...
+ * 2264 WATO Web API: new function get_all_hosts (returns all host attributes)
* 1761 FIX: Ruleset search is now consistent for host & serviceparameters and
manual checks
* 1765 FIX: Fixed bug when generating nagvis backends while having sites with
livestatus proxy configured...
* 1789 FIX: Fix preview of passive checks in WATO list of services
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 932b5a4..39a3f03 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -18231,6 +18231,22 @@ class API:
else:
raise MKUserError(None, ", ".join(errors))
+ def get_all_hosts(self, effective_attr = False):
+ self.__prepare_folder_info()
+ all_hosts = self.__get_all_hosts()
+ return_hosts = {}
+
+ for hostname in all_hosts.keys():
+ self.__validate_host_parameters(None, hostname, {}, all_hosts, True,
["host_missing", "permissions_read"])
+
+ the_host = all_hosts[hostname]
+ if effective_attr:
+ the_host = effective_attributes(the_host, the_host[".folder"])
+ cleaned_host = dict([(k, v) for (k, v) in the_host.iteritems() if not
k.startswith('.') ])
+
+ return_hosts[hostname] = { "attributes": cleaned_host,
"path": the_host[".folder"][".path"], "hostname":
hostname }
+
+ return return_hosts
# internal helper functions for API
def collect_hosts(folder):
diff --git a/web/plugins/webapi/webapi.py b/web/plugins/webapi/webapi.py
index eea3cb9..0b3921c 100644
--- a/web/plugins/webapi/webapi.py
+++ b/web/plugins/webapi/webapi.py
@@ -137,3 +137,17 @@ api_actions["activate_changes"] = {
"locking" : True,
}
+###############
+
+def action_get_all_hosts(request):
+ if html.var("effective_attributes"):
+ effective_attributes = bool(int(html.var("effective_attributes")))
+ else:
+ effective_attributes = False
+ return g_api.get_all_hosts(effective_attr = effective_attributes)
+
+api_actions["get_all_hosts"] = {
+ "handler": action_get_all_hosts,
+ "locking": False,
+}
+