コード例 #1
0
ファイル: ldap.py プロジェクト: spearheadsys/checkmk
    def action(self):
        connections = userdb.load_connection_config(lock=True)
        if html.request.has_var("_delete"):
            index = int(html.request.var("_delete"))
            connection = connections[index]
            c = wato_confirm(
                _("Confirm deletion of LDAP connection"),
                _("Do you really want to delete the LDAP connection <b>%s</b>?"
                  ) % (connection["id"]))
            if c:
                self._add_change(
                    "delete-ldap-connection",
                    _("Deleted LDAP connection %s") % (connection["id"]))
                del connections[index]
                userdb.save_connection_config(connections)
            elif c is False:
                return ""
            else:
                return

        elif html.request.has_var("_move"):
            if not html.check_transaction():
                return

            from_pos = html.get_integer_input("_move")
            to_pos = html.get_integer_input("_index")
            connection = connections[from_pos]
            self._add_change(
                "move-ldap-connection",
                _("Changed position of LDAP connection %s to %d") %
                (connection["id"], to_pos))
            del connections[from_pos]  # make to_pos now match!
            connections[to_pos:to_pos] = [connection]
            userdb.save_connection_config(connections)
コード例 #2
0
ファイル: test_http.py プロジェクト: n00rm/checkmk
def test_request_processing(register_builtin_html):
    html.request.set_var("varname", "1a")
    html.request.set_var("varname2", "1")

    html.get_unicode_input("varname", deflt="lol")
    html.get_integer_input("varname2")
    html.get_request(exclude_vars=["varname2"])
コード例 #3
0
    def _move_tag_group(self):
        move_nr = html.get_integer_input("_move")
        move_to = html.get_integer_input("_index")

        moved = self._tag_config.tag_groups.pop(move_nr)
        self._tag_config.tag_groups.insert(move_to, moved)

        self._tag_config.validate_config()
        self._tag_config_file.save(self._tag_config.get_dict_format())
        watolib.add_change("edit-tags", _("Changed order of tag groups"))
コード例 #4
0
    def _move_tag_group(self):
        move_nr = html.get_integer_input("_move")
        move_to = html.get_integer_input("_index")

        moved = self._tag_config.tag_groups.pop(move_nr)
        self._tag_config.tag_groups.insert(move_to, moved)

        try:
            self._tag_config.validate_config()
        except MKGeneralException as e:
            raise MKUserError(None, "%s" % e)
        self._tag_config_file.save(self._tag_config.get_dict_format())
        self._load_effective_config()
        watolib.add_change("edit-tags", _("Changed order of tag groups"))
コード例 #5
0
def handle_acknowledgement():
    if html.request.var("_werk_ack") and html.check_transaction():
        werk_id = html.get_integer_input("_werk_ack")
        if werk_id not in g_werks:
            raise MKUserError("werk", _("This werk does not exist."))
        werk = g_werks[werk_id]

        if werk["compatible"] == "incomp_unack":
            acknowledge_werk(werk)
            html.message(
                _("Werk %s - %s has been acknowledged.") % (render_werk_id(
                    werk, with_link=True), render_werk_title(werk)))
            html.reload_sidebar()
            load_werks()  # reload ack states after modification

    elif html.request.var("_ack_all"):
        if html.confirm(_(
                "Do you really want to acknowledge <b>all</b> incompatible werks?"
        ),
                        method="GET"):
            num = len(unacknowledged_incompatible_werks())
            acknowledge_all_werks()
            html.message(
                _("%d incompatible Werks have been acknowledged.") % num)
            html.reload_sidebar()
            load_werks()  # reload ack states after modification

    render_unacknowleged_werks()
コード例 #6
0
    def action(self):
        if not html.check_transaction():
            return

        test_id = html.request.var("_test_id")
        site_id = html.request.var("_site_id")
        status_id = html.get_integer_input("_status_id", 0)

        if not test_id:
            raise MKUserError("_ack_test_id", _("Needed variable missing"))

        if html.request.var("_do") in ["ack", "unack"]:
            if not site_id:
                raise MKUserError("_ack_site_id", _("Needed variable missing"))

            if site_id not in activation_sites():
                raise MKUserError("_ack_site_id", _("Invalid site given"))

        if html.request.var("_do") == "ack":
            self._acknowledge_test(test_id, site_id, status_id)

        elif html.request.var("_do") == "unack":
            self._unacknowledge_test(test_id, site_id, status_id)

        elif html.request.var("_do") == "disable":
            self._disable_test(test_id)

        elif html.request.var("_do") == "enable":
            self._enable_test(test_id)

        else:
            raise NotImplementedError()
