From aa602f476390cbfdccebaf5e754c120d28afdc52 Mon Sep 17 00:00:00 2001 From: Arcadia Rose <682761+arcrose@users.noreply.github.com> Date: Mon, 13 Jul 2020 17:38:12 -0400 Subject: [PATCH] Update an alert to acknowledged in mongodb when the triagebot updates its status (#1656) --- rest/index.py | 21 +++++++++++++-------- tests/rest/test_rest_index.py | 2 ++ 2 files changed, 15 insertions(+), 8 deletions(-) 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