예제 #1
0
    def _from_vars(self):
        self._check_type = html.request.get_ascii_input_mandatory("check_type", "")

        if not re.match("^[a-zA-Z0-9_.]+$", self._check_type):
            raise MKUserError("check_type", _("Invalid check type"))

        manpage = man_pages.load_man_page(self._check_type)
        if manpage is None:
            raise MKUserError(None, _("There is no manpage for this check."))
        self._manpage = manpage

        checks = watolib.check_mk_local_automation("get-check-information")
        if self._check_type in checks:
            self._manpage = {
                "type": "check_mk",
                **checks[self._check_type],
                **self._manpage,
            }
        elif self._check_type.startswith("check_"):  # Assume active check
            self._manpage = {
                "type": "active",
                **self._manpage,
            }
        elif self._check_type in ['check-mk', "check-mk-inventory"]:
            self._manpage = {
                "type": "check_mk",
                "service_description": "Check_MK%s" %
                                       ("" if self._check_type == "check-mk" else " Discovery"),
                **self._manpage,
            }
예제 #2
0
def test_load_man_page_format():
    page = man_pages.load_man_page("if64")
    assert type(page) == dict

    _check_man_page_structure(page)

    # Check optional keys
    for key in ['item', 'inventory']:
        assert key in page["header"]
예제 #3
0
def test_missing_catalog_entries_of_man_pages():
    catalog_titles = set(man_pages.catalog_titles.keys())
    found_catalog_entries_from_man_pages = set()
    for name in man_pages.all_man_pages():
        man_page = man_pages.load_man_page(name)
        found_catalog_entries_from_man_pages |= set(man_page['header']['catalog'].split("/"))
    missing_catalog_entries = found_catalog_entries_from_man_pages - catalog_titles
    assert missing_catalog_entries == set(), "Found missing catalog entries: %s" % ", ".join(
        sorted(missing_catalog_entries))
예제 #4
0
def get_all_pages() -> ManPages:
    base_dirs = [
        Path(cpe_path(), "checkman"),
        Path(cmk_path(), "checkman"),
    ]
    return {
        name: man_pages.load_man_page(name, base_dirs)
        for name in man_pages.all_man_pages(base_dirs)
    }
예제 #5
0
    def _from_vars(self) -> None:
        self._check_plugin_name = request.get_ascii_input_mandatory(
            "check_type", "")

        check_builtins = ["check-mk", "check-mk-inventory"]
        if (not re.match("^[a-zA-Z0-9_.]+$", self._check_plugin_name)
                and self._check_plugin_name not in check_builtins):
            raise MKUserError("check_type", _("Invalid check type"))

        manpage = man_pages.load_man_page(self._check_plugin_name)
        if manpage is None:
            raise MKUserError(None, _("There is no manpage for this check."))
        self._manpage = manpage

        checks = get_check_information().plugin_infos
        if (check_info := checks.get(self._check_plugin_name)) is not None:
            self._check_type = "check_mk"
            self._service_description = check_info["service_description"]
            self._ruleset: Optional[
                str] = f"checkgroup_parameters:{check_info['check_ruleset_name']}"
예제 #6
0
    def _from_vars(self):
        self._check_type = request.get_ascii_input_mandatory("check_type", "")

        builtin_check_types = ["check-mk", "check-mk-inventory"]
        if (not re.match("^[a-zA-Z0-9_.]+$", self._check_type)
                and self._check_type not in builtin_check_types):
            raise MKUserError("check_type", _("Invalid check type"))

        manpage = man_pages.load_man_page(self._check_type)
        if manpage is None:
            raise MKUserError(None, _("There is no manpage for this check."))
        self._manpage = manpage

        checks = get_check_information().plugin_infos
        if self._check_type in checks:
            self._manpage = {
                "type": "check_mk",
                **checks[self._check_type],
                **self._manpage,
            }
        elif self._check_type.startswith("check_"):  # Assume active check
            self._manpage = {
                "type": "active",
                **self._manpage,
            }
        elif self._check_type in builtin_check_types:
            self._manpage = {
                "type":
                "check_mk",
                "service_description":
                "Check_MK%s" %
                ("" if self._check_type == "check-mk" else " Discovery"),
                **self._manpage,
            }
        else:
            raise MKUserError(
                None,
                _("Could not detect type of manpage: %s. Maybe the check is missing "
                  ) % self._check_type,
            )
예제 #7
0
def test_load_all_man_pages():
    for name in man_pages.all_man_pages().keys():
        man_page = man_pages.load_man_page(name)
        assert type(man_page) == dict
        _check_man_page_structure(man_page)
예제 #8
0
def test_load_man_page_not_existing():
    assert man_pages.load_man_page("not_existing") is None
예제 #9
0
def test_load_all_man_pages():
    for name in man_pages.all_man_pages():
        man_page = man_pages.load_man_page(name)
        assert isinstance(man_page, dict)
        _check_man_page_structure(man_page)
예제 #10
0
def _get_all_pages():
    return {
        name: man_pages.load_man_page(name)
        for name in man_pages.all_man_pages()
    }
예제 #11
0
def get_all_pages() -> ManPages:
    return {
        name: man_pages.load_man_page(name)
        for name in man_pages.all_man_pages()
    }