コード例 #7
0
ファイル: utils.py プロジェクト: stefan927/checkmk
    def _get_time_range_of(self, what):
        varprefix = self.ident + "_" + what

        rangename = html.request.var(varprefix + "_range")
        if rangename == "abs":
            try:
                return time.mktime(time.strptime(html.request.var(varprefix), "%Y-%m-%d"))
            except Exception:
                html.add_user_error(varprefix, _("Please enter the date in the format YYYY-MM-DD."))
                return None

        elif rangename == "unix":
            return html.get_integer_input(varprefix)

        try:
            count = html.get_integer_input(varprefix)
            secs = count * int(rangename)
            return int(time.time()) - secs
        except Exception:
            html.request.set_var(varprefix, "")
            return None
コード例 #8
0
def page_werk():
    load_werks()
    werk_id = html.get_integer_input("werk")
    if werk_id not in g_werks:
        raise MKUserError("werk", _("This werk does not exist."))
    werk = g_werks[werk_id]

    html.header(
        ("%s %s - %s") %
        (_("Werk"), render_werk_id(werk, with_link=False), werk["title"]))
    html.begin_context_buttons()
    back_url = html.makeuri([], filename="version.py",
                            delvars=["werk"])  # keeps filter settings
    html.context_button(_("Back"), back_url, "back")
    if werk["compatible"] == "incomp_unack" and may_acknowledge():
        ack_url = html.makeactionuri([("_werk_ack", werk["id"])],
                                     filename="version.py")
        html.context_button(_("Acknowledge"), ack_url, "werk_ack")
    html.end_context_buttons()

    html.open_table(class_=["data", "headerleft", "werks"])

    def werk_table_row(caption, content, css=None):
        html.open_tr()
        html.th(caption)
        html.open_td(class_=css)
        html.write(content)
        html.close_td()
        html.close_tr()

    translator = cmk.utils.werks.WerkTranslator()
    werk_table_row(_("ID"), render_werk_id(werk, with_link=False))
    werk_table_row(_("Title"), html.render_b(render_werk_title(werk)))
    werk_table_row(_("Component"), translator.component_of(werk))
    werk_table_row(_("Date"), render_werk_date(werk))
    werk_table_row(_("Check_MK Version"), werk["version"])
    werk_table_row(_("Level"),
                   translator.level_of(werk),
                   css="werklevel werklevel%d" % werk["level"])
    werk_table_row(_("Class"),
                   translator.class_of(werk),
                   css="werkclass werkclass%s" % werk["class"])
    werk_table_row(_("Compatibility"),
                   translator.compatibility_of(werk),
                   css="werkcomp werkcomp%s" % werk["compatible"])
    werk_table_row(_("Description"),
                   render_werk_description(werk),
                   css="nowiki")

    html.close_table()

    html.footer()
コード例 #9
0
def test_get_integer_input(register_builtin_html):
    html.request.set_var("number", "2")
    html.request.set_var("float", "2.2")
    html.request.set_var("not_a_number", "a")

    with pytest.raises(MKUserError) as e:
        html.get_integer_input("not_existing")
    assert "is missing" in "%s" % e

    assert html.get_integer_input("get_default", 1) == 1

    assert html.get_integer_input("number") == 2

    with pytest.raises(MKUserError) as e:
        html.get_integer_input("bla")
    assert "is missing" in "%s" % e

    with pytest.raises(MKUserError) as e:
        html.get_integer_input("float")
    assert "is not an integer" in "%s" % e

    with pytest.raises(MKUserError) as e:
        html.get_integer_input("not_a_number")
    assert "is not an integer" in "%s" % e
コード例 #10
0
 def tristate_value(self):
     return html.get_integer_input(self.varname, self.deflt)