Пример #1
0
def _validate_general_host_attributes(host_attributes, new):
    # inventory_failed and site are no "real" host_attributes (TODO: Clean this up!)
    all_host_attribute_names = list(
        host_attribute_registry.keys()) + ["inventory_failed", "site"]
    for name, value in host_attributes.items():
        if name not in all_host_attribute_names:
            raise MKUserError(
                None,
                _("Unknown attribute: %s") % escaping.escape_attribute(name))

        # For real host attributes validate the values
        try:
            attr = watolib.host_attribute(name)
        except KeyError:
            attr = None

        if attr is not None:
            if attr.needs_validation("host", new):
                attr.validate_input(value, "")

        # The site attribute gets an extra check
        if name == "site" and value not in config.allsites().keys():
            raise MKUserError(
                None,
                _("Unknown site %s") % escaping.escape_attribute(value))
Пример #2
0
    def _activate_changes(self, request):
        mode = request.get("mode", "dirty")
        if request.get("allow_foreign_changes"):
            allow_foreign_changes = bool(
                int(request.get("allow_foreign_changes")))
        else:
            allow_foreign_changes = False

        sites = request.get("sites")

        changes = watolib.ActivateChanges()
        changes.load()

        if changes.has_foreign_changes():
            if not config.user.may("wato.activateforeign"):
                raise MKAuthException(
                    _("You are not allowed to activate changes of other users."
                      ))
            if not allow_foreign_changes:
                raise MKAuthException(
                    _("There are changes from other users and foreign changes are not allowed in this API call."
                      ))

        if mode == "specific":
            for site in sites:
                if site not in config.allsites().keys():
                    raise MKUserError(
                        None,
                        _("Unknown site %s") % escaping.escape_attribute(site))

        manager = watolib.ActivateChangesManager()
        manager.load()

        if not manager.has_changes():
            raise MKUserError(None,
                              _("Currently there are no changes to activate."))

        if not sites:
            sites = manager.dirty_and_active_activation_sites()

        comment = request.get("comment", "").strip()
        if comment == "":
            comment = None

        manager.start(sites,
                      comment=comment,
                      activate_foreign=allow_foreign_changes)
        manager.wait_for_completion()
        return manager.get_state()
Пример #3
0
    def show(self):
        only_sites = snapin_site_choice("performance",
                                        config.get_configured_site_choices())

        def write_line(left, right, show_more):
            html.open_tr(class_="show_more_mode" if show_more else "basic")
            html.td(left, class_="left")
            html.td(html.render_strong(right), class_="right")
            html.close_tr()

        html.open_table(class_=["content_center", "performance"])

        try:
            sites.live().set_only_sites(only_sites)
            data = sites.live().query(
                "GET status\nColumns: service_checks_rate host_checks_rate "
                "external_commands_rate connections_rate forks_rate "
                "log_messages_rate cached_log_messages\n")
        finally:
            sites.live().set_only_sites(None)

        for what, show_more, col, format_str in \
            [("Service checks",         False, 0, "%.2f/s"),
             ("Host checks",            False, 1, "%.2f/s"),
             ("External commands",      True, 2, "%.2f/s"),
             ("Livestatus-conn.",       True, 3, "%.2f/s"),
             ("Process creations",      True, 4, "%.2f/s"),
             ("New log messages",       True, 5, "%.2f/s"),
             ("Cached log messages",    True, 6, "%d")]:
            write_line(what + ":",
                       format_str % sum(row[col] for row in data),
                       show_more=show_more)

        if only_sites is None and len(config.allsites()) == 1:
            try:
                data = sites.live().query(
                    "GET status\nColumns: external_command_buffer_slots "
                    "external_command_buffer_max\n")
            finally:
                sites.live().set_only_sites(None)
            size = sum([row[0] for row in data])
            maxx = sum([row[1] for row in data])
            write_line(_('Com. buf. max/total'),
                       "%d / %d" % (maxx, size),
                       show_more=True)

        html.close_table()
Пример #4
0
 def _validate(self, value):
     if value not in config.allsites().keys():
         self.fail("unknown_site", site=value)
Пример #5
0
 def _validate(self, value):
     if value not in config.allsites().keys():
         raise self.make_error("unknown_site", site=value)