コード例 #1
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
コード例 #2
0
    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 = ''
コード例 #3
0
    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')