def test_diagnostics_element_performance_graphs_content(monkeypatch, tmp_path, _fake_local_connection, _collectors, host_list, status_code, text, content): diagnostics_element = diagnostics.PerformanceGraphsDiagnosticsElement() monkeypatch.setattr(livestatus, "LocalConnection", _fake_local_connection(host_list)) FakeResponse = collections.namedtuple("FakeResponse", ["status_code", "text", "content"]) monkeypatch.setattr(requests, "post", lambda *arg, **kwargs: FakeResponse(status_code, text, content)) automation_dir = Path(cmk.utils.paths.var_dir) / "web" / "automation" automation_dir.mkdir(parents=True, exist_ok=True) with automation_dir.joinpath("automation.secret").open("w") as f: f.write("my-123-password") etc_omd_dir = Path(cmk.utils.paths.omd_root) / "etc" / "omd" etc_omd_dir.mkdir(parents=True, exist_ok=True) with etc_omd_dir.joinpath("site.conf").open("w") as f: f.write("""CONFIG_APACHE_TCP_ADDR='127.0.0.1' CONFIG_APACHE_TCP_PORT='5000'""") tmppath = Path(tmp_path).joinpath("tmp") tmppath.mkdir(parents=True, exist_ok=True) filepath = next(diagnostics_element.add_or_get_files(tmppath, _collectors)) assert isinstance(filepath, Path) assert filepath == tmppath.joinpath("performance_graphs.pdf") shutil.rmtree(str(automation_dir)) shutil.rmtree(str(etc_omd_dir))
def test_diagnostics_element_performance_graphs(): diagnostics_element = diagnostics.PerformanceGraphsDiagnosticsElement() assert diagnostics_element.ident == "performance_graphs" assert diagnostics_element.title == "Performance Graphs of Checkmk Server" assert diagnostics_element.description == ( "CPU load and utilization, Number of threads, Kernel Performance, " "OMD, Filesystem, Apache Status, TCP Connections of the time ranges " "25 hours and 35 days")
def test_diagnostics_element_performance_graphs_error( monkeypatch, tmp_path, _fake_local_connection, _collectors, host_list, status_code, text, content, error, ): diagnostics_element = diagnostics.PerformanceGraphsDiagnosticsElement() monkeypatch.setattr(livestatus, "LocalConnection", _fake_local_connection(host_list)) class FakeResponse(NamedTuple): status_code: int text: str content: str monkeypatch.setattr( requests, "post", lambda *arg, **kwargs: FakeResponse(status_code, text, content) ) automation_dir = Path(cmk.utils.paths.var_dir) / "web" / "automation" automation_dir.mkdir(parents=True, exist_ok=True) with automation_dir.joinpath("automation.secret").open("w") as f: f.write("my-123-password") etc_omd_dir = cmk.utils.paths.omd_root / "etc" / "omd" etc_omd_dir.mkdir(parents=True, exist_ok=True) with etc_omd_dir.joinpath("site.conf").open("w") as f: f.write( """CONFIG_APACHE_TCP_ADDR='127.0.0.1' CONFIG_APACHE_TCP_PORT='5000'""" ) tmppath = Path(tmp_path).joinpath("tmp") tmppath.mkdir(parents=True, exist_ok=True) with pytest.raises(diagnostics.DiagnosticsElementError) as e: next(diagnostics_element.add_or_get_files(tmppath, _collectors)) assert error == str(e) shutil.rmtree(str(automation_dir)) shutil.rmtree(str(etc_omd_dir))