Module: check_mk
Branch: master
Commit: c5b5f99929a18867aa57e3a69f717989eddcb588
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c5b5f99929a188…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Dec 2 10:33:16 2016 +0100
Added test for new get_graph API
---
tests/testlib/__init__.py | 37 ++++++++++++++++++++++-
tests/web/{test_wato_webapi.py => test_webapi.py} | 20 ++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/tests/testlib/__init__.py b/tests/testlib/__init__.py
index 3dd9cd5..aeac117 100644
--- a/tests/testlib/__init__.py
+++ b/tests/testlib/__init__.py
@@ -749,7 +749,7 @@ class CMKWebSession(WebSession):
})
assert type(result) == unicode
- assert result.startswith("Service discovery successful")
+ assert result.startswith("Service discovery successful"), "Failed
to discover: %r" % result
def activate_changes(self, mode=None, allow_foreign_changes=None):
@@ -774,6 +774,41 @@ class CMKWebSession(WebSession):
assert status["_time_ended"] > time_started
+ def get_regular_graph(self, hostname, service_description, graph_index):
+ result = self._api_request("webapi.py?action=get_graph", {
+ "request": json.dumps({
+ "specification": ["template", {
+ "service_description" : service_description,
+ "site" : self.site.id,
+ "graph_index" : graph_index,
+ "host_name" : hostname,
+ }],
+ "data_range": {
+ "time_range": [time.time()-3600, time.time()]
+ }
+ }),
+ })
+
+ assert type(result) == dict
+ assert "start_time" in result
+ assert type(result["start_time"]) == int
+ assert "end_time" in result
+ assert type(result["end_time"]) == int
+ assert "step" in result
+ assert type(result["step"]) == int
+ assert "curves" in result
+ assert type(result["curves"]) == list
+ assert len(result["curves"]) > 0
+
+ for curve in result["curves"]:
+ assert "color" in curve
+ assert "rrddata" in curve
+ assert "line_type" in curve
+ assert "title" in curve
+
+ return result
+
+
class CMKEventConsole(CMKWebSession):
def __init__(self, site):
super(CMKEventConsole, self).__init__(site)
diff --git a/tests/web/test_wato_webapi.py b/tests/web/test_webapi.py
similarity index 68%
rename from tests/web/test_wato_webapi.py
rename to tests/web/test_webapi.py
index d83c2d4..5551356 100644
--- a/tests/web/test_wato_webapi.py
+++ b/tests/web/test_webapi.py
@@ -64,3 +64,23 @@ def test_activate_changes(web, site):
finally:
web.delete_host("test-host-activate")
web.activate_changes()
+
+
+def test_get_graph(web):
+ try:
+ web.add_host("test-host-get-graph", attributes={
+ "ipaddress": "127.0.0.1",
+ })
+ web.discover_services("test-host-get-graph")
+ web.activate_changes()
+
+ data = web.get_regular_graph("test-host-get-graph",
"Check_MK", 0)
+ assert len(data["curves"]) == 4
+ assert data["curves"][0]["title"] == "CPU time in user
space"
+ assert data["curves"][1]["title"] == "CPU time in
operating system"
+ assert data["curves"][2]["title"] == "Time spent waiting
for Check_MK agent"
+ assert data["curves"][3]["title"] == "Total execution
time"
+
+ finally:
+ web.delete_host("test-host-get-graph")
+ web.activate_changes()