fix: include asset_name in customer notifications and logging (#410)
taylor_socfortress committed
Feb 25, 2025 at 16:10 UTC
dad788ea7b2b9438249e185bb766c68caaf52555
1 file changed
+7
-5
backend/app/incidents/services/incident_alert.py
+7
-5
@@ -470,6 +470,7 @@ async def build_alert_payload(
470
471
async def handle_customer_notifications(
472
customer_code: str,
473
+ asset_name: str,
474
alert_payload: CreatedAlertPayload,
475
session: AsyncSession,
476
type: str = "alert",
@@ -483,6 +484,7 @@ async def handle_customer_notifications(
484
execution_arguments={
485
"type": type,
486
"customer_code": customer_code,
487
+ "asset_name": asset_name,
488
"alert_context_payload": alert_payload.alert_context_payload,
489
"alert_title": alert_payload.alert_title_payload,
490
"alert_id": alert_payload.alert_id,
@@ -511,7 +513,7 @@ async def create_alert_full(alert_payload: CreatedAlertPayload, customer_code: s
513
alert_context_id = (
514
await create_alert_context_payload(source=alert_payload.source, alert_payload=alert_payload.alert_context_payload, session=session)
515
).id
514
- asset_id = (
516
+ asset = (
517
await create_asset_context_payload(
518
customer_code=customer_code,
519
asset_payload=alert_payload,
@@ -519,7 +521,7 @@ async def create_alert_full(alert_payload: CreatedAlertPayload, customer_code: s
521
alert_id=alert_id,
522
session=session,
523
)
522
- ).id
524
+ )
525
if alert_payload.ioc_payload is not None:
526
ioc_id = (
527
await create_ioc_payload(
@@ -534,11 +536,11 @@ async def create_alert_full(alert_payload: CreatedAlertPayload, customer_code: s
536
)
537
).id
538
logger.info(
537
- f"Creating alert for customer code {customer_code} with alert context ID {alert_context_id} and asset ID {asset_id} and ioc ID {ioc_id}",
539
+ f"Creating alert for customer code {customer_code} with alert context ID {alert_context_id} and asset ID {asset.id} and ioc ID {ioc_id}",
540
)
539
- logger.info(f"Creating alert for customer code {customer_code} with alert context ID {alert_context_id} and asset ID {asset_id}")
541
+ logger.info(f"Creating alert for customer code {customer_code} with alert context ID {alert_context_id} and asset ID {asset.id}")
542
alert_payload.alert_id = alert_id
541
- await handle_customer_notifications(customer_code=customer_code, alert_payload=alert_payload, session=session)
543
+ await handle_customer_notifications(customer_code=customer_code, asset_name=asset.asset_name, alert_payload=alert_payload, session=session)
544
545
await add_alert_to_document(CreateAlertRequest(index_name=alert_payload.index_name, alert_id=alert_payload.index_id), alert_id)
546