diff --git a/cs_misp_import/importer.py b/cs_misp_import/importer.py index 74ab55a..f653586 100644 --- a/cs_misp_import/importer.py +++ b/cs_misp_import/importer.py @@ -212,12 +212,12 @@ def remove_crowdstrike_tags(self): fallback="BEGIN DELETE", hide_cool_banners=self.import_settings["no_banners"] ) - # self.log.info(DELETE_BANNER) removed = 0 - self.log.info("Retrieving list of tags to remove from MISP instance") + self.log.info("Retrieving list of tags to remove from MISP instance (may take several minutes).") + lock = Lock() with concurrent.futures.ThreadPoolExecutor(self.misp_client.thread_count, thread_name_prefix="thread") as executor: futures = { - executor.submit(self.misp_client.clear_tag, tg) + executor.submit(self.misp_client.clear_tag, tg, lock) for tg in self.misp_client.search_tags("CrowdStrike:%", strict_tagname=True) } for _ in concurrent.futures.as_completed(futures): diff --git a/cs_misp_import/threaded_misp.py b/cs_misp_import/threaded_misp.py index 9edc374..c2ade7d 100644 --- a/cs_misp_import/threaded_misp.py +++ b/cs_misp_import/threaded_misp.py @@ -101,16 +101,34 @@ def get_cs_tags(self): return self.search_tags("CrowdStrike:%", strict_tagname=True) def clear_tag(self, *args, **kwargs): -# tags = self.search_tags("CrowdStrike:%") - #for tag in kwargstags: - tag = args[0] - if tag: + def perform_tag_clear(): if not self.deleted_tag_count % 50 and self.deleted_tag_count: self.log.info("%i tags deleted", self.deleted_tag_count, extra={"key": ""}) result = self._retry(self.delete_tag, tag, **kwargs) if "errors" not in result: self.deleted_tag_count += 1 + thread_lock = kwargs.get("lock", None) + if thread_lock: + kwargs.pop("lock") + tag = args[0] + if tag: + if thread_lock: + with thread_lock: + perform_tag_clear() + # if not self.deleted_tag_count % 50 and self.deleted_tag_count: + # self.log.info("%i tags deleted", self.deleted_tag_count, extra={"key": ""}) + # result = self._retry(self.delete_tag, tag, **kwargs) + # if "errors" not in result: + # self.deleted_tag_count += 1 + else: + perform_tag_clear() + # if not self.deleted_tag_count % 50 and self.deleted_tag_count: + # self.log.info("%i tags deleted", self.deleted_tag_count, extra={"key": ""}) + # result = self._retry(self.delete_tag, tag, **kwargs) + # if "errors" not in result: + # self.deleted_tag_count += 1 + return self.deleted_tag_count #self.log.info("%i tags deleted", self.deleted_tag_count)