Exemplo n.º 1
0
    def _automation_push_profile(self):
        site_id = request.var("siteid")
        if not site_id:
            raise MKGeneralException(_("Missing variable siteid"))

        user_id = request.var("user_id")
        if not user_id:
            raise MKGeneralException(_("Missing variable user_id"))

        our_id = omd_site()

        if our_id is not None and our_id != site_id:
            raise MKGeneralException(
                _("Site ID mismatch. Our ID is '%s', but you are saying we are '%s'."
                  ) % (our_id, site_id))

        profile = request.var("profile")
        if not profile:
            raise MKGeneralException(
                _("Invalid call: The profile is missing."))

        users = userdb.load_users(lock=True)
        users[UserId(user_id)] = watolib_utils.mk_eval(profile)
        userdb.save_users(users, datetime.now())

        return True
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 def _execute_cmk_automation(self):
     cmk_command = request.get_str_input_mandatory("automation")
     args = watolib_utils.mk_eval(
         request.get_str_input_mandatory("arguments"))
     indata = watolib_utils.mk_eval(
         request.get_str_input_mandatory("indata"))
     stdin_data = watolib_utils.mk_eval(
         request.get_str_input_mandatory("stdin_data"))
     timeout = watolib_utils.mk_eval(
         request.get_str_input_mandatory("timeout"))
     cmdline_cmd, serialized_result = check_mk_local_automation_serialized(
         command=cmk_command,
         args=args,
         indata=indata,
         stdin_data=stdin_data,
         timeout=timeout,
     )
     # Don't use write_text() here (not needed, because no HTML document is rendered)
     response.set_data(
         self._format_cmk_automation_result(
             serialized_result=SerializedResult(serialized_result),
             cmk_command=cmk_command,
             cmdline_cmd=cmdline_cmd,
         ))