16
16
from intelmq .lib .utils import parse_relative
17
17
18
18
try :
19
- from pymisp import MISPEvent , MISPObject , MISPOrganisation , NewAttributeError
19
+ from pymisp import MISPEvent , MISPObject , MISPOrganisation , MISPTag , NewAttributeError
20
20
from pymisp .tools import feed_meta_generator
21
21
except ImportError :
22
22
# catching SyntaxError because of https://github.com/MISP/PyMISP/issues/501
@@ -38,6 +38,10 @@ class MISPFeedOutputBot(OutputBot, CacheMixin):
38
38
attribute_mapping : dict = None
39
39
event_separator : str = None
40
40
additional_info : str = None
41
+ tagging : dict = None
42
+ # A structure like:
43
+ # __all__: list of tag kwargs for all events
44
+ # <key>: list of tag kwargs per separator key
41
45
42
46
@staticmethod
43
47
def check_output_dir (dirname ):
@@ -95,6 +99,18 @@ def init(self):
95
99
self .max_time_current = self .min_time_current + self .timedelta
96
100
self .current_events = {}
97
101
102
+ self ._tagging_objects = {}
103
+ if self .tagging :
104
+ for key , tag_list in self .tagging .items ():
105
+ self ._tagging_objects [key ] = list ()
106
+ for kw in tag_list :
107
+ # For some reason, PyMISP do not uses classmethod, and from_dict requires
108
+ # unpacking. So this is really the way to initialize tag objects.
109
+ tag = MISPTag ()
110
+ tag .from_dict (** kw )
111
+ self ._tagging_objects [key ].append (tag )
112
+ self .logger .debug ("Generated tags: %r." , self ._tagging_objects )
113
+
98
114
def _load_event (self , file_path : Path , key : str ):
99
115
if file_path .exists ():
100
116
self .current_events [key ] = MISPEvent ()
@@ -140,6 +156,14 @@ def process(self):
140
156
141
157
def _generate_new_event (self , key ):
142
158
self .current_events [key ] = MISPEvent ()
159
+
160
+ tags : list [MISPTag ] = []
161
+ if "__all__" in self ._tagging_objects :
162
+ tags .extend (self ._tagging_objects ["__all__" ])
163
+ if key in self ._tagging_objects :
164
+ tags .extend (self ._tagging_objects [key ])
165
+ self .current_events [key ].tags = tags
166
+
143
167
info = "IntelMQ event {begin} - {end}" "" .format (
144
168
begin = self .min_time_current .isoformat (),
145
169
end = self .max_time_current .isoformat (),
@@ -195,6 +219,9 @@ def _default_mapping(self, obj: "MISPObject", message: dict):
195
219
)
196
220
197
221
def _extract_misp_attribute_kwargs (self , message : dict , definition : dict ) -> dict :
222
+ """
223
+ Creates a
224
+ """
198
225
# For caching and default mapping, the serialized version is the right format to work on.
199
226
# However, for any custom mapping the Message object is more sufficient as it handles
200
227
# subfields.
0 commit comments