From 49a240612cded2915c8416ea809bb64b7724aed6 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 13 Jan 2022 17:13:50 +0100 Subject: [PATCH] feat(alerts): fix webhook json-serialization issue --- api/app.py | 5 +++-- api/app_alerts.py | 5 ++--- api/chalicelib/core/alerts_processor.py | 6 +++++- ee/api/app.py | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/api/app.py b/api/app.py index 0d4176330..d261dadac 100644 --- a/api/app.py +++ b/api/app.py @@ -1,6 +1,7 @@ import logging from apscheduler.schedulers.asyncio import AsyncIOScheduler +from decouple import config from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from starlette.responses import StreamingResponse @@ -65,5 +66,5 @@ for job in core_crons.cron_jobs + core_dynamic_crons.cron_jobs: for job in Schedule.get_jobs(): print({"Name": str(job.id), "Run Frequency": str(job.trigger), "Next Run": str(job.next_run_time)}) -logging.basicConfig(level=logging.INFO) -logging.getLogger('apscheduler').setLevel(logging.INFO) +logging.basicConfig(level=config("LOGLEVEL", default=logging.INFO)) +logging.getLogger('apscheduler').setLevel(config("LOGLEVEL", default=logging.INFO)) diff --git a/api/app_alerts.py b/api/app_alerts.py index bdd4702e2..57bfcd55d 100644 --- a/api/app_alerts.py +++ b/api/app_alerts.py @@ -20,9 +20,8 @@ app.schedule.start() app.schedule.add_job(id="alerts_processor", **{"func": alerts_processor.process, "trigger": "interval", "minutes": config("ALERTS_INTERVAL", cast=int, default=5), "misfire_grace_time": 20}) - for job in app.schedule.get_jobs(): print({"Name": str(job.id), "Run Frequency": str(job.trigger), "Next Run": str(job.next_run_time)}) -logging.basicConfig(level=logging.INFO) -logging.getLogger('apscheduler').setLevel(logging.INFO) +logging.basicConfig(level=config("LOGLEVEL", default=logging.INFO)) +logging.getLogger('apscheduler').setLevel(config("LOGLEVEL", default=logging.INFO)) diff --git a/api/chalicelib/core/alerts_processor.py b/api/chalicelib/core/alerts_processor.py index 36ea9c501..80973fadd 100644 --- a/api/chalicelib/core/alerts_processor.py +++ b/api/chalicelib/core/alerts_processor.py @@ -1,3 +1,4 @@ +import decimal import logging import schemas @@ -224,7 +225,10 @@ def process(): "sourceMeta": alert["detectionMethod"], "message": alert["options"]["message"], "projectId": alert["projectId"], "data": {"title": alert["name"], - "limitValue": alert["query"]["right"], "actualValue": result["value"], + "limitValue": alert["query"]["right"], + "actualValue": float(result["value"]) \ + if isinstance(result["value"], decimal.Decimal) \ + else result["value"], "operator": alert["query"]["operator"], "trigger": alert["query"]["left"], "alertId": alert["alertId"], diff --git a/ee/api/app.py b/ee/api/app.py index 15bcc7ac5..fdf7f60b8 100644 --- a/ee/api/app.py +++ b/ee/api/app.py @@ -2,6 +2,7 @@ import logging import queue from apscheduler.schedulers.asyncio import AsyncIOScheduler +from decouple import config from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from starlette import status @@ -81,5 +82,5 @@ app.schedule.add_job(id="trace_worker", **traces.cron_jobs[0]) for job in app.schedule.get_jobs(): print({"Name": str(job.id), "Run Frequency": str(job.trigger), "Next Run": str(job.next_run_time)}) -logging.basicConfig(level=logging.INFO) -logging.getLogger('apscheduler').setLevel(logging.INFO) +logging.basicConfig(level=config("LOGLEVEL", default=logging.INFO)) +logging.getLogger('apscheduler').setLevel(config("LOGLEVEL", default=logging.INFO))