Exemple #1
0
 def restart_task_server(self, taskserver_port):
     try:
         # settings update successfully, then trigger restart server api to make change taking effect
         requests.delete(self.restart_url % taskserver_port, verify=False)
     except Exception as ex:
         # if task server is not running, this request will failed
         logger.warn("action=restart_task_server_request_failed", ex)
Exemple #2
0
def _autodetect_java_home():
    if os.name == 'posix':
        cur_os = os.uname()[0]
        if cur_os == 'Darwin':
            return _autodetect_java_home_osx()
        else:
            return _autodetect_java_home_posix()
    elif os.name == 'nt':
        return _autodetect_java_home_win()
    else:
        logger.warn("Unable to autodetect JAVA_HOME on platform %s", os.name)
        return ""
Exemple #3
0
 def check_java_home(self, content):
     if "javaHome" not in content:
         if "JAVA_HOME" in os.environ:
             java_home = os.environ["JAVA_HOME"].replace('"', '')
             content["javaHome"] = java_home
         else:
             try:
                 java_home = JavaHomeDetector.detect()
                 content["javaHome"] = java_home
             except Exception as ex:
                 logger.warn("java home auto detection failed")
                 content["javaHome"] = ""
Exemple #4
0
def read():
    try:
        jvm_options_file_path = _get_jvm_options_filepath()
        if not os.path.isfile(jvm_options_file_path):
            logger.debug("action=jvm_options_file_not_exist, file_path=%s" % jvm_options_file_path)
            return ""
        with open(jvm_options_file_path, 'r') as vmopts_file:
            vmopts = vmopts_file.readline().strip()
            if not vmopts:
                return ""
            else:
                return vmopts
    except Exception as ex:
        logger.warn("action=fail_to_read_jvm_options_from_file", ex)
        return ""
 def _update_server_log_level_runtime(self, server_log_level):
     data = []
     for (module, level) in server_log_level.items():
         packages = self.server_module_info[module]["packages"]
         for package in packages:
             data.append({
                 "logger": package,
                 "level": level
             })
     try:
         logger.debug("action=send_log_level_update_request url=%s data=%s" % (self.server_log_level_url, dumps(data)))
         headers = {
             'content-type': 'application/json'
         }
         response = requests.put(url=self.server_log_level_url, headers=headers, data=dumps(data), verify=False)
         if response.status_code != 200:
             logger.warn("acton=fail_to_send_request_to_update_log_level status=%s content=%s" % (response.status_code, response.content))
     except Exception as ex:
         # TODO: whether to raise error? vmopts file have been updated successfully
         logger.warn("acton=fail_to_send_request_to_update_log_level", ex)
    def _create_handler(cls):
        script_dir = os.path.dirname(os.path.realpath(__file__))

        key_file_location = os.path.join(script_dir, '..', '..', '..', 'certs',
                                         'privkey.pem')
        cert_file_location = os.path.join(script_dir, '..', '..', '..',
                                          'certs', 'cert.pem')

        key_file_exists = os.path.isfile(key_file_location)
        cert_file_exists = os.path.isfile(cert_file_location)

        if key_file_exists and cert_file_exists:
            logger.debug('action=enable_client_certicates')
        else:
            key_file_location = cert_file_location = None
            if key_file_exists != cert_file_exists:
                logger.warn(
                    'Unable to enable client certificate because the key or the certificate is missing.' \
                    'certs application folder should contain privkey.pem and cert.pem files')

        custom_handler = handler(key_file=key_file_location,
                                 cert_file=cert_file_location)

        # we wrap the handler to intercept any SSL exception to give a meaningful message to end user
        def handler_wrapper(url, message, **kwargs):
            logger.debug('action=sending_request url=%s message=%s kwargs=%s',
                         url, message, kwargs)
            try:
                return custom_handler(url, message, **kwargs)
            except ssl.SSLError:
                message = 'Unable to communicate with Splunkd. ' \
                          'If you enable requireClientCert please make sure certs folder contains privkey.pem and cert.pem files. ' \
                          'Also make sure cert.pem has been signed by the root CA used by Splunkd.'
                logger.error(message, exc_info=True)
                raise ssl.SSLError(message)

        return handler_wrapper
Exemple #7
0
    def _forward_request_to_proxy(self):
        status, result = self._check_java_server_availability()
        if status != Status.OK:
            return self._create_health_check_result(status, result)

        forward_url = "https://{}/servicesNS/{}/splunk_app_db_connect/{}/dbxproxy/{}" \
            .format(self.hostPath, self.userName, self.pathParts[1], "/".join(self.pathParts[2:]))
        try:
            response = requests.get(
                url=forward_url,
                headers={'Authorization': ('Splunk %s' % self.sessionKey)},
                verify=False)
            if response.status_code != 200:
                logger.warn(
                    "action=fail_to_send_request_to_get_health_check_result url={} status_code={} content={}"
                    .format(forward_url, response.status_code,
                            response.content))
                raise Exception(
                    "fail to get health check result from server url={} status_code={} content={}"
                    .format(forward_url, response.status_code,
                            response.content))
            result = response.json()
            if isinstance(result, list):
                return [
                    self._create_health_check_result(entry['severity_level'],
                                                     entry['details'])
                    for entry in result
                ]
            else:
                return self._create_health_check_result(
                    result['severity_level'], result['details'])

        except Exception as ex:
            logger.error(
                "action=fail_to_send_request_to_get_health_check_result", ex)
            return "unhealthy", str(ex)