コード例 #1
0
ファイル: weblib.py プロジェクト: petrows/checkmk
def ajax_set_rowselection() -> None:
    ident = request.get_str_input_mandatory('id')
    action = request.get_str_input_mandatory('action', 'set')
    if action not in ['add', 'del', 'set', 'unset']:
        raise MKUserError(None, _('Invalid action'))

    rows = request.get_str_input_mandatory('rows', '').split(',')
    user.set_rowselection(selection_id(), ident, rows, action)
コード例 #2
0
def ajax_set_rowselection() -> None:
    ident = request.get_str_input_mandatory("id")
    action = request.get_str_input_mandatory("action", "set")
    if action not in ["add", "del", "set", "unset"]:
        raise MKUserError(None, _("Invalid action"))

    rows = request.get_str_input_mandatory("rows", "").split(",")
    user.set_rowselection(selection_id(), ident, rows, action)
コード例 #3
0
    def _import(self, csv_reader: CSVReader) -> ActionResult:
        if self._has_title_line:
            try:
                next(csv_reader)  # skip header
            except StopIteration:
                pass

        num_succeeded, num_failed = 0, 0
        fail_messages = []
        selected = []
        imported_hosts = []

        for row_num, row in enumerate(csv_reader):
            if not row:
                continue  # skip empty lines

            host_name, attributes = self._get_host_info_from_row(row, row_num)
            try:
                watolib.Folder.current().create_hosts(
                    [(host_name, attributes, None)],
                    bake_hosts=False,
                )
                imported_hosts.append(host_name)
                selected.append("_c_%s" % host_name)
                num_succeeded += 1
            except Exception as e:
                fail_messages.append(
                    _("Failed to create a host from line %d: %s") %
                    (csv_reader.line_num, e))
                num_failed += 1

        watolib.hosts_and_folders.try_bake_agents_for_hosts(imported_hosts)

        self._delete_csv_file()

        msg = _("Imported %d hosts into the current folder.") % num_succeeded
        if num_failed:
            msg += "<br><br>" + (_("%d errors occured:") % num_failed)
            msg += "<ul>"
            for fail_msg in fail_messages:
                msg += "<li>%s</li>" % fail_msg
            msg += "</ul>"

        folder_path = watolib.Folder.current().path()
        if num_succeeded > 0 and request.var("do_service_detection") == "1":
            # Create a new selection for performing the bulk discovery
            user.set_rowselection(
                weblib.selection_id(),
                "wato-folder-/" + folder_path,
                selected,
                "set",
            )
            return redirect(
                mode_url(
                    "bulkinventory",
                    _bulk_inventory="1",
                    show_checkboxes="1",
                    folder=folder_path,
                    selection=weblib.selection_id(),
                ))
        flash(msg)
        return redirect(mode_url("folder", folder=folder_path))