Пример #1
0
 def test_complex_get(self):
     original_dct = {
         'details': {
             'key1': 'value1',
             'subkey': {
                 'subkey': 'subvalue'
             }
         }
     }
     dct = DotDict(original_dct)
     assert dct.get('does.not.exist') == None
     assert dct.get('details') == {'key1': 'value1','subkey': {'subkey': 'subvalue'}}
     assert dct.get('details.key1') == 'value1'
     assert dct.get('details.subkey') == {'subkey':'subvalue'}
     assert dct.get('details.subkey.subkey') == 'subvalue'
Пример #2
0
    def onMessage(self, message, metadata):
        if 'source' not in message:
            return (message, metadata)

        if not message['source'] == 'guardduty':
            return (message, metadata)

        # reformat the date fields to iosformat
        for date_key in self.date_keys:
            if key_exists(date_key, message):
                message = self.convert_key_date_format(date_key, message)

        # convert the dict to a dot dict for saner deep key/value processing
        message=DotDict(message)
        # pull out the likely source IP address
        for ipaddress_key in self.ipaddress_keys:
            if 'sourceipaddress' not in message['details'].keys():
                if key_exists(ipaddress_key,message):
                    message.details.sourceipaddress = message.get(ipaddress_key)

        # recovert the message back to a plain dict
        return (dict(message), metadata)