def render(self, row: Row, cell: Cell) -> CellSpec: single_url = "view.py?" + urlencode_vars( [("view_name", "aggr_single"), ("aggr_name", row["aggr_name"])]) avail_url = single_url + "&mode=availability" bi_map_url = "bi_map.py?" + urlencode_vars([ ("aggr_name", row["aggr_name"]), ]) with output_funnel.plugged(): html.icon_button(bi_map_url, _("Visualize this aggregation"), "aggr") html.icon_button(single_url, _("Show only this aggregation"), "showbi") html.icon_button(avail_url, _("Analyse availability of this aggregation"), "availability") if row["aggr_effective_state"]["in_downtime"] != 0: html.icon( "derived_downtime", _("A service or host in this aggregation is in downtime.")) if row["aggr_effective_state"]["acknowledged"]: html.icon( "ack", _("The critical problems that make this aggregation non-OK have been acknowledged." ), ) if not row["aggr_effective_state"]["in_service_period"]: html.icon( "outof_serviceperiod", _("This aggregation is currently out of its service period." ), ) code = HTML(output_funnel.drain()) return "buttons", code
def do_remote_automation(site, command, vars_, files=None, timeout=None): auto_logger.info("RUN [%s]: %s", site, command) auto_logger.debug("VARS: %r", vars_) base_url = site["multisiteurl"] secret = site.get("secret") if not secret: raise MKAutomationException( _("You are not logged into the remote site.")) url = (base_url + "automation.py?" + urlencode_vars([("command", command), ("secret", secret), ("debug", config.debug and '1' or '')])) response = get_url(url, site.get('insecure', False), data=dict(vars_), files=files, timeout=timeout) auto_logger.debug("RESPONSE: %r", response) if not response: raise MKAutomationException(_("Empty output from remote site.")) try: response = ast.literal_eval(response) except SyntaxError: # The remote site will send non-Python data in case of an error. raise MKAutomationException("%s: <pre>%s</pre>" % (_("Got invalid data"), response)) return response
def _legacy_push_user_profile_to_site(site, user_id, profile): url = site["multisiteurl"] + "automation.py?" + urlencode_vars([ ("command", "push-profile"), ("secret", site["secret"]), ("siteid", site['id']), ("debug", config.debug and "1" or ""), ]) response = get_url(url, site.get('insecure', False), data={ 'user_id': user_id, 'profile': mk_repr(profile), }, timeout=60) if not response: raise MKAutomationException(_("Empty output from remote site.")) try: response = mk_eval(response) except Exception: # The remote site will send non-Python data in case of an error. raise MKAutomationException("%s: <pre>%s</pre>" % (_("Got invalid data"), response)) return response
def _do_remote_automation_serialized( *, site, command, vars_, files=None, timeout=None, ) -> str: auto_logger.info("RUN [%s]: %s", site, command) auto_logger.debug("VARS: %r", vars_) base_url = site["multisiteurl"] secret = site.get("secret") if not secret: raise MKAutomationException( _("You are not logged into the remote site.")) url = (base_url + "automation.py?" + urlencode_vars([("command", command), ("secret", secret), ("debug", config.debug and "1" or "")])) response = get_url(url, site.get("insecure", False), data=dict(vars_), files=files, timeout=timeout) auto_logger.debug("RESPONSE: %r", response) if not response: raise MKAutomationException(_("Empty output from remote site.")) return response
def js_dashlet(self, figure_type_name: str) -> None: fetch_url = "ajax_figure_dashlet_data.py" div_id = "%s_dashlet_%d" % (self.type_name(), self._dashlet_id) html.div("", id_=div_id) # TODO: Would be good to align this scheme with AjaxPage.webapi_request() # (a single HTTP variable "request=<json-body>". post_body = urlencode_vars(self._dashlet_http_variables()) html.javascript( """ let figure_%(dashlet_id)d = cmk.figures.figure_registry.get_figure(%(type_name)s); let %(instance_name)s = new figure_%(dashlet_id)d(%(div_selector)s); %(instance_name)s.set_post_url_and_body(%(url)s, %(body)s); %(instance_name)s.initialize(); %(instance_name)s.scheduler.set_update_interval(%(update)d); %(instance_name)s.scheduler.enable(); """ % { "type_name": json.dumps(figure_type_name), "dashlet_id": self._dashlet_id, "instance_name": self.instance_name, "div_selector": json.dumps("#%s" % div_id), "url": json.dumps(fetch_url), "body": json.dumps(post_body), "update": self.update_interval, })
def _handle_report_form(self, crash_info): details = {} try: vs = self._vs_crash_report() details = vs.from_html_vars("_report") vs.validate_value(details, "_report") # Make the resulting page execute the crash report post request url_encoded_params = urlencode_vars( list(details.items()) + [ ("crashdump", base64.b64encode( _pack_crash_report( self._get_serialized_crash_report()))), ]) html.open_div(id_="pending_msg", style="display:none") html.show_message(_("Submitting crash report...")) html.close_div() html.open_div(id_="success_msg", style="display:none") html.show_message( _("Your crash report has been submitted (ID: ###ID###). Thanks for your participation, " "it is very important for the quality of Checkmk.<br><br>" "Please note:" "<ul>" "<li>In general we do <i>not</i> respond to crash reports, " "except we need further information from you.</li>" "<li>We read every feedback thoroughly, but this might happen " "not before a couple of weeks or even months have passed and is " "often aligned with our release cycle.</li>" "<li>If you are in need of a quick solution for your problem, then " "we can help you within the scope of professional support. If you " "already have a support contract, then please use your personal " "support email address to send us a mail refering to your crash " "report.<br>If you are interested in the details about support, " "you find details on <a href=\"https://checkmk.com/" "checkmk_support_contract.html\" target=\"_blank\">our website</a>." )) html.close_div() html.open_div(id_="fail_msg", style="display:none") report_url = makeuri_contextless( request, [ ("subject", "Checkmk Crash Report - " + self._get_version()), ], filename="mailto:" + self._get_crash_report_target(), ) html.show_error( _("Failed to send the crash report. Please download it manually and send it " "to <a href=\"%s\">%s</a>") % (report_url, self._get_crash_report_target())) html.close_div() html.javascript( "cmk.transfer.submit_crash_report(%s, %s);" % (json.dumps( config.crash_report_url), json.dumps(url_encoded_params))) except MKUserError as e: user_errors.add(e) return details
def paint(self, value, hostname): parts = [ html.render_a( hn, "wato.py?" + urlencode_vars([("mode", "edit_host"), ("host", hn)])) for hn in value ] return "", HTML(", ").join(parts)
def render(self, what, row, tags, custom_vars): # TODO: At least for interfaces we have 2 predictive values. But this icon # only creates a link to the first one. Add multiple icons or add a navigation # element to the prediction page. if what == "service": parts = row[what + "_perf_data"].split() for p in parts: if p.startswith("predict_"): varname, _value = p.split("=") dsname = varname[8:] sitename = row["site"] url_prefix = config.site(sitename)["url_prefix"] url = url_prefix + "check_mk/prediction_graph.py?" + urlencode_vars( [ ("host", row["host_name"]), ("service", row["service_description"]), ("dsname", dsname), ]) title = _("Analyse predictive monitoring for this service") return 'prediction', title, url
def _show_tree(self): tree = self._get_tree() affected_hosts = self._row["aggr_hosts"] title = self._row["aggr_tree"]["title"] group = self._row["aggr_group"] url_id = urlencode_vars( [ ("aggregation_id", self._row["aggr_tree"]["aggregation_id"]), ("group", group), ("title", title), ("omit_root", "yes" if self._omit_root else ""), ("renderer", self.__class__.__name__), ("only_problems", "yes" if self._only_problems else ""), ("reqhosts", ",".join("%s#%s" % sitehost for sitehost in affected_hosts)), ] ) html.open_div(id_=url_id, class_="bi_tree_container") self._show_subtree(tree, path=[tree[2]["title"]], show_host=len(affected_hosts) > 1) html.close_div()
def render(self, what, row, tags, custom_vars): if not config.mkeventd_enabled: return # show for services based on the mkevents active check command = row[what + "_check_command"] if what != "service" or not command.startswith("check_mk_active-mkevents"): return # Split command by the parts (COMMAND!ARG0!...) Beware: Do not split by escaped exclamation mark. splitted_command = re.split(r"(?<!\\)!", command) # All arguments are space separated in in ARG0 if len(splitted_command) != 2: return host = None app = None # Extract parameters from check_command args = shlex.split(splitted_command[1]) if not args: return # Handle -a and -H options. Sorry for the hack. We currently # have no better idea if len(args) >= 2 and args[0] == "-H": args = args[2:] # skip two arguments if len(args) >= 1 and args[0] == "-a": args = args[1:] if len(args) >= 1: host = _get_hostname(args, row) # If we have no host then the command line from the check_command seems # to be garbled. Better show nothing in this case. if not host: return # It is possible to have a central event console, this is the default case. # Another possible architecture is to have an event console in each site in # a distributed environment. For the later case the base url need to be # constructed here url_prefix = "" if getattr(config, "mkeventd_distributed", False): site = get_site_config(row["site"]) url_prefix = site["url_prefix"] + "check_mk/" url_vars = [ ("view_name", "ec_events_of_monhost"), ("site", row["site"]), ("host", row["host_name"]), ] title = _("Events of Host %s") % (row["host_name"]) if len(args) >= 2: app = args[1].strip("'").replace("\\\\", "\\").replace("\\!", "!") title = _('Events of Application "%s" on Host %s') % (app, host) url_vars.append(("event_application", app)) url = "view.py?" + urlencode_vars(url_vars) return "mkeventd", title, url_prefix + url
def test_urlencode_vars(inp, out): assert urlencode_vars(inp) == out
def __init__(self, endpoint: str, url_vars: Optional[HTTPVariables]): super().__init__(type="ajax") self.endpoint = endpoint if endpoint else None self.url_vars = urlencode_vars(url_vars) if url_vars else None