Module: check_mk
Branch: master
Commit: 7516f27a056e42fb682caa1c97807fcd19349bb5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7516f27a056e42…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jul 11 10:55:25 2017 +0200
4959 FIX Web-API: Fixed calls related to groups when using CME
The WEB API calls related to groups of hosts, services or contacts
were not dealing with the customer field. This has been added as
required attribute now when using the CME just like it's done when
using the GUI.
Change-Id: I03f84bd265726f9e7055d1234ac0ad335d3ffff2
---
.werks/4959 | 13 ++++++++++
tests/web/test_webapi.py | 62 +++++++++++++++++++++++++++++++++++++-------
web/htdocs/webapi.py | 5 ++++
web/plugins/webapi/webapi.py | 14 ++++++++--
4 files changed, 83 insertions(+), 11 deletions(-)
diff --git a/.werks/4959 b/.werks/4959
new file mode 100644
index 0000000..ad64467
--- /dev/null
+++ b/.werks/4959
@@ -0,0 +1,13 @@
+Title: Web-API: Fixed calls related to groups when using CME
+Level: 1
+Component: wato
+Compatible: compat
+Edition: cme
+Version: 1.5.0i1
+Date: 1499763203
+Class: fix
+
+The WEB API calls related to groups of hosts, services or contacts
+were not dealing with the customer field. This has been added as
+required attribute now when using the CME just like it's done when
+using the GUI.
diff --git a/tests/web/test_webapi.py b/tests/web/test_webapi.py
index 5d5c471..ee78e66 100644
--- a/tests/web/test_webapi.py
+++ b/tests/web/test_webapi.py
@@ -9,6 +9,7 @@ import base64
from PIL import Image
from StringIO import StringIO
+import cmk
from testlib import web, APIError
def test_global_settings(site, web):
@@ -157,43 +158,69 @@ def test_write_host_tags(web, site):
web.delete_host("test-host-dmz")
+# TODO: Parameterize test for cme / non cme
@pytest.mark.parametrize(("group_type"), [ "contact",
"host", "service" ])
def test_add_group(web, group_type):
group_id = "%s_testgroup_id" % group_type
group_alias = "%s_testgroup_alias" % group_type
try:
- web.add_group(group_type, group_id, {"alias": group_alias})
+ attributes = {"alias": group_alias}
+
+ if cmk.is_managed_edition():
+ attributes["customer"] = "provider"
+
+ web.add_group(group_type, group_id, attributes)
all_groups = web.get_all_groups(group_type)
assert group_id in all_groups
assert group_alias == all_groups[group_id]["alias"]
+
+ if cmk.is_managed_edition():
+ assert provider == all_groups[group_id]["provider"]
finally:
web.delete_group(group_type, group_id)
+# TODO: Parameterize test for cme / non cme
@pytest.mark.parametrize(("group_type"), [ "contact",
"host", "service" ])
def test_edit_group(web, group_type):
group_id = "%s_testgroup_id" % group_type
group_alias = "%s_testgroup_alias" % group_type
group_alias2 = "%s_testgroup_otheralias" % group_type
try:
- web.add_group(group_type, group_id, {"alias": group_alias})
- web.edit_group(group_type, group_id, {"alias": group_alias2})
+ attributes = {"alias": group_alias}
+
+ if cmk.is_managed_edition():
+ attributes["customer"] = "provider"
+
+ web.add_group(group_type, group_id, attributes)
+
+ attributes["alias"] = group_alias2
+ web.edit_group(group_type, group_id, attributes)
all_groups = web.get_all_groups(group_type)
assert group_id in all_groups
- assert group_alias2 in all_groups[group_id]["alias"]
+ assert group_alias2 == all_groups[group_id]["alias"]
+
+ if cmk.is_managed_edition():
+ assert "provider" == all_groups[group_id]["customer"]
finally:
web.delete_group(group_type, group_id)
+# TODO: Parameterize test for cme / non cme
@pytest.mark.parametrize(("group_type"), [ "contact",
"host", "service" ])
def test_edit_group_missing(web, group_type):
group_id = "%s_testgroup_id" % group_type
group_alias = "%s_testgroup_alias" % group_type
group_alias2 = "%s_testgroup_otheralias" % group_type
try:
- web.add_group(group_type, group_id, {"alias": group_alias})
+ attributes = {"alias": group_alias}
+
+ if cmk.is_managed_edition():
+ attributes["customer"] = "provider"
+
+ web.add_group(group_type, group_id, attributes)
try:
#web.edit_group(group_type, group_id, {"alias": group_alias2},
expect_error = True)
web.edit_group(group_type, "%s_missing" % group_id,
{"alias": group_alias2}, expect_error = True)
@@ -206,14 +233,26 @@ def test_edit_group_missing(web, group_type):
web.delete_group(group_type, group_id)
+# TODO: Parameterize test for cme / non cme
def test_edit_cg_group_with_nagvis_maps(web, site):
dummy_map_filepath1 = "%s/etc/nagvis/maps/blabla.cfg" % site.root
dummy_map_filepath2 = "%s/etc/nagvis/maps/bloblo.cfg" % site.root
try:
file(dummy_map_filepath1, "w")
file(dummy_map_filepath2, "w")
- web.add_group("contact", "nagvis_test", {"alias":
"nagvis_test_alias", "nagvis_maps": ["blabla"]})
- web.edit_group("contact", "nagvis_test", {"alias":
"nagvis_test_alias", "nagvis_maps": ["bloblo"]})
+
+ attributes = {
+ "alias": "nagvis_test_alias",
+ "nagvis_maps": ["blabla"]
+ }
+
+ if cmk.is_managed_edition():
+ attributes["customer"] = "provider"
+
+ web.add_group("contact", "nagvis_test", attributes)
+
+ attributes["nagvis_maps"] = ["bloblo"]
+ web.edit_group("contact", "nagvis_test", attributes)
all_groups = web.get_all_groups("contact")
assert "nagvis_test" in all_groups
@@ -224,13 +263,18 @@ def test_edit_cg_group_with_nagvis_maps(web, site):
os.unlink(dummy_map_filepath2)
-
+# TODO: Parameterize test for cme / non cme
@pytest.mark.parametrize(("group_type"), [ "contact",
"host", "service" ])
def test_delete_group(web, group_type):
group_id = "%s_testgroup_id" % group_type
group_alias = "%s_testgroup_alias" % group_type
try:
- web.add_group(group_type, group_id, {"alias": group_alias})
+ attributes = {"alias": group_alias}
+
+ if cmk.is_managed_edition():
+ attributes["customer"] = "provider"
+
+ web.add_group(group_type, group_id, attributes)
finally:
web.delete_group(group_type, group_id)
diff --git a/web/htdocs/webapi.py b/web/htdocs/webapi.py
index f84f935..ce070ee 100644
--- a/web/htdocs/webapi.py
+++ b/web/htdocs/webapi.py
@@ -32,6 +32,11 @@ import config
from watolib import *
from valuespec import *
+if cmk.is_managed_edition():
+ import managed
+else:
+ managed = None
+
try:
import simplejson as json
except ImportError:
diff --git a/web/plugins/webapi/webapi.py b/web/plugins/webapi/webapi.py
index 99c6433..d24ef58 100644
--- a/web/plugins/webapi/webapi.py
+++ b/web/plugins/webapi/webapi.py
@@ -466,17 +466,27 @@ def action_delete_group(request, group_type):
def get_group_extra_info(request, group_type):
extra_info = {}
extra_info["alias"] = request.get("alias")
+
if group_type == "contact" and "nagvis_maps" in request:
extra_info["nagvis_maps"] = request["nagvis_maps"]
+
+ if cmk.is_managed_edition():
+ extra_info["customer"] = request["customer"]
+
return extra_info
def validate_group_request_keys(request, group_type):
+ required_keys = ["groupname", "alias"]
+
+ if cmk.is_managed_edition():
+ required_keys.append("customer")
+
if group_type == "contact":
- validate_request_keys(request, required_keys=["groupname",
"alias"],
+ validate_request_keys(request, required_keys=required_keys,
optional_keys=["nagvis_maps"])
else:
- validate_request_keys(request, required_keys=["groupname",
"alias"])
+ validate_request_keys(request, required_keys=required_keys)
def action_add_group(request, group_type):