diff --git a/rest/index.py b/rest/index.py index bdc0df6d..0a0bf2e0 100644 --- a/rest/index.py +++ b/rest/index.py @@ -579,17 +579,22 @@ def update_alert_status(): "identityConfidence": req.get("identityConfidence"), } - modified_count = 0 + fields_to_update = { + "status": req.get("status"), + "details": details, + } - modified_count += alerts.update_one( - {"esmetadata.id": req.get("alert")}, {"$set": {"status": req.get("status")}} + if req.get("status") == "acknowledged": + fields_to_update.update({ + "acknowledged": toUTC(datetime.utcnow()), + "acknowledgedby": "triagebot", + }) + + modified_count = alerts.update_one( + {"esmetadata.id": req.get("alert")}, {"$set": fields_to_update} ).modified_count - modified_count += alerts.update_one( - {"esmetadata.id": req.get("alert")}, {"$set": {"details": details}} - ).modified_count - - if modified_count < 2: + if modified_count != 1: response.status = StatusCode.BAD_REQUEST return {"error": "Alert not found"} diff --git a/tests/rest/test_rest_index.py b/tests/rest/test_rest_index.py index 2426c5e3..0fa701de 100644 --- a/tests/rest/test_rest_index.py +++ b/tests/rest/test_rest_index.py @@ -179,6 +179,8 @@ class TestAlertStatus(RestTestSuite): assert alert['status'] == 'acknowledged' assert alert['details']['triage']['user']['slack'] == 'tester' assert alert['details']['triage']['response'] == 'yes' + assert 'acknowledged' in alert + assert alert['acknowledgedby'] == 'triagebot' return