Beispiel #1
0
def run(dateRange, schema_file):
    profile = get_instance_profile()
    ms = load_schema(schema_file, profile.visibility)
    sm = ScheduleManager(ms, dataPointFactory)
    logging.info("INST Started")

    if profile.visibility:
        sm.collect(dateRange)
        sleep(5)
        sm.send(dateRange)
    logging.info("INST Done")
Beispiel #2
0
    def __init__(self,
                 splunkrc=None,
                 deploymentID=None,
                 schema=None,
                 factory=None,
                 send_data=None,
                 send_log=None,
                 instance_profile=None,
                 quick_draw=None):
        self._splunkrc = splunkrc
        self.deploymentID = deploymentID
        self.transaction_id = None
        if not instance_profile:
            self.instance_profile = get_instance_profile(self._splunkrc)
        else:
            self.instance_profile = instance_profile
        if not schema:
            schema = metrics_schema.load_schema(
                INST_SCHEMA_FILE, visibility=self.instance_profile.visibility)
        self.schema = schema
        if not factory:
            factory = dataPointFactory
        self.factory = factory
        self.deliverySchema = self.schema.delivery
        if not quick_draw:
            qd = get_quick_draw()
        else:
            qd = quick_draw
        if qd:
            self.deliverySchema.url = qd.get('url')

        self.transaction_id = self.get_transactionID()

        if not send_data:
            self.sd = SendData(
                deploymentID=self.instance_profile.get_deployment_id(),
                deliverySchema=self.deliverySchema,
                transaction_id=self.get_transactionID())
        else:
            self.sd = send_data

        if not send_log:
            self.sl = SendLog(splunkrc=self._splunkrc)
        else:
            self.sl = send_log

        self.result = None
        self.is_cloud = self.instance_profile.server_is_cloud
Beispiel #3
0
def run_phase_1_for_all_nodes(dateRange, schema_file):
    '''
    phase 1 runs by all nodes to collect role based data and index to data to _introspection
    phase 1 does not check opt in options

    :param profile
    :param dateRange
    :param schema_file
    :return: None
    '''

    report.report('Running_Phase[]', 1)
    ms = load_schema(schema_file, '*')
    sm = ScheduleManager(ms, dataPointFactory)

    # to add phase 1 and ignore visibility
    sm.phase_1(dateRange, INTROSPECTION_INDEX_NAME)
Beispiel #4
0
def run_phase_2(profile, dateRange, schema_file):
    '''
    phase 2 runs by lead node only and only runs when a deployment is opted in.
    sm.phase_2() does the following:
    - collects and indexes data points marked as phase = 2
    - query data collected by phase = 1 and phase = 2 and send the data to splunkx

    :param profile
    :param dateRange
    :param schema_file
    :return: None
    '''
    report.report('Running_Phase[]', 2)
    ms = load_schema(schema_file, profile.visibility)
    sm = ScheduleManager(ms, dataPointFactory)

    sleep(5)
    sm.phase_2(dateRange, INTROSPECTION_INDEX_NAME)
    def __init__(self, command_line=None, command_arg=None):
        PersistentServerConnectionApplication.__init__(self)
        self.DTO_FIELD = [
            'timestamp',
            'deploymentID',
            'eventID',
            'experienceID',
            'component',
            'userID',
            'visibility',
            'data'
        ]

        self.DTO_DEFAULT_VALUE = {
            "timestamp": lambda event: int(time.time()),
            "deploymentID": self.getDeploymentID,
            "userID": self.getUserID,
            "visibility": lambda event: ANONYMOUS,
            "eventID": lambda event: str(uuid.uuid4())
        }
        self.FIELD_TYPE = {
            "userID": [str, unicode],
            "eventID": [str, unicode],
            "experienceID": [str, unicode],
            "timestamp": [int],
            "data": [dict],
            "component": [str, unicode]
        }

        self.FIELD_NAME = {
            str: 'string',
            unicode: 'string',
            int: 'integer',
            dict: 'JSON Object'
        }

        self.schema = metrics_schema.load_schema(INST_SCHEMA_FILE)
        self.qd = get_quick_draw()
        self.deliverySchema = self.schema.delivery
        self.deliverySchema.url = self.qd.get('url')
        self.deploymentID = ''
        self.token = ''
        self.server_uri = ''
        self.userID = ''
