Skip to content

Commit

Permalink
fix: semantic changes ❤️
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Jan 30, 2024
1 parent 584ff8a commit 8560b4d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/api_app/monitoring/exceptions.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion backend/api_app/monitoring/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
13 changes: 8 additions & 5 deletions backend/api_app/monitoring/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions backend/configuration/iocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"name": "WEBHOOK_URL",
"description": "Webhook URL for sending alerts",
"type": "str"
},
"FROM": {
"name": "FROM",
"description": "Address to track",
"type": "str"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'

0 comments on commit 8560b4d

Please sign in to comment.