Skip to content

Commit fb35091

Browse files
committed
fix(connectors): eliminate N+1 HTTP requests in MISP connector
1 parent bb50c8e commit fb35091

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

  • api_app/connectors_manager/connectors

api_app/connectors_manager/connectors/misp.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def _base_attr_obj(self) -> pymisp.MISPAttribute:
6262
value = self._job.analyzable.name
6363
if _type == Classification.HASH:
6464
matched_type = helpers.get_hash_type(value)
65-
matched_type.replace("-", "") # convert sha-x to shax
66-
_type = matched_type if matched_type is not None else "text"
65+
_type = matched_type.replace("-", "") if matched_type is not None else "text"
6766
else:
6867
_type = INTELOWL_MISP_TYPE_MAP[_type]
6968

@@ -119,13 +118,20 @@ def run(self):
119118
# append attribute name to event info
120119
event.info += f": {base_attr.value}"
121120

122-
# add event to MISP Instance
123-
misp_event = misp_instance.add_event(event, pythonify=True)
124-
# add attributes to event on MISP Instance
121+
# bulk: attach all attributes to the event object before sending
125122
for attr in attributes:
126-
misp_instance.add_attribute(misp_event.id, attr)
123+
event.add_attribute(
124+
attr.type,
125+
attr.value,
126+
**{k: v for k, v in attr.to_dict().items() if k not in ("type", "value", "uuid")},
127+
)
128+
129+
# add event + all attributes in a single request (bulk optimization)
130+
misp_event = misp_instance.add_event(event, pythonify=True)
131+
132+
result = misp_instance.get_event(misp_event.id)
127133

128-
return misp_instance.get_event(misp_event.id)
134+
return result
129135

130136
@classmethod
131137
def _monkeypatch(cls):

0 commit comments

Comments
 (0)