fix(iwooos): normalize wazuh receipt timestamps
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m27s
CD Pipeline / build-and-deploy (push) Successful in 6m55s
CD Pipeline / post-deploy-checks (push) Successful in 1m55s
All checks were successful
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 2m27s
CD Pipeline / build-and-deploy (push) Successful in 6m55s
CD Pipeline / post-deploy-checks (push) Successful in 1m55s
This commit is contained in:
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
from collections.abc import Mapping
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import text
|
||||
@@ -484,5 +484,26 @@ def _latest_receipt_at(data: Mapping[str, Any]) -> str | None:
|
||||
]
|
||||
if not values:
|
||||
return None
|
||||
latest = max(values)
|
||||
return latest.isoformat() if isinstance(latest, datetime) else str(latest)
|
||||
normalized = [
|
||||
parsed
|
||||
for value in values
|
||||
if (parsed := _utc_receipt_datetime(value)) is not None
|
||||
]
|
||||
if normalized:
|
||||
return max(normalized).isoformat()
|
||||
return max(str(value) for value in values)
|
||||
|
||||
|
||||
def _utc_receipt_datetime(value: Any) -> datetime | None:
|
||||
if isinstance(value, datetime):
|
||||
parsed = value
|
||||
elif isinstance(value, str):
|
||||
try:
|
||||
parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
||||
except ValueError:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
if parsed.tzinfo is None:
|
||||
parsed = parsed.replace(tzinfo=UTC)
|
||||
return parsed.astimezone(UTC)
|
||||
|
||||
Reference in New Issue
Block a user