Beispiel #1
0
def get_all_conf_contents(server_uri, sessionkey, settings, input_type=None):
    schema = GlobalConfigSchema(settings)
    global_config = GlobalConfig(server_uri, sessionkey, schema)
    inputs = global_config.inputs.load(input_type=input_type)
    configs = global_config.configs.load()
    settings = global_config.settings.load()
    return inputs, configs, settings
Beispiel #2
0
 def init_global_config(self):
     if self.__global_config is not None:
         return
     schema_file = get_schema_path()
     if not os.path.isfile(schema_file):
         self.log_error("Global config JSON file not found!")
         self.__global_config = None
     else:
         with open(get_schema_path()) as f:
             json_schema = ''.join([l for l in f])
         self.__global_config = GlobalConfig(self.__uri, self.__session_key,
                                             GlobalConfigSchema(json.loads(json_schema)))
Beispiel #3
0
    def _parse_input_args_from_global_config(self, inputs):
        """Parse input arguments from global configuration.
        :param inputs:
        """
        # dirname at this point will be <splunk_home>/etc/apps/<ta-name>/lib/splunktaucclib/modinput_wrapper, go up 3 dirs from this file to find the root TA directory
        dirname = os.path.dirname
        config_path = os.path.join(
            dirname(dirname(dirname(dirname(__file__)))),
            "appserver",
            "static",
            "js",
            "build",
            "globalConfig.json",
        )
        with open(config_path) as f:
            schema_json = "".join([l for l in f])
        global_schema = GlobalConfigSchema(json.loads(schema_json))

        uri = inputs.metadata["server_uri"]
        session_key = inputs.metadata["session_key"]
        global_config = GlobalConfig(uri, session_key, global_schema)
        ucc_inputs = global_config.inputs.load(input_type=self.input_type)
        all_stanzas = ucc_inputs.get(self.input_type, {})
        if not all_stanzas:
            # for single instance input. There might be no input stanza.
            # Only the default stanza. In this case, modinput should exit.
            self.log_warning("No stanza found for input type: " + self.input_type)
            sys.exit(0)

        account_fields = self.get_account_fields()
        checkbox_fields = self.get_checkbox_fields()
        self.input_stanzas = {}
        for stanza in all_stanzas:
            full_stanza_name = "{}://{}".format(self.input_type, stanza.get("name"))
            if full_stanza_name in inputs.inputs:
                if stanza.get("disabled", False):
                    raise RuntimeError("Running disabled data input!")
                stanza_params = {}
                for k, v in stanza.items():
                    if k in checkbox_fields:
                        stanza_params[k] = sutils.is_true(v)
                    elif k in account_fields:
                        stanza_params[k] = copy.deepcopy(v)
                    else:
                        stanza_params[k] = v
                self.input_stanzas[stanza.get("name")] = stanza_params
    def _parse_input_args_from_global_config(self, inputs):
        """Parse input arguments from global configuration.

        :param inputs:
        """
        dirname = os.path.dirname
        config_path = os.path.join(
            dirname(dirname(dirname(dirname(dirname(__file__))))), 'appserver',
            'static', 'js', 'build', 'globalConfig.json')
        with open(config_path) as f:
            schema_json = ''.join([l for l in f])
        global_schema = GlobalConfigSchema(json.loads(schema_json))

        uri = inputs.metadata["server_uri"]
        session_key = inputs.metadata['session_key']
        global_config = GlobalConfig(uri, session_key, global_schema)
        ucc_inputs = global_config.inputs.load(input_type=self.input_type)
        all_stanzas = ucc_inputs.get(self.input_type, {})
        if not all_stanzas:
            # for single instance input. There might be no input stanza.
            # Only the default stanza. In this case, modinput should exit.
            self.log_warning("No stanza found for input type: " +
                             self.input_type)
            sys.exit(0)

        account_fields = self.get_account_fields()
        checkbox_fields = self.get_checkbox_fields()
        self.input_stanzas = {}
        for stanza in all_stanzas:
            full_stanza_name = '{}://{}'.format(self.input_type,
                                                stanza.get('name'))
            if full_stanza_name in inputs.inputs:
                if stanza.get('disabled', False):
                    raise RuntimeError("Running disabled data input!")
                stanza_params = {}
                for k, v in stanza.items():
                    if k in checkbox_fields:
                        stanza_params[k] = sutils.is_true(v)
                    elif k in account_fields:
                        stanza_params[k] = copy.deepcopy(v)
                    else:
                        stanza_params[k] = v
                self.input_stanzas[stanza.get('name')] = stanza_params
Beispiel #5
0
    def read_global_configuration(self, global_setting_meta):
        ucc_meta = self.get_ucc_meta(global_setting_meta)
        schema = GlobalConfigSchema(ucc_meta)
        global_config = GlobalConfig(
            common_util.get_splunkd_uri(self._service_with_tab_context),
            self._service_with_tab_context.token, schema)

        accounts = global_config.configs.load().get('account', [])
        settings = global_config.settings.load()
        global_configuration = dict()
        global_configuration['credential_settings'] = [{
            "username":
            account['username'],
            "password":
            account['password'],
            "name":
            account['name']
        } for account in accounts]

        for setting in settings.get('settings', []):
            self._logger.info("setting: {}".format(
                logger.hide_sensitive_field(setting)))
            if setting['name'] == 'logging':
                global_configuration["log_settings"] = {
                    "log_level": setting.get('loglevel')
                }
            elif setting['name'] == "proxy":
                if 'disabled' in setting:
                    del setting['disabled']
                global_configuration["proxy_settings"] = setting
            else:  # should be customized settings
                global_configuration[
                    "customized_settings"] = global_setting_meta.get(
                        "customized_settings", [])
                for customized_setting in global_configuration[
                        "customized_settings"]:
                    var_name = customized_setting['name']
                    if var_name in setting:
                        customized_setting['value'] = setting[var_name]

        return global_configuration
Beispiel #6
0
    def write_global_configuration(self, global_setting_meta, old_meta=None):
        if old_meta is None:
            old_meta = self.meta
        ucc_meta = self.get_ucc_meta(global_setting_meta)
        schema = GlobalConfigSchema(ucc_meta)
        global_config = GlobalConfig(
            common_util.get_splunkd_uri(self._service_with_tab_context),
            self._service_with_tab_context.token, schema)

        all_payload = dict()
        configs_payload = self.get_ucc_configs_content_meta(
            global_setting_meta, old_meta)
        if configs_payload:
            all_payload.update(configs_payload)
        settings_payload = self.get_ucc_settings_content_meta(
            global_setting_meta, old_meta)
        if settings_payload:
            all_payload.update(settings_payload)
        if all_payload:
            self._logger.debug('Save global settings to UCC. payload: %s',
                               logger.hide_sensitive_field(all_payload))
            global_config.save(all_payload)