From a2b28db32efb4bb9e6522d37a35a6c0c31316d6d Mon Sep 17 00:00:00 2001 From: TonyJabbour Date: Mon, 4 Oct 2021 12:55:40 +0200 Subject: [PATCH] Added a try/catch to handle exceptions Replaced the raise to send message to redis_logger --- bin/trackers/Tracker_Regex.py | 9 ++++++--- bin/trackers/Tracker_Term.py | 10 +++++++--- bin/trackers/Tracker_Yara.py | 10 +++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/bin/trackers/Tracker_Regex.py b/bin/trackers/Tracker_Regex.py index 00642445..8134c67b 100755 --- a/bin/trackers/Tracker_Regex.py +++ b/bin/trackers/Tracker_Regex.py @@ -109,9 +109,12 @@ class Tracker_Regex(AbstractModule): "emailNotification": f'{mail_to_notify}', "trackerType": tracker_type } - response = requests.post(webhook_to_post, json=json_request) - if response.status_code >= 400: - raise Exception(f"Webhook request failed for {webhook_to_post}\nReason: {response.reason}") + try: + response = requests.post(webhook_to_post, json=json_request) + if response.status_code >= 400: + self.redis_logger.error(f"Webhook request failed for {webhook_to_post}\nReason: {response.reason}") + except: + self.redis_logger.error(f"Webhook request failed for {webhook_to_post}\nReason: Something went wrong") if __name__ == "__main__": diff --git a/bin/trackers/Tracker_Term.py b/bin/trackers/Tracker_Term.py index 703dfb4f..fd90224a 100755 --- a/bin/trackers/Tracker_Term.py +++ b/bin/trackers/Tracker_Term.py @@ -152,9 +152,13 @@ class Tracker_Term(AbstractModule): "emailNotification": f'{mail_to_notify}', "trackerType": term_type } - response = requests.post(webhook_to_post, json=json_request) - if response.status_code >= 400: - raise Exception(f"Webhook request failed for {webhook_to_post}\nReason: {response.reason}") + try: + response = requests.post(webhook_to_post, json=json_request) + if response.status_code >= 400: + self.redis_logger.error(f"Webhook request failed for {webhook_to_post}\nReason: {response.reason}") + except: + self.redis_logger.error(f"Webhook request failed for {webhook_to_post}\nReason: Something went wrong") + if __name__ == '__main__': diff --git a/bin/trackers/Tracker_Yara.py b/bin/trackers/Tracker_Yara.py index 43cd179b..3b23fbee 100755 --- a/bin/trackers/Tracker_Yara.py +++ b/bin/trackers/Tracker_Yara.py @@ -109,9 +109,13 @@ class Tracker_Yara(AbstractModule): "emailNotification": f'{mail_to_notify}', "trackerType": "yara" } - response = requests.post(webhook_to_post, json=json_request) - if response.status_code >= 400: - raise Exception(f"Webhook request failed for {webhook_to_post}\nReason: {response.reason}") + try: + response = requests.post(webhook_to_post, json=json_request) + if response.status_code >= 400: + self.redis_logger.error(f"Webhook request failed for {webhook_to_post}\nReason: {response.reason}") + except: + self.redis_logger.error(f"Webhook request failed for {webhook_to_post}\nReason: Something went wrong") + return yara.CALLBACK_CONTINUE