Fix always-empty timestamp in IOC extraction report

generate_ioc_report()'s "generated" field used:
    datetime.utcnow().isoformat() if "datetime" in dir() else ""

"datetime" is never imported anywhere in this file, and dir() with
no arguments only inspects local scope names -- so this guard is
always False, and every generated report had "generated": "" instead
of a real timestamp.

Fixed by importing datetime/timezone at the top and calling
datetime.now(timezone.utc).isoformat() directly (the non-deprecated
replacement for utcnow(), since Python 3.12 deprecates utcnow()).

Tested: python3 -m py_compile, --help works, and:
    python3 agent.py report --file <any file>
now produces a real ISO 8601 UTC timestamp
(e.g. "2026-07-17T14:46:03.178652+00:00") instead of an empty string.
This commit is contained in:
Syed Farhan Ahmed
2026-07-17 19:46:11 +05:00
parent 673da1f3b0
commit a134047328
@@ -5,6 +5,7 @@ import json
import argparse
import re
import hashlib
from datetime import datetime, timezone
from pathlib import Path
@@ -102,7 +103,7 @@ def generate_ioc_report(file_path, output=None):
hashes = hash_file(file_path)
strings = extract_strings(file_path)
report = {
"generated": datetime.utcnow().isoformat() if "datetime" in dir() else "",
"generated": datetime.now(timezone.utc).isoformat(),
"file_info": hashes,
"strings_analysis": {
"total": strings["total_strings"],