Example #1
0
    def measurement_create(self,
                           metric=None,
                           value=None,
                           source=None,
                           timestamp=None,
                           properties=None):
        """
        Creates a new measurement in TrueSight Pulse instance.

        :param metric: Identifies the metric to use to add a measurement
        :param value: Value of the measurement
        :param source: Origin of the measurement
        :param timestamp: Time of the occurrence of the measurement
        :param properties: Properties of the measurement
        :return: None
        """

        if metric is None:
            raise ValueError('metrics not specified')

        if value is None:
            raise ValueError('value not specified')
        self._method = 'POST'
        payload = {}
        payload['metric'] = metric
        payload['measure'] = float(value)
        if source is not None:
            payload['source'] = source
        if timestamp is not None:
            payload['timestamp'] = Measurement.parse_timestamp(timestamp)
        if properties is not None:
            payload['metadata'] = properties
        self._data = json.dumps(payload, sort_keys=True)
        self._headers = {
            'Content-Type': 'application/json',
            "Accept": "application/json"
        }
        self._path = "v1/measurements"
        self._api_call()
Example #2
0
    def measurement_create(self,
                           metric=None,
                           value=None,
                           source=None,
                           timestamp=None,
                           properties=None):
        """
        Creates a new measurement in TrueSight Pulse instance.

        :param metric: Identifies the metric to use to add a measurement
        :param value: Value of the measurement
        :param source: Origin of the measurement
        :param timestamp: Time of the occurrence of the measurement
        :param properties: Properties of the measurement
        :return: None
        """

        if metric is None:
            raise ValueError('metrics not specified')

        if value is None:
            raise ValueError('value not specified')
        self._method = 'POST'
        payload = {}
        payload['metric'] = metric
        payload['measure'] = float(value)
        if source is not None:
            payload['source'] = source
        if timestamp is not None:
            payload['timestamp'] = Measurement.parse_timestamp(timestamp)
        if properties is not None:
            payload['metadata'] = properties
        self._data = json.dumps(payload, sort_keys=True)
        self._headers = {'Content-Type': 'application/json', "Accept": "application/json"}
        self._path = "v1/measurements"
        self._api_call()
Example #3
0
    def event_create(
        self,
        created_at=None,
        event_class=None,
        fingerprint_fields=None,
        message=None,
        properties=None,
        sender=None,
        severity='INFO',
        source=None,
        status='OPEN',
        tags=None,
        title=None,
    ):
        """
        Creates an event in an account
        :param created_at:
        :param event_class:
        :param fingerprint_fields:
        :param message:
        :param properties:
        :param sender:
        :param severity:
        :param source:
        :param status:
        :param tags:
        :param title:
        :return:
        """

        if title is None:
            raise ValueError('title not specified')

        if source is None:
            raise ValueError('source not specified')

        if fingerprint_fields is None:
            raise ValueError('fingerprint fields not specified')

        payload = {}

        if created_at is not None:
            payload['createdAt'] = Measurement.parse_timestamp(created_at)

        if event_class is not None:
            payload['eventClass'] = event_class

        if fingerprint_fields is not None:
            payload['fingerprintFields'] = fingerprint_fields

        if message is not None:
            payload['message'] = message

        if properties is not None:
            payload['properties'] = properties

        if sender is not None:
            if not isinstance(sender, Sender):
                raise ValueError('sender is not a Sender instance')
            else:
                payload['sender'] = {}
                payload['sender']['ref'] = sender.ref
                payload['sender']['type'] = sender.type
                payload['sender']['name'] = sender.name

        if severity is not None:
            payload['severity'] = severity

        if source is not None:
            if not isinstance(source, Source):
                raise ValueError('source is not a Source instance')
            else:
                payload['source'] = {}
                payload['source']['ref'] = source.ref
                payload['source']['type'] = source.type
                payload['source']['name'] = source.name

        if status is not None:
            payload['status'] = status

        if tags is not None:
            payload['tags'] = tags

        if title is not None:
            payload['title'] = title

        self._method = 'POST'
        self._data = json.dumps(payload)
        self._headers = {
            'Content-Type': 'application/json',
            "Accept": "application/json"
        }
        self._path = 'v1/events'
        self._api_call(handle_results=tspapi.event.event_create_handle_results,
                       good_response=tspapi.event.event_create_good_response)
Example #4
0
    def event_create(self,
                     created_at=None,
                     event_class=None,
                     fingerprint_fields=None,
                     message=None,
                     properties=None,
                     sender=None,
                     severity='INFO',
                     source=None,
                     status='OPEN',
                     tags=None,
                     title=None,
                     ):
        """
        Creates an event in an account
        :param created_at:
        :param event_class:
        :param fingerprint_fields:
        :param message:
        :param properties:
        :param sender:
        :param severity:
        :param source:
        :param status:
        :param tags:
        :param title:
        :return:
        """

        if title is None:
            raise ValueError('title not specified')

        if source is None:
            raise ValueError('source not specified')

        if fingerprint_fields is None:
            raise ValueError('fingerprint fields not specified')

        payload = {}

        if created_at is not None:
            payload['createdAt'] = Measurement.parse_timestamp(created_at)

        if event_class is not None:
            payload['eventClass'] = event_class

        if fingerprint_fields is not None:
            payload['fingerprintFields'] = fingerprint_fields

        if message is not None:
            payload['message'] = message

        if properties is not None:
            payload['properties'] = properties

        if sender is not None:
            if not isinstance(sender, Sender):
                raise ValueError('sender is not a Sender instance')
            else:
                payload['sender'] = {}
                payload['sender']['ref'] = sender.ref
                payload['sender']['type'] = sender.type
                payload['sender']['name'] = sender.name

        if severity is not None:
            payload['severity'] = severity

        if source is not None:
            if not isinstance(source, Source):
                raise ValueError('source is not a Source instance')
            else:
                payload['source'] = {}
                payload['source']['ref'] = source.ref
                payload['source']['type'] = source.type
                payload['source']['name'] = source.name

        if status is not None:
            payload['status'] = status

        if tags is not None:
            payload['tags'] = tags

        if title is not None:
            payload['title'] = title

        self._method = 'POST'
        self._data = json.dumps(payload)
        self._headers = {'Content-Type': 'application/json', "Accept": "application/json"}
        self._path = 'v1/events'
        self._api_call(handle_results=tspapi.event.event_create_handle_results,
                       good_response=tspapi.event.event_create_good_response)