From 8560b4db0a1bbbe65499f58a4458c285176507a1 Mon Sep 17 00:00:00 2001 From: Aditya <60684641+0x0elliot@users.noreply.github.com> Date: Tue, 30 Jan 2024 08:05:10 +0530 Subject: [PATCH] fix: semantic changes :heart: --- backend/api_app/monitoring/exceptions.py | 4 ++-- backend/api_app/monitoring/integrations.py | 2 +- backend/api_app/monitoring/serializers.py | 13 ++++++++----- backend/configuration/iocs.json | 5 +++++ .../yaml/TRACK_ADDRESSES_WITHOUT_IDENTITY.yaml | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/backend/api_app/monitoring/exceptions.py b/backend/api_app/monitoring/exceptions.py index 6c7d4e0..60131d8 100644 --- a/backend/api_app/monitoring/exceptions.py +++ b/backend/api_app/monitoring/exceptions.py @@ -1,8 +1,8 @@ class ConditionResultError(Exception): """Raised when a condition result is invalid.""" - def __init__(self, message): - super().__init__(f"Condition result is invalid: {message}") + def __init__(self, message, condition): + super().__init__(f"Condition result is invalid: {message} - {condition}") class ABINotFoundError(Exception): diff --git a/backend/api_app/monitoring/integrations.py b/backend/api_app/monitoring/integrations.py index 1388999..55d8b3e 100644 --- a/backend/api_app/monitoring/integrations.py +++ b/backend/api_app/monitoring/integrations.py @@ -2,7 +2,7 @@ import requests # move this to a separate file later -def airstack_identities(self, wallet: str) -> dict: +def airstack_identities(wallet: str) -> dict: url = "https://api.airstack.xyz/gql" headers = { diff --git a/backend/api_app/monitoring/serializers.py b/backend/api_app/monitoring/serializers.py index a570348..b87d88f 100644 --- a/backend/api_app/monitoring/serializers.py +++ b/backend/api_app/monitoring/serializers.py @@ -246,21 +246,24 @@ def check_alert_condition(self, alert) -> bool: variables = { "txn": txn_or_block, + } + + functions = { "airstack_identities": airstack_identities, } if condition is None: - raise ConditionResultError("Condition not found in alert.") + raise ConditionResultError("Condition not found in alert.", condition) try: - result: bool = simple_eval(condition, names=variables) + result: bool = simple_eval(condition, names=variables, functions=functions) except Exception as e: - raise ConditionResultError(e) + raise ConditionResultError(e, condition) if isinstance(result, bool): return result - raise ConditionResultError("Condition didn't return a boolean.") + raise ConditionResultError("Condition didn't return a boolean.", condition) def run_dummy_check(self): # implement this later @@ -302,7 +305,7 @@ def send_webhook(self, alert_data): alert_body = { "message": f"Alert {self.Alert.name} triggered for { text } {hash_}", - "transaction": self.transaction.compile_to_dict(), + text: self.transaction.compile_to_dict(), } logger.info("[INFO] Alert body: " + str(alert_body)) diff --git a/backend/configuration/iocs.json b/backend/configuration/iocs.json index 9a9e41f..ebb5dfb 100644 --- a/backend/configuration/iocs.json +++ b/backend/configuration/iocs.json @@ -26,6 +26,11 @@ "name": "WEBHOOK_URL", "description": "Webhook URL for sending alerts", "type": "str" + }, + "FROM": { + "name": "FROM", + "description": "Address to track", + "type": "str" } } }, diff --git a/backend/configuration/yaml/TRACK_ADDRESSES_WITHOUT_IDENTITY.yaml b/backend/configuration/yaml/TRACK_ADDRESSES_WITHOUT_IDENTITY.yaml index 220633b..9623930 100644 --- a/backend/configuration/yaml/TRACK_ADDRESSES_WITHOUT_IDENTITY.yaml +++ b/backend/configuration/yaml/TRACK_ADDRESSES_WITHOUT_IDENTITY.yaml @@ -2,7 +2,7 @@ blockchain_alerts: - alert_type: every_transaction alerts: AlertName: - condition: 'airstack_identities(from).get("socials") == None' + condition: 'airstack_identities(${FROM}).get("socials") == None' notifications: - send_webhook webhook_url: '${WEBHOOK_URL}' \ No newline at end of file