|
| 1 | +import contextlib |
1 | 2 | import csv
|
2 | 3 | import io
|
3 | 4 | import json
|
4 | 5 | import logging
|
5 | 6 | import sys
|
| 7 | +from datetime import datetime |
6 | 8 |
|
7 | 9 | from dateutil import parser as date_parser
|
8 | 10 |
|
@@ -57,6 +59,35 @@ def parse_findings(self, test: Test, reader: csv.DictReader) -> list[Finding]:
|
57 | 59 | mitigation = row.get("Remediation Recommendation")
|
58 | 60 | description = ""
|
59 | 61 | status_dict = WizcliParsers.convert_status(row.get("Status", None))
|
| 62 | + if status_dict.get("is_mitigated", False): |
| 63 | + # If the finding is mitigated, set the date to the mitigation date |
| 64 | + mitigated_timestamp = None |
| 65 | + |
| 66 | + if row.get("Resolved Time", None): |
| 67 | + with contextlib.suppress(ValueError): |
| 68 | + mitigated_timestamp = date_parser.parse(row.get("Resolved Time")) |
| 69 | + |
| 70 | + if not mitigated_timestamp: |
| 71 | + # other timestamps in the wiz scans are ISO8601 |
| 72 | + # but the Resolved Time is in a different format based on data we've seen |
| 73 | + # example value: 2025-04-03 20:20:00.43042 +0000 UTC |
| 74 | + |
| 75 | + resolved_time_string = row.get("Resolved Time") |
| 76 | + # need to use suppress as try-except ValueError doesn't work here for some reason |
| 77 | + |
| 78 | + # File "/usr/local/lib/python3.11/_strptime.py", line 352, in _strptime |
| 79 | + # raise ValueError("unconverted data remains: %s" % |
| 80 | + # ValueError: unconverted data remains: CET |
| 81 | + with contextlib.suppress(ValueError): |
| 82 | + mitigated_timestamp = datetime.strptime( |
| 83 | + resolved_time_string, "%Y-%m-%d %H:%M:%S.%f %z %Z", |
| 84 | + ) |
| 85 | + |
| 86 | + if not mitigated_timestamp: |
| 87 | + logger.warning(f"Unable to parse Resolved Time: {resolved_time_string}") |
| 88 | + |
| 89 | + status_dict["mitigated"] = mitigated_timestamp |
| 90 | + |
60 | 91 | # Iterate over the description fields to create the description
|
61 | 92 | for field in description_fields:
|
62 | 93 | if (field_value := row.get(field)) is not None and len(field_value) > 0:
|
|
0 commit comments