class SwaContext(object):
    '''
    Encapsulates all of the contextual data
    needed to render the SWA initialization script.
    '''
    salt = None
    deployment_id = ''
    send_anonymized_web_analytics = False
    opt_in_is_up_to_date = False
    user_id = ''
    swa_base_url = False
    schema = load_schema(INST_SCHEMA_FILE)
    server_uri = rest.makeSplunkdUri()
    # Defer cds_url until we know that there has been opt-in for SWA.
    # See SPL-141718 [Splunkweb Appserver may take a long time to start due to
    # SWA/splunk_instrumentation] for more details.
    cds_url = None
    instance_guid = ''
    visibility = ''

    def should_load_swajs(self):
        '''
        Returns true if the telemetry conf file idicates we should be
        instrumentation the UI.
        '''
        return self.send_anonymized_web_analytics and self.opt_in_is_up_to_date

    def to_dict(self):
        '''
        Returns the configuration items from this object in a dictionary.
        '''
        swa_js_url = routes.make_route(
            '/static/app/splunk_instrumentation/build/pages/swa.js')

        result = {
            'swa_js_url': swa_js_url,
            'options': {
                'deploymentID': self.deployment_id,
                'userID': self.user_id,
                'version': self.schema.delivery.version,
                'instanceGUID': self.instance_guid,
                'visibility': self.visibility,
            }
        }

        if self.swa_base_url:
            result['options']['url'] = routes.make_route(self.swa_base_url)
            result['options']['bundleDataFunction'] = 'json'
        else:
            result['options']['url'] = self.cds_url

        return result

    def update(self,
               cherrypy,
               services=None,
               deployment_id_manager=None,
               salt_manager=None):
        '''
        Updates the volatile data members of the swa context.
        This method is hit each time an HTML page is hit, so the
        less work done here the better.
        '''

        if services is None:
            splunkd = Splunkd(token=cherrypy.session.get('sessionKey'),
                              server_uri=self.server_uri)
            telemetry_conf_service = TelemetryConfService(splunkd,
                                                          is_read_only=True)
            telemetry_conf_service.fetch()
            # Specialize the telemetry_conf_service to be read only up front,
            # use the default construction for other services.
            services = ServiceBundle(
                splunkd, telemetry_conf_service=telemetry_conf_service)

        if not self.instance_guid:
            self.instance_guid = services.server_info_service.content.get(
                'guid')

        salt_manager = salt_manager or SaltManager(services)
        self.salt = salt_manager.get_salt()

        deployment_id_manager = deployment_id_manager or DeploymentIdManager(
            splunkd, telemetry_conf_service=services.telemetry_conf_service)

        self.deployment_id = deployment_id_manager.get_deployment_id() or ''

        self.opt_in_is_up_to_date = services.telemetry_conf_service.opt_in_is_up_to_date(
        )

        self.swa_base_url = services.telemetry_conf_service.content.get(
            'swaEndpoint')

        hash_key = self.salt + splunk.auth.getCurrentUser()['name']
        if sys.version_info >= (3, 0):
            hash_key = hash_key.encode()

        self.user_id = hashlib.sha256(hash_key).hexdigest()

        self.send_anonymized_web_analytics = conf_bool(
            services.telemetry_conf_service.content.get(
                'sendAnonymizedWebAnalytics'))

        visibilities = []

        if services.server_info_service.is_cloud():
            visibilities = ['anonymous', 'support']
        else:
            if conf_bool(
                    services.telemetry_conf_service.content.get(
                        'sendAnonymizedUsage')):
                visibilities.append('anonymous')

            if conf_bool(
                    services.telemetry_conf_service.content.get(
                        'sendSupportUsage')):
                visibilities.append('support')

        self.visibility = ','.join(visibilities)

        if self.send_anonymized_web_analytics and not self.cds_url:
            self.cds_url = get_quick_draw().get('url')