def process(self,
             record: LogRecord,
             state: PipelineStageResult) -> PipelineStageResult:
     from re import search, I, X
     if search(COMPONENT_ID_PATTERN, record.content, I | X):
         return PipelineStageResult(tags=[COMPONENT_NAMESPACE])
     return PipelineStageResult()
def test_stage_result_can_check_presence_with_if_stmt():
    assert not PipelineStageResult()
    assert not PipelineStageResult(tags=[])
    assert not PipelineStageResult(structured={})

    assert PipelineStageResult(tags=['any'])
    assert PipelineStageResult(structured={'any': 'value'})
    def process(self, record: LogRecord,
                state: PipelineStageResult) -> PipelineStageResult:

        if not type(state.structured[STRUCT_D]) == list:
            state = state.structured[STRUCT_D]
            conn = {}
            if 'connOpened' in state:

                conn = {}
                conn['rem_name'] = state['connOpened']['remName']
                conn['rem_port'] = state['connOpened']['remPort']
                conn['loc_name'] = state['connOpened']['locName']
                conn['loc_port'] = state['connOpened']['locPort']
                CONN_RESULT = PipelineStageResult(structured={CONN_KEY: conn})

                return CONN_RESULT

            elif state and 'remName' in state and 'locName' in state:

                conn = {}
                conn['rem_name'] = state['remName']
                conn['rem_port'] = state['remPort']
                conn['loc_name'] = state['locName']
                conn['loc_port'] = state['locPort']
                CONN_RESULT = PipelineStageResult(structured={CONN_KEY: conn})
                return CONN_RESULT

        return PipelineStageResult()
Ejemplo n.º 4
0
    def process(self, record: LogRecord,
                state: PipelineStageResult) -> PipelineStageResult:

        from re import search, I, X
        match = search(STRUCTURED_DATA_PATTERN_ID, record.content, I | X)
        if match:
            return PipelineStageResult(
                structured={MSG_ID: match.groupdict()['object_id']})
        return PipelineStageResult()
Ejemplo n.º 5
0
    def process(self, record, state):
        if not record:
            return PipelineStageResult()
        from re import search, I
        matches = search(INTRODUCTION_PATTERN, record.content, I)

        tags = []
        if matches:
            tags.append(TAG_INTRO)

        return PipelineStageResult(tags=tags)
def test_stage_result_tags_are_immutable():
    tags = ['actual-results']
    res = PipelineStageResult(tags=tags)

    with pytest.raises(AttributeError) as e:
        res.tags = ['falsified-results']

    assert e.match("can't set attribute")
    assert res.tags == tags

    res.tags.append('another')

    assert res.tags == tags
def test_stage_result_structured_data_are_immutable():
    sdata = {'component': {'id': 'SomethingSomethingComponent'}}
    res = PipelineStageResult(structured=sdata)

    with pytest.raises(AttributeError) as e:
        res.structured = {}

    assert e.match("can't set attribute")
    assert res.structured == sdata

    res.structured['another'] = 'key'
    res.structured['component']['another'] = 'key'

    assert res.structured == sdata
Ejemplo n.º 8
0
    def process(self, record: LogRecord) -> PipelineStageResult:
        results_so_far = PipelineStageResult()
        for (name, stage) in self._stages:
            try:
                stage_results = stage.process(record, results_so_far)
                results_so_far = PipelineStageResult(
                    tags=[*results_so_far.tags, *stage_results.tags],
                    structured={
                        **results_so_far.structured,
                        **stage_results.structured
                    })
            except Exception as e:
                raise Exception(f'stage {name}: {str(e)}')

        return results_so_far
    def process(self,
                record: LogRecord,
                state: PipelineStageResult) -> PipelineStageResult:
        from re import search, I, X
        if COMPONENT_NAMESPACE not in state.tags:
            return PipelineStageResult()

        cap = {
            **search(COMPONENT_ID_PATTERN, record.content, I | X).groupdict(),
            **search(COMPONENT_TYPE_PATTERN, record.content, I | X).groupdict()
        }
        return PipelineStageResult(structured={
            COMPONENT_NAMESPACE: {
                'type': cap['component_type'],
                'id': cap['component_id']
            }
        })
Ejemplo n.º 10
0
    def process(self, record, state):
        if not record:
            return PipelineStageResult()

        if TAG_INTRO not in state.tags:
            return PipelineStageResult()

        from re import search, I
        matches = search(INTRODUCTION_PATTERN, record.content, I)

        if matches:
            caps = matches.groupdict()
            return PipelineStageResult(
                structured={TAG_INTRO: {
                    'name': caps['name']
                }})

        return PipelineStageResult()
Ejemplo n.º 11
0
 def process(self, record, state):
     import json
     from sys import stdout
     print(json.dumps({
         'record': record.__dict__,
         'results': state.__dict__
     }),
           file=stdout)
     return PipelineStageResult()
Ejemplo n.º 12
0
    def process(self,
                record: LogRecord,
                state: PipelineStageResult) -> PipelineStageResult:
        if MSG_ID in state.structured and STRUCTURED_DATA in state.structured:
            sdata = state.structured[STRUCTURED_DATA]
            # FIXME: assumes exactly zero or one instances in the list.
            for asp in sdata.get('aspsSip', []):
                if 'aspRequest' not in asp:
                    return PipelineStageResult()

                req = asp['aspRequest']
                if not req or not sdata['internalMessage']:
                    return PipelineStageResult()

                type_ = sdata['internalMessage']['description']
                return PipelineStageResult(structured={
                    MESSAGE_TYPE: type_
                })

        return PipelineStageResult()
Ejemplo n.º 13
0
def test_parse_map(mapstr):
    header = ('2014/Oct/24 19:16:48.062933 111 SYSCALL ' +
              'ExampleComponentTest.ttcn:313(function:ExampleTestedFunction)')
    stage = ParseSdata()
    record = LogRecord(f'{header} asdf')
    result = stage.process(
        record,
        PipelineStageResult(structured={STRUCTURED_DATA_AS_STRING: mapstr}))

    sdata = result.structured[STRUCTURED_DATA]

    expected = {
        'true': True,
        'false': False,
        'string': 'Read me',
        'integer': 42,
        'real': 42.0,
        'negative_integer': -42,
        'negative_real': -42.0,
        'list': ['we are now', 'getting', 'lispy'],
        'empty_object': {},
        'a_nested': {
            'map': 'this one is'
        },
        'weirdo_data': {
            'hex': '4865786C696679206D65',
            'plain': 'Hexlify me'
        },
        'named_value': {
            'name': 'NAME',
            'value': '0x42'  # TODO: Currently always treated as string
        },
        'undefined': None,
        'also_undefined': None
    }

    assert sdata == expected
 def process(self,
             record: LogRecord,
             state: PipelineStageResult) -> PipelineStageResult:
     return PipelineStageResult()