Skip to content

Commit 9b5e22b

Browse files
committed
Check if a tag is already attached to an event before adding it
Related to #13 , adapted from @TheDr1ver comment
1 parent e0bccd0 commit 9b5e22b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/otx_misp/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def tag_event(misp, event, tag):
6060
:param tag: tag to add
6161
:return: None
6262
"""
63+
if not hasattr(misp, '_otx_tags_cache'):
64+
misp._otx_tags_cache = misp.get_all_tags()['Tag']
65+
for exist_tag in misp._otx_tags_cache:
66+
if exist_tag['name'] == tag:
67+
tag_id = exist_tag['id']
68+
if 'EventTag' in event:
69+
for evt_tag in event['EventTag']:
70+
if tag_id == evt_tag['id']:
71+
log.info("\t - Tag already exists. Skipping:".format(tag))
72+
return
73+
break
6374
if hasattr(misp, 'tag'):
6475
version = misp_server_version(misp).split('.')
6576
tag_version = '2.4.69'.split('.')

0 commit comments

Comments
 (0)