コード例 #1
0
 def _parse_system_properties(self, message: Message):
     try:
         return unicode_binary_map(parse_entity(message.properties, True))
     except Exception:
         details = strings.invalid_system_properties()
         self._add_issue(severity=Severity.warning, details=details)
         return {}
コード例 #2
0
    def _output_msg_kpi(msg):
        # TODO: Determine if amqp filters can support boolean operators for multiple conditions
        origin = str(msg.annotations.get(b'iothub-connection-device-id'), 'utf8')
        if device_id and origin != device_id:
            return

        event_source = {'event': {}}

        event_source['event']['origin'] = origin
        event_source['event']['payload'] = str(next(msg.get_data()), 'utf8')
        if 'anno' in properties or 'all' in properties:
            event_source['event']['annotations'] = unicode_binary_map(msg.annotations)
        if 'sys' in properties or 'all' in properties:
            if not event_source['event'].get('properties'):
                event_source['event']['properties'] = {}
            event_source['event']['properties']['system'] = unicode_binary_map(parse_entity(msg.properties, True))
        if 'app' in properties or 'all' in properties:
            if not event_source['event'].get('properties'):
                event_source['event']['properties'] = {}
            app_prop = msg.application_properties if msg.application_properties else None

            if app_prop:
                event_source['event']['properties']['application'] = unicode_binary_map(app_prop)

        six.print_(yaml.dump(event_source, default_flow_style=False), flush=True)
コード例 #3
0
 def _parse_system_properties(self, message: Message):
     try:
         return unicode_binary_map(parse_entity(message.properties, True))
     except Exception:
         self._errors.append(
             "Failed to parse system_properties for message {message}.".
             format(message))
         return {}
コード例 #4
0
    def _output_msg_kpi(msg):
        # TODO: Determine if amqp filters can support boolean operators for multiple conditions
        origin = str(msg.annotations.get(b'iothub-connection-device-id'), 'utf8')
        if device_id and device_id != origin:
            if '*' in device_id or '?' in device_id:
                regex = re.escape(device_id).replace("\\*", ".*").replace('\\?', ".") + "$"
                if not re.match(regex, origin):
                    return
            else:
                return
        if devices and origin not in devices:
            return

        event_source = {'event': {}}

        event_source['event']['origin'] = origin

        payload = ''

        data = msg.get_data()
        if data:
            payload = str(next(data), 'utf8')

        system_props = unicode_binary_map(parse_entity(msg.properties, True))

        ct = content_type
        if not ct:
            ct = system_props['content_type'] if 'content_type' in system_props else ''

        if ct and ct.lower() == 'application/json':
            try:
                payload = json.loads(re.compile(r'(\\r\\n)+|\\r+|\\n+').sub('', payload))
            except Exception:  # pylint: disable=broad-except
                # We don't want to crash the monitor if JSON parsing fails
                pass

        event_source['event']['payload'] = payload

        if 'anno' in properties or 'all' in properties:
            event_source['event']['annotations'] = unicode_binary_map(msg.annotations)
        if 'sys' in properties or 'all' in properties:
            if not event_source['event'].get('properties'):
                event_source['event']['properties'] = {}
            event_source['event']['properties']['system'] = system_props
        if 'app' in properties or 'all' in properties:
            if not event_source['event'].get('properties'):
                event_source['event']['properties'] = {}
            app_prop = msg.application_properties if msg.application_properties else None

            if app_prop:
                event_source['event']['properties']['application'] = unicode_binary_map(app_prop)

        if output.lower() == 'json':
            dump = json.dumps(event_source, indent=4)
        else:
            dump = yaml.safe_dump(event_source, default_flow_style=False)

        six.print_(dump, flush=True)
コード例 #5
0
async def evaluate_redirect(endpoint):
    source = uamqp.address.Source('amqps://{}/messages/events/$management'.format(endpoint))
    receive_client = uamqp.ReceiveClientAsync(source, timeout=30000, prefetch=1, debug=DEBUG)

    try:
        await receive_client.open_async()
        await receive_client.receive_message_batch_async(max_batch_size=1)
    except uamqp.errors.LinkRedirect as redirect:
        redirect = unicode_binary_map(parse_entity(redirect))
        result = {}
        result['events'] = {}
        result['events']['endpoint'] = redirect['hostname']
        result['events']['path'] = redirect['address'].replace('amqps://', '').split('/')[1]
        result['events']['address'] = redirect['address']
        return redirect, result
    finally:
        await receive_client.close_async()
コード例 #6
0
    async def _evaluate_redirect(self, endpoint):
        source = uamqp.address.Source(
            "amqps://{}/messages/events/$management".format(endpoint))
        receive_client = uamqp.ReceiveClientAsync(source,
                                                  timeout=30000,
                                                  prefetch=1,
                                                  debug=DEBUG)

        try:
            await receive_client.open_async()
            await receive_client.receive_message_batch_async(max_batch_size=1)
        except uamqp.errors.LinkRedirect as redirect:
            redirect = unicode_binary_map(parse_entity(redirect))
            result = {}
            result["events"] = {}
            result["events"]["endpoint"] = redirect["hostname"]
            result["events"]["path"] = (redirect["address"].replace(
                "amqps://", "").split("/")[1])
            result["events"]["address"] = redirect["address"]
            return redirect, result
        finally:
            await receive_client.close_async()