Update an alert to acknowledged in mongodb when the triagebot updates its status (#1656)

This commit is contained in:
Arcadia Rose 2020-07-13 17:38:12 -04:00 коммит произвёл GitHub
Родитель ffa92efcb0
Коммит aa602f4763
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 15 добавлений и 8 удалений

Просмотреть файл

@ -579,17 +579,22 @@ def update_alert_status():
"identityConfidence": req.get("identityConfidence"), "identityConfidence": req.get("identityConfidence"),
} }
modified_count = 0 fields_to_update = {
"status": req.get("status"),
"details": details,
}
modified_count += alerts.update_one( if req.get("status") == "acknowledged":
{"esmetadata.id": req.get("alert")}, {"$set": {"status": req.get("status")}} 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
modified_count += alerts.update_one( if modified_count != 1:
{"esmetadata.id": req.get("alert")}, {"$set": {"details": details}}
).modified_count
if modified_count < 2:
response.status = StatusCode.BAD_REQUEST response.status = StatusCode.BAD_REQUEST
return {"error": "Alert not found"} return {"error": "Alert not found"}

Просмотреть файл

@ -179,6 +179,8 @@ class TestAlertStatus(RestTestSuite):
assert alert['status'] == 'acknowledged' assert alert['status'] == 'acknowledged'
assert alert['details']['triage']['user']['slack'] == 'tester' assert alert['details']['triage']['user']['slack'] == 'tester'
assert alert['details']['triage']['response'] == 'yes' assert alert['details']['triage']['response'] == 'yes'
assert 'acknowledged' in alert
assert alert['acknowledgedby'] == 'triagebot'
return return