diff --git a/api/chalicelib/core/alerts.py b/api/chalicelib/core/alerts.py index 42411b8bc..3bb632c30 100644 --- a/api/chalicelib/core/alerts.py +++ b/api/chalicelib/core/alerts.py @@ -7,9 +7,6 @@ from chalicelib.utils import pg_client, helper, email_helper from chalicelib.utils.TimeUTC import TimeUTC -# ALLOW_UPDATE = ["name", "description", "active", "detectionMethod", "query", "options"] - - def get(id): with pg_client.PostgresClient() as cur: cur.execute( @@ -38,34 +35,6 @@ def get_all(project_id): return all -# SUPPORTED_THRESHOLD = [15, 30, 60, 120, 240, 1440] -# -# -# def __transform_structure(data): -# if data.get("options") is None: -# return f"Missing 'options'", None -# if data["options"].get("currentPeriod") not in SUPPORTED_THRESHOLD: -# return f"Unsupported currentPeriod, please provide one of these values {SUPPORTED_THRESHOLD}", None -# if data["options"].get("previousPeriod", 15) not in SUPPORTED_THRESHOLD: -# return f"Unsupported previousPeriod, please provide one of these values {SUPPORTED_THRESHOLD}", None -# if data["options"].get("renotifyInterval") is None: -# data["options"]["renotifyInterval"] = 720 -# data["query"]["right"] = float(data["query"]["right"]) -# data["query"] = json.dumps(data["query"]) -# data["description"] = data["description"] if data.get("description") is not None and len( -# data["description"]) > 0 else None -# if data.get("options"): -# messages = [] -# for m in data["options"].get("message", []): -# if m.get("value") is None: -# continue -# m["value"] = str(m["value"]) -# messages.append(m) -# data["options"]["message"] = messages -# data["options"] = json.dumps(data["options"]) -# return None, data - - def __process_circular(alert): if alert is None: return None @@ -83,7 +52,7 @@ def create(project_id, data: schemas.AlertSchema): cur.execute( cur.mogrify("""\ INSERT INTO public.alerts(project_id, name, description, detection_method, query, options, series_id) - VALUES (%(project_id)s, %(name)s, %(description)s, %(detectionMethod)s, %(query)s, %(options)s::jsonb, %(series_id)s) + VALUES (%(project_id)s, %(name)s, %(description)s, %(detection_method)s, %(query)s, %(options)s::jsonb, %(series_id)s) RETURNING *;""", {"project_id": project_id, **data}) ) @@ -96,15 +65,6 @@ def update(id, data: schemas.AlertSchema): data["query"] = json.dumps(data["query"]) data["options"] = json.dumps(data["options"]) - # changes = {k: changes[k] for k in changes.keys() if k in ALLOW_UPDATE} - # err, changes = __transform_structure(changes) - # if err is not None: - # return {"errors": [err]} - # updateq = [] - # for k in changes.keys(): - # updateq.append(f"{helper.key_to_snake_case(k)} = %({k})s") - # if len(updateq) == 0: - # return {"errors": ["nothing to update"]} with pg_client.PostgresClient() as cur: query = cur.mogrify("""\ UPDATE public.alerts @@ -144,7 +104,6 @@ def process_notifications(data): BATCH_SIZE = 200 for t in full.keys(): for i in range(0, len(full[t]), BATCH_SIZE): - # helper.async_post(config('alert_ntf') % t, {"notifications": full[t][i:i + BATCH_SIZE]}) notifications_list = full[t][i:i + BATCH_SIZE] if t == "slack": diff --git a/api/schemas.py b/api/schemas.py index 6a33c20a4..0dfd949ac 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -325,7 +325,7 @@ class AlertDetectionMethod(str, Enum): class AlertSchema(BaseModel): name: str = Field(...) - detectionMethod: AlertDetectionMethod = Field(...) + detection_method: AlertDetectionMethod = Field(...) description: Optional[str] = Field(None) options: _AlertOptionSchema = Field(...) query: _AlertQuerySchema = Field(...)