def graph_test_config(web, site): # No graph yet... with pytest.raises(APIError) as exc_info: web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True) assert "Cannot calculate graph recipes" in "%s" % exc_info try: # Now add the host web.add_host("test-host-get-graph", attributes={ "ipaddress": "127.0.0.1", }) site.write_file( "etc/check_mk/conf.d/test-host-get-graph.mk", "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ['test-host-get-graph']))\n" ) site.makedirs("var/check_mk/agent_output/") site.write_file( "var/check_mk/agent_output/test-host-get-graph", open( "%s/tests/integration/cmk/base/test-files/linux-agent-output" % repo_path()).read()) web.discover_services("test-host-get-graph") web.activate_changes() site.schedule_check("test-host-get-graph", "Check_MK", 0) # Wait for RRD file creation. Isn't this a bug that the graph is not instantly available? rrd_path = site.path( "var/check_mk/rrd/test-host-get-graph/Check_MK.rrd") for attempt in xrange(50): time.sleep(0.1) proc = subprocess.Popen([ site.path("bin/unixcat"), site.path("tmp/run/rrdcached.sock") ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate("FLUSH %s\n" % rrd_path) if os.path.exists(rrd_path): break sys.stdout.write("waiting for %s (attempt %d)%s%s\n" % ( rrd_path, attempt + 1, # ", stdout: %s" % out if out else "", ", stderr: %s" % err if err else "")) else: assert False, "RRD file %s missing" % rrd_path yield finally: web.delete_host("test-host-get-graph") site.delete_file("etc/check_mk/conf.d/test-host-get-graph.mk") web.activate_changes()
def graph_test_config(web, site): # No graph yet... with pytest.raises(APIError) as e: web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True) assert "Cannot calculate graph recipes" in "%s" % e try: # Now add the host web.add_host("test-host-get-graph", attributes={ "ipaddress": "127.0.0.1", }) site.write_file( "etc/check_mk/conf.d/test-host-get-graph.mk", "datasource_programs.append(('cat ~/var/check_mk/agent_output/<HOST>', [], ['test-host-get-graph']))\n" ) site.makedirs("var/check_mk/agent_output/") site.write_file( "var/check_mk/agent_output/test-host-get-graph", file( "%s/tests/integration/cmk_base/test-files/linux-agent-output" % repo_path()).read()) web.discover_services("test-host-get-graph") web.activate_changes() site.schedule_check("test-host-get-graph", "Check_MK", 0) # Wait for RRD file creation # Isn't this a bug that the graph is not instantly available? timeout = 10 print "Checking for graph..." while timeout and not site.file_exists( "var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"): try: web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True) except Exception: pass timeout -= 1 time.sleep(1) print "Checking for graph..." assert site.file_exists("var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"), \ "RRD %s is still missing" % "var/check_mk/rrd/test-host-get-graph/Check_MK.rrd" yield finally: web.delete_host("test-host-get-graph") site.delete_file("etc/check_mk/conf.d/test-host-get-graph.mk") web.activate_changes()
def test_get_graph(web, site): try: # No graph yet... with pytest.raises(APIError) as e: data = web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True) assert "Cannot calculate graph recipes" in "%s" % e # Now add the host web.add_host("test-host-get-graph", attributes={ "ipaddress": "127.0.0.1", }) web.discover_services("test-host-get-graph") web.activate_changes() # Issue a reschedule site.live.command( "SCHEDULE_FORCED_SERVICE_CHECK;test-host-get-graph;Check_MK;%d" % int(time.time())) # Wait for RRD file creation # Isn't this a bug that the graph is not instantly available? timeout = 10 print "Checking for graph..." while timeout and not site.file_exists( "var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"): try: data = web.get_regular_graph("test-host-get-graph", "Check_MK", 0, expect_error=True) except Exception: pass timeout -= 1 time.sleep(1) print "Checking for graph..." assert site.file_exists("var/check_mk/rrd/test-host-get-graph/Check_MK.rrd"), \ "RRD %s is still missing" % "var/check_mk/rrd/test-host-get-graph/Check_MK.rrd" _test_get_graph_api(web) _test_get_graph_image(web) _test_get_graph_notification_image(web) finally: web.delete_host("test-host-get-graph") web.activate_changes()
def test_get_graph_api(web, graph_test_config): # Now we get a graph data = web.get_regular_graph("test-host-get-graph", "Check_MK", 0) assert len(data["curves"]) == 5 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"] == "Time spent waiting for special agent" assert data["curves"][4]["title"] == "Total execution time"