Exemplo n.º 1
0
    def __init__(self,
                 appname,
                 uri,
                 session_key,
                 service_with_tab_context=None):
        self.__appname = appname
        self.__logger = logger.get_input_builder_logger()
        self.__uri = uri
        self.__session_key = session_key

        self.__conf_mgr_with_tab_context = common_util.create_conf_mgr(
            self.__session_key, self.__uri)
        self.__default_input_properties = {
            "index": "default",
            "sourcetype": "{}_sourcetype".format(self.__appname),
            "interval": 60,
            "use_external_validation": True,
            "streaming_mode_xml": True,
        }

        if not service_with_tab_context:
            service_with_tab_context = common_util.create_splunk_service(
                session_key, uri)
        self.__service_with_tab_context = service_with_tab_context
        self.__meta_mgr = meta_manager.create_meta_manager(
            session_key, uri, meta_const.DATA_INPUT_BUILDER, self.__appname)
        self.required_meta_keys = ['name', 'type', 'sourcetype']
        self.__alert_builder = None
Exemplo n.º 2
0
    def __init__(self,
                 appname,
                 uri,
                 session_key,
                 service_with_tab_context=None,
                 service_with_ta_context=None):
        self.__appname = appname
        self.__app_namespace = common_util.get_python_lib_dir_name(
            self.__appname)
        self.__logger = logger.get_input_builder_logger()
        self.__parent_dir = os.path.split(os.path.realpath(__file__))[0]
        self.__resource_dir = os.path.join(self.__parent_dir, "resources")
        self.__resource_lib_dir = os.path.join(self.__parent_dir,
                                               "resources_lib")
        self.__splunk_home = os.environ['SPLUNK_HOME']
        self.__splunk_app_dir = os.path.join(self.__splunk_home, "etc", "apps")
        self.__current_ta_dir = os.path.join(self.__splunk_app_dir,
                                             self.__appname)
        self.__asset_generator = ta_static_asset_generator.AssetGenerator(
            self.__resource_dir,
            self.__current_ta_dir,
            self.__resource_lib_dir,
            app_name=self.__appname)
        self.__uri = uri
        self.__session_key = session_key

        if service_with_ta_context:
            self.__service_with_ta_context = service_with_ta_context
        else:
            self.__service_with_ta_context = common_util.create_splunk_service(
                session_key, uri, self.__appname)
            self.__logger.info('Create splunk service with args: %s, %s',
                               session_key, uri)

        self.__conf_mgr = common_util.create_conf_mgr(
            self.__session_key, self.__uri, app=self.__appname)
        self.__conf_mgr_with_tab_context = common_util.create_conf_mgr(
            self.__session_key, self.__uri)

        if not service_with_tab_context:
            service_with_tab_context = common_util.create_splunk_service(
                session_key, uri)
        self.__service_with_tab_context = service_with_tab_context
        self.required_meta_keys = ['name', 'type', 'sourcetype']
        self.__global_vars = None

        self.__input_meta_mgr = TAInputMetaMgr(appname, uri, session_key,
                                               self.__service_with_tab_context)

        self._ta_configuration_builder = builder_ta_configuration.TAConfigurationBuilder(
            self.__appname, self.__service_with_tab_context, self.__service_with_ta_context)
Exemplo n.º 3
0
import re
import subprocess
import os

try:
    from lxml import etree
except ImportError:
    from lxml.html import etree

import jsonpath_rw
from jsonpath_rw.jsonpath import Index, Fields, Root, This
from aob.aob_common import logger
from tabuilder_utility import builder_exception, common_util
from aob.aob_common.metric_collector import metric_util

_logger = logger.get_input_builder_logger()

# CONSTANTS
INPUT_METHOD_REST = 'rest'
INPUT_METHOD_CMD = 'command'
INPUT_METHOD_CUSTOMIZED = 'customized'
ALL_INPUT_METHODS = [
    INPUT_METHOD_CMD, INPUT_METHOD_REST, INPUT_METHOD_CUSTOMIZED
]

REST_URL_NAME = '_rest_api_url'
REST_METHOD_NAME = '_rest_api_method'

