Beispiel #1
0
def test_diagnostics_element_checkmk_overview():
    diagnostics_element = diagnostics.CheckmkOverviewDiagnosticsElement()
    assert diagnostics_element.ident == "checkmk_overview"
    assert diagnostics_element.title == "Checkmk Overview of Checkmk Server"
    assert diagnostics_element.description == (
        "Checkmk Agent, Number, version and edition of sites, Cluster host; "
        "Number of hosts, services, CMK Helper, Live Helper, "
        "Helper usage; State of daemons: Apache, Core, Crontag, "
        "DCD, Liveproxyd, MKEventd, MKNotifyd, RRDCached "
        "(Agent plugin mk_inventory needs to be installed)")
Beispiel #2
0
def test_diagnostics_element_checkmk_overview_content(monkeypatch, tmp_path,
                                                      _fake_local_connection,
                                                      _collectors, host_list,
                                                      host_tree):

    diagnostics_element = diagnostics.CheckmkOverviewDiagnosticsElement()

    monkeypatch.setattr(livestatus, "LocalConnection",
                        _fake_local_connection(host_list))

    if host_tree:
        # Fake HW/SW inventory tree
        inventory_dir = Path(cmk.utils.paths.inventory_output_dir)
        inventory_dir.mkdir(parents=True, exist_ok=True)
        with inventory_dir.joinpath("checkmk-server-name").open("w") as f:
            f.write(repr(host_tree))

    tmppath = Path(tmp_path).joinpath("tmp")
    filepath = next(diagnostics_element.add_or_get_files(tmppath, _collectors))

    assert isinstance(filepath, Path)
    assert filepath == tmppath.joinpath("checkmk_overview.json")

    content = json.loads(filepath.open().read())

    assert content["Nodes"]["cluster"]["Attributes"]["Pairs"] == {
        "is_cluster": False,
    }

    assert content["Nodes"]["sites"]["Table"]["Rows"] == [
        {
            "autostart": False,
            "site": "heute",
            "used_version": "2020.06.09.cee",
        },
    ]

    assert content["Nodes"]["versions"]["Table"]["Rows"] == [
        {
            "demo": False,
            "edition": "cee",
            "num_sites": 0,
            "number": "2020.06.07",
            "version": "2020.06.07.cee",
        },
        {
            "demo": False,
            "edition": "cee",
            "num_sites": 1,
            "number": "2020.06.09",
            "version": "2020.06.09.cee",
        },
    ]

    shutil.rmtree(str(inventory_dir))
Beispiel #3
0
def test_diagnostics_element_checkmk_overview_content(monkeypatch, tmp_path,
                                                      _fake_local_connection,
                                                      _collectors, host_list,
                                                      host_tree):

    diagnostics_element = diagnostics.CheckmkOverviewDiagnosticsElement()

    monkeypatch.setattr(livestatus, "LocalConnection",
                        _fake_local_connection(host_list))

    if host_tree:
        # Fake HW/SW inventory tree
        inventory_dir = Path(cmk.utils.paths.inventory_output_dir)
        inventory_dir.mkdir(parents=True, exist_ok=True)
        with inventory_dir.joinpath("checkmk-server-name").open("w") as f:
            f.write(repr(host_tree))

    tmppath = Path(tmp_path).joinpath("tmp")
    filepath = next(diagnostics_element.add_or_get_files(tmppath, _collectors))

    assert isinstance(filepath, Path)
    assert filepath == tmppath.joinpath("checkmk_overview.json")

    content = json.loads(filepath.open().read())

    assert content["cluster"] == {
        'is_cluster': False,
    }

    assert content["sites"] == [
        {
            'autostart': False,
            'site': 'heute',
            'used_version': '2020.06.09.cee',
        },
    ]

    assert content["versions"] == [
        {
            'demo': False,
            'edition': 'cee',
            'num_sites': 0,
            'number': '2020.06.07',
            'version': '2020.06.07.cee',
        },
        {
            'demo': False,
            'edition': 'cee',
            'num_sites': 1,
            'number': '2020.06.09',
            'version': '2020.06.09.cee',
        },
    ]

    shutil.rmtree(str(inventory_dir))
Beispiel #4
0
def test_diagnostics_element_checkmk_overview_error(monkeypatch, tmp_path, _fake_local_connection,
                                                    _collectors, host_list, host_tree, error):
    diagnostics_element = diagnostics.CheckmkOverviewDiagnosticsElement()

    monkeypatch.setattr(livestatus, "LocalConnection", _fake_local_connection(host_list))

    if host_tree:
        # Fake HW/SW inventory tree
        inventory_dir = Path(cmk.utils.paths.inventory_output_dir)
        inventory_dir.mkdir(parents=True, exist_ok=True)
        with inventory_dir.joinpath("checkmk-server-name").open("w") as f:
            f.write(repr(host_tree))

    tmppath = Path(tmp_path).joinpath("tmp")

    with pytest.raises(diagnostics.DiagnosticsElementError) as e:
        next(diagnostics_element.add_or_get_files(tmppath, _collectors))
        assert error == str(e)

    if host_tree:
        shutil.rmtree(str(inventory_dir))