def _search_url(self, ident): return html.makeuri_contextless([ ("mode", "rulesets"), ("search_p_rule_predefined_condition", DropdownChoice.option_id(ident)), ("search_p_rule_predefined_condition_USE", "on") ])
def _page_menu_entries_this_folder(self) -> Iterator[PageMenuEntry]: if self._folder.may("read"): yield PageMenuEntry( title=_("Properties"), icon_name="edit", item=make_simple_link(self._folder.edit_url(backfolder=self._folder)), ) if not self._folder.locked_subfolders() and not self._folder.locked(): if self._folder.may("write") and config.user.may("wato.manage_folders"): yield PageMenuEntry( title=_("Add subfolder"), icon_name="newfolder", item=make_simple_link(self._folder.url([("mode", "newfolder")])), is_shortcut=True, is_suggested=True, ) yield make_folder_status_link(watolib.Folder.current(), view_name="allhosts") if config.user.may("wato.rulesets") or config.user.may("wato.seeall"): yield PageMenuEntry( title=_("Rules"), icon_name="rulesets", item=make_simple_link( watolib.folder_preserving_link([ ("mode", "rule_search"), ("filled_in", "rule_search"), ("folder", watolib.Folder.current().path()), ("search_p_ruleset_used", DropdownChoice.option_id(True)), ("search_p_ruleset_used_USE", "on"), ])), )
def make_object_audit_log_url(object_ref: ObjectRef) -> str: return makeuri_contextless(request, [ ("mode", "auditlog"), ("options_object_type", DropdownChoice.option_id(object_ref.object_type)), ("options_object_ident", object_ref.ident), ], filename="wato.py")
def _search_url(self, ident): return makeuri_contextless( request, [("mode", "rule_search"), ("filled_in", "rule_search"), ("search_p_rule_predefined_condition", DropdownChoice.option_id(ident)), ("search_p_rule_predefined_condition_USE", "on")], )
def page(self): watolib.init_wato_datastructures(with_wato_lock=True) if not user.may("wato.diag_host"): raise MKAuthException(_("You are not permitted to perform this action.")) if not transactions.check_transaction(): raise MKAuthException(_("Invalid transaction")) api_request = self.webapi_request() hostname = api_request.get("host") if not hostname: raise MKGeneralException(_("The hostname is missing.")) host = watolib.Host.host(hostname) if not host: raise MKGeneralException(_("The given host does not exist.")) if host.is_cluster(): raise MKGeneralException(_("This view does not support cluster hosts.")) host.need_permission("read") _test = api_request.get("_test") if not _test: raise MKGeneralException(_("The test is missing.")) # Execute a specific test if _test not in dict(ModeDiagHost.diag_host_tests()).keys(): raise MKGeneralException(_("Invalid test.")) # TODO: Use ModeDiagHost._vs_rules() for processing/validation? args: List[str] = [""] * 13 for idx, what in enumerate( [ "ipaddress", "snmp_community", "agent_port", "snmp_timeout", "snmp_retries", "tcp_connect_timeout", ] ): args[idx] = api_request.get(what, "") if api_request.get("snmpv3_use"): snmpv3_use = { "0": "noAuthNoPriv", "1": "authNoPriv", "2": "authPriv", }.get(api_request.get("snmpv3_use", ""), "") args[7] = snmpv3_use if snmpv3_use != "noAuthNoPriv": snmpv3_auth_proto = { str(DropdownChoice.option_id("md5")): "md5", str(DropdownChoice.option_id("sha")): "sha", }.get(api_request.get("snmpv3_auth_proto", ""), "") args[8] = snmpv3_auth_proto args[9] = api_request.get("snmpv3_security_name", "") args[10] = api_request.get("snmpv3_security_password", "") if snmpv3_use == "authPriv": snmpv3_privacy_proto = { str(DropdownChoice.option_id("DES")): "DES", str(DropdownChoice.option_id("AES")): "AES", }.get(api_request.get("snmpv3_privacy_proto", ""), "") args[11] = snmpv3_privacy_proto args[12] = api_request.get("snmpv3_privacy_password", "") else: args[9] = api_request.get("snmpv3_security_name", "") result = watolib.diag_host( host.site_id(), hostname, _test, *args, ) return { "next_transid": transactions.fresh_transid(), "status_code": result.return_code, "output": ensure_str(result.response, errors="replace"), }
def page(self): watolib.init_wato_datastructures(with_wato_lock=True) if not config.user.may('wato.diag_host'): raise MKAuthException( _('You are not permitted to perform this action.')) if not html.check_transaction(): raise MKAuthException(_("Invalid transaction")) request = self.webapi_request() hostname = request.get("host") if not hostname: raise MKGeneralException(_('The hostname is missing.')) host = watolib.Host.host(hostname) if not host: raise MKGeneralException(_('The given host does not exist.')) if host.is_cluster(): raise MKGeneralException( _('This view does not support cluster hosts.')) host.need_permission("read") _test = request.get('_test') if not _test: raise MKGeneralException(_('The test is missing.')) # Execute a specific test if _test not in dict(ModeDiagHost.diag_host_tests()).keys(): raise MKGeneralException(_('Invalid test.')) # TODO: Use ModeDiagHost._vs_rules() for processing/validation? args = [u""] * 13 # type: List[Text] for idx, what in enumerate([ 'ipaddress', 'snmp_community', 'agent_port', 'snmp_timeout', 'snmp_retries', 'tcp_connect_timeout', ]): args[idx] = request.get(what, u"") if config.user.may('wato.add_or_modify_executables'): args[6] = request.get("datasource_program", "") if request.get("snmpv3_use"): snmpv3_use = { u"0": u"noAuthNoPriv", u"1": u"authNoPriv", u"2": u"authPriv", }.get(request.get("snmpv3_use", u""), u"") args[7] = snmpv3_use if snmpv3_use != u"noAuthNoPriv": snmpv3_auth_proto = { six.text_type(DropdownChoice.option_id("md5")): u"md5", six.text_type(DropdownChoice.option_id("sha")): u"sha" }.get(request.get("snmpv3_auth_proto", u""), u"") args[8] = snmpv3_auth_proto args[9] = request.get("snmpv3_security_name", u"") args[10] = request.get("snmpv3_security_password", u"") if snmpv3_use == "authPriv": snmpv3_privacy_proto = { six.text_type(DropdownChoice.option_id("DES")): u"DES", six.text_type(DropdownChoice.option_id("AES")): u"AES" }.get(request.get("snmpv3_privacy_proto", u""), u"") args[11] = snmpv3_privacy_proto args[12] = request.get("snmpv3_privacy_password", u"") else: args[9] = request.get("snmpv3_security_name", u"") result = watolib.check_mk_automation(host.site_id(), "diag-host", [hostname, _test] + args) return { "next_transid": html.transaction_manager.fresh_transid(), "status_code": result[0], "output": six.ensure_text(result[1], errors="replace"), }