EVENT_JPATH_TYPE = 'event_json_path_key'
CKPT_JPATH_TYPE = 'ckpt_json_path_key'
CKPT_ENABLE_TYPE = 'ckpt_enable'
Exemplo n.º 4
0
    def __init__(self, input_meta, global_settings_meta):
        '''
        input_meta is a dict which contain the input meta data
        global_settings_meta is a dict
        '''
        self._global_proxy_setting_enabled = (
            GlobalSettingMeta.PROXY_SETTING_KEY in global_settings_meta)
        self._global_log_setting_enabled = (
            GlobalSettingMeta.LOG_LEVEL_SETTING_KEY in global_settings_meta)
        var_list = global_settings_meta.get(
            GlobalSettingMeta.CUSTOMIZED_SETTING_KEY, [])
        self._customized_var_names_and_types = {
            v['name']: v['type']
            for v in var_list
        }
        self._meta = input_meta
        self._logger = logger.get_input_builder_logger()
        # begin to parse the meta
        self._headers = {}
        self._payload = {}
        self._event_jpath_key = None
        self._ckpt_enable = False
        self._ckpt_time_format_enabled = False
        self._ckpt_jpath_key = None
        self._ckpt_var_name = None
        self._ckpt_source_time_format = None
        self._ckpt_target_time_format = None
        self._rest_url = None
        self._rest_method = None
        self._ckpt_init_value = ''
        for option in self._meta.get('data_inputs_options', []):
            opt_type = option.get('type')
            if opt_type == data_input_util.CUSTOMIZED_VAR_TYPE:
                continue
            elif opt_type == data_input_util.EVENT_JPATH_TYPE:
                self._event_jpath_key = option.get('value', '').strip()
            elif opt_type == data_input_util.CKPT_JPATH_TYPE:
                self._ckpt_jpath_key = option.get('value', '').strip()
            elif opt_type == data_input_util.CKPT_VAR_NAME_TYPE:
                self._ckpt_var_name = option.get('value', '').strip()
            elif opt_type == data_input_util.CKPT_INIT_VALUE_TYPE:
                self._ckpt_init_value = option.get('value', '').strip()
            elif opt_type == data_input_util.CKPT_ENABLE_TYPE:
                self._ckpt_enable = option.get('value', False)
            elif opt_type == data_input_util.CKPT_SOURCE_TIME_FORMAT_TYPE:
                self._ckpt_source_time_format = option.get('value', '').strip()
            elif opt_type == data_input_util.CKPT_TARGET_TIME_FORMAT_TYPE:
                self._ckpt_target_time_format = option.get('value', '').strip()
            else:
                opt_name = option['name']
                if opt_name == data_input_util.REST_METHOD_NAME:
                    self._rest_method = str(option.get('value')).upper()
                elif opt_name == data_input_util.REST_URL_NAME:
                    self._rest_url = data_input_util.convert_mako_template_string_to_jinja2_template(
                        option.get('value'))
                else:
                    opt_name = data_input_util.convert_mako_template_string_to_jinja2_template(
                        option['name'])
                    opt_value = data_input_util.convert_mako_template_string_to_jinja2_template(
                        option['value'])
                    if option.get(data_input_util.REST_HEADER_KEY, False):
                        self._headers[opt_name] = opt_value
                    else:
                        self._payload[opt_name] = opt_value

        self._ckpt_time_format_enabled = self._ckpt_source_time_format and self._ckpt_target_time_format
        if not self._ckpt_enable:
            self._ckpt_var_name = None
            self._ckpt_jpath_key = None
            self._ckpt_init_value = None
            self._ckpt_source_time_format = None
            self._ckpt_target_time_format = None
            self._ckpt_time_format_enabled = False

        if not self._event_jpath_key or self._event_jpath_key == '$':
            self._event_jpath_key = '$'
        else:
            self._event_jpath_key = '$.' + self._event_jpath_key
        if not self._ckpt_jpath_key or self._ckpt_jpath_key == '$':
            self._ckpt_jpath_key = '$'
        else:
            self._ckpt_jpath_key = '$.' + self._ckpt_jpath_key

        # the following logic is used for testing modular input
        self._enable_proxy_in_dryrun = False
        self._enable_logging_in_dryrun = False
        self._customized_var_names_and_types_in_dryrun = {}
        if 'test_id' in input_meta:
            # if dry run the input, get the global setting meta from the input meta
            test_global_settings = input_meta.get('global_settings', {})
            self._enable_proxy_in_dryrun = ta_configuration_meta.GlobalSettingMeta.PROXY_SETTING_KEY in test_global_settings
            self._enable_logging_in_dryrun = ta_configuration_meta.GlobalSettingMeta.LOG_LEVEL_SETTING_KEY in test_global_settings
            self._customized_var_names_and_types_in_dryrun = dict()
            for v in test_global_settings.get(
                    ta_configuration_meta.GlobalSettingMeta.
                    CUSTOMIZED_SETTING_KEY, []):
                if v.get('name') and v.get('type'):
                    self._customized_var_names_and_types_in_dryrun[
                        v['name']] = v['type']