Beispiel #1
0
    def package_send(self, dateRange):
        """Auto send and log data.

        First we look at our index and check the start, stop, and visibility
        Next we query based on that, and send it.
        """
        visibility = self.instance_profile.visibility
        if visibility is False:
            return False

        time_range = {"start": INST_EXECUTION_START_TIME, "stop": utcNow()}

        events = self._query_events(dateRange['start'],
                                    dateRange['stop'],
                                    visibility,
                                    False,
                                    time_range=time_range)

        if len(events) == 0:
            report.report('send-canceled', True)
            return False
        return self._send_package(events,
                                  dateRange['start'],
                                  dateRange['stop'],
                                  time_range=time_range)
 def send(self):
     """
     Prints the whole of self.log to stdout as json.
     This is used to log reporting information in production
     runs of the instrumentation.py script.
     """
     self.log.setdefault('timestamp', date_to_timestamp(utcNow()))
     print(json.dumps(self.log, default=json_serial))
 def write(self):
     """
     Writes the data accumulated in self.log to report.json,
     next to the report python module (this module) on disk.
     """
     self.log.setdefault('timestamp', date_to_timestamp(utcNow()))
     with open(
             os.path.dirname(os.path.realpath(__file__)) + '/report.json',
             'w') as target:
         target.write(json.dumps(self.log, default=json_serial))
Beispiel #4
0
    def data_point_results_transform(self, class_def, data_point_result,
                                     date_range):
        fields = class_def.index_fields
        hash_key = class_def.getHashKey()

        result = {"data": None}
        if data_point_result['data']:
            if (isinstance(data_point_result['data'], basestring)):
                data = json.loads(data_point_result['data'])
            else:
                data = data_point_result['data']

            data = hash_specific_value_by_key(data=data,
                                              hash_key=hash_key,
                                              scheme=self.scheme)
            data = transform_object(data=data, fields=fields)
            result['data'] = data

        result['timestamp'] = date_to_timestamp(utcNow())

        result['component'] = class_def.component
        result['date'] = date_range['stop'].isoformat()

        data_point_time = data_point_result.get('_time')

        if not date_range['stop'] == date_range['start']:
            try:
                if data_point_result.get('date'):
                    result['date'] = data_point_result.get('date')
                elif data_point_time and 'T' in data_point_time:
                    result['date'] = data_point_result.get('_time').split(
                        'T')[0]
            except Exception:
                result['date'] = date_range['stop'].isoformat()

        # SPECIAL CASE:
        # At least one (the indexer cluster member count) data point is retrieved
        # on the fly during data collection. Its time/date will be "today" though
        # it really pertains to the stop date (typically yesterday in prod).
        # Note - There is discussion of having each node persist this data so the
        #        true historical values can be retrieved later. That would eliminate
        #        this situation.
        if str_to_date(result['date']) > date_range['stop']:
            result['date'] = date_range['stop']

        result['visibility'] = class_def.visibility or "anonymous"
        result['executionID'] = INST_EXECUTION_ID

        return result
Beispiel #5
0
# QUICKDRAW_URL is the QUICKDRAW_URL to hit
# DEFAULT_QUICKDRAW is the default url returned if we request QUICKDRAW_URL
DEFAULT_QUICKDRAW = {"url": "https://e1345286.api.splkmobile.com/1.0/e1345286"}
if os.environ.get('DEFAULT_QUICKDRAW'):
    DEFAULT_QUICKDRAW = {"url": os.environ.get('DEFAULT_QUICKDRAW')}
QUICKDRAW_URL = os.environ.get('QUICKDRAW_URL') or "https://quickdraw.splunk.com/telemetry/destination"
INST_DEBUG_LEVEL = os.environ.get('INST_DEBUG_LEVEL') or "ERROR"

INST_MODE = os.environ.get('INST_MODE') or "INPUT"
INST_NO_COLLECT = os.environ.get('INST_NO_COLLECT') or False
INST_NO_SEND = os.environ.get('INST_NO_SEND') or False
INST_COLLECT_DATE = os.environ.get('INST_COLLECT_DATE') or False
INST_SCHEMA_FILE = os.environ.get('INST_SCHEMA_FILE') or os.path.dirname(os.path.realpath(__file__)) + '/schema.json'
INST_EXECUTION_ID = os.environ.get('INST_EXECUTION_ID') or "".join(random.choice('0123456789ABCDEF') for i in range(30))
INST_EXECUTION_START_TIME = utcNow()
INST_KV_OWNER = "nobody"

INST_APP_NAME = "splunk_instrumentation"

INST_PROFILE_OWNER = "nobody"
INST_PROFILE_APP = "splunk_instrumentation"

INST_LICENSE_TYPES = ['anonymous', 'license']

SPLUNKD_URI = rest.makeSplunkdUri()
SPLUNKRC = {"token": os.environ.get('INST_TOKEN') or None,
            "server_uri": os.environ.get('INST_SERVER_URI') or SPLUNKD_URI
            }

VISIBILITY_FIELDS_BY_NAME = {