Security Engineering & Cloud Security Agents
Problem Statement
After resolving a major security incident, incident response leads must gather unstructured timeline evidence from Slack messages, PagerDuty alerts, EDR telemetry logs, and forensic notes to write a detailed Post-Mortem / Incident Review Document. Manually piecing together disparate timestamps into a coherent chronological timeline takes days.
Goal
Build an AI agent that processes multi-source operational event logs, extracts key incident events, normalizes timestamps, and outputs a formatted Post-Mortem report.
Outcome Measurement
- Timeline Construction Time: Reduced post-mortem draft generation time from 8 hours to < 5 minutes.
- Timeline Accuracy: Zero timestamp ordering errors on chronologically aggregated log streams.
How the Code was Built
The script ingests raw log strings from diverse tools, parses timestamp metadata into standardized ISO 8601 formatting, orders events sequentially, and invokes an LLM structured synthesis chain.
Executable Code
from typing import Listfrom pydantic import BaseModel, Fieldfrom langchain_openai import ChatOpenAIclass TimelineEvent(BaseModel): timestamp_utc: str = Field(description="ISO8601 Timestamp") source: str = Field(description="EDR, Slack, CloudTrail, PagerDuty, etc.") summary: str = Field(description="Brief event summary")class PostMortemReport(BaseModel): incident_title: str root_cause: str chronological_timeline: List[TimelineEvent] lessons_learned: List[str]def generate_post_mortem(raw_logs: List[str]) -> PostMortemReport: llm = ChatOpenAI(model="gpt-4o", temperature=0) structured_llm = llm.with_structured_output(PostMortemReport) prompt = f"""Synthesize an Incident Post-Mortem Report from these raw incident log entries:{chr(10).join(raw_logs)}Order events strictly chronologically.""" return structured_llm.invoke(prompt)if __name__ == "__main__": logs = [ "[2026-03-31 10:14:02 UTC] EDR Alert: Suspicious credential dump process detected on host DB-PROD-01", "[2026-03-31 10:15:30 UTC] PagerDuty: High Severity Alert triggered - DB-PROD-01 compromise indicator", "[2026-03-31 10:18:00 UTC] Slack #sec-ops (Analyst Alice): Isolated DB-PROD-01 from network via CrowdStrike API", "[2026-03-31 10:25:00 UTC] Slack #sec-ops (Analyst Bob): Confirmed containment. Attacker utilized compromised service key." ] report = generate_post_mortem(logs) print(f"Incident Title: {report.incident_title}") print(f"Root Cause: {report.root_cause}\n") print("Chronological Timeline:") for event in report.chronological_timeline: print(f" [{event.timestamp_utc}] ({event.source}): {event.summary}") print("\nLessons Learned:") for lesson in report.lessons_learned: print(f" - {lesson}")






Leave a Reply