def _show_diagnose_output(self): if not request.var("_try"): html.show_message( _( "You can diagnose the connection to a specific host using this dialog. " "You can either test whether your current configuration is still working " "or investigate in which ways a host can be reached. Simply configure the " "connection options you like to try on the right side of the screen and " 'press the "Test" button. The results will be displayed here.' ) ) return if user_errors: html.show_user_errors() return # TODO: Insert any vs_host valuespec validation # These tests can be called with invalid valuespec settings... # TODO: Replace hard coded icon paths with dynamic ones to old or new theme for ident, title in ModeDiagHost.diag_host_tests(): html.h3(title) html.open_table(class_=["data", "test"]) html.open_tr(class_=["data", "odd0"]) html.open_td(class_="icons") html.open_div() html.icon("reload", id_="%s_img" % ident) html.open_a(href="") html.icon( "reload", title=_("Retry this test"), cssclass="retry", id_="%s_retry" % ident ) html.close_a() html.close_div() html.close_td() html.open_td() html.div("", class_="log", id="%s_log" % ident) html.close_td() html.close_tr() html.close_table() html.javascript( "cmk.host_diagnose.start_test(%s, %s, %s)" % ( json.dumps(ident), json.dumps(self._hostname), json.dumps(transactions.fresh_transid()), ) )
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 transactions.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: List[str] = [u""] * 13 for idx, what in enumerate([ 'ipaddress', 'snmp_community', 'agent_port', 'snmp_timeout', 'snmp_retries', 'tcp_connect_timeout', ]): args[idx] = request.get(what, u"") 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 = { str(DropdownChoice.option_id("md5")): u"md5", str(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 = { str(DropdownChoice.option_id("DES")): u"DES", str(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": transactions.fresh_transid(), "status_code": result[0], "output": ensure_str(result[1], errors="replace"), }