Auto-Triage Security Incidents in n8n with GPT-4o-mini and Gmail Alerts
Security Hub alert → Webhook ingestion → field normalization → LLM classification & severity → LLM remediation plan → Gmail HTML brief
- Who
- SOC or cloud ops staff who need to auto-grade AWS Security Hub-style alerts and notify owners
- You get
- An automated HTML email brief with incident type, severity (P0–P3), urgency, a 3-step remediation plan, and owner hint
Constraints
Prerequisites: a publicly reachable n8n instance; OpenAI API credentials (openAiApi) and Gmail OAuth2 credentials (gmailOAuth2) configured in n8n. Input is Security-Hub-style JSON (detail.findings array). Costs are mainly OpenAI tokens and n8n hosting; Gmail can be swapped for SMTP or another channel. Estimated setup time: ~10–15 minutes.
What they did
Author ca7ai published an n8n template (5 functional nodes plus 2 sticky notes) that automates security alert handling. The workflow ingests AWS Security Hub-style JSON alerts via Webhook, extracts key fields through an Edit Fields node, then passes them through two gpt-4o-mini nodes for classification (incident_type, severity P0–P3, urgency, short_title, why) and 3-step remediation planning (next_actions, owner_hint, success_criteria), finally sending an HTML brief via Gmail. Template sticky notes provide a curl test example and the email subject format.
How it went
The author reports ~10–15 minutes setup time and Beginner–Intermediate difficulty (author_report). The template page shows 322 views. No throughput, latency, or production runtime data is provided.
Worth knowing
1) No measured runtime data from the author; this site has not reproduced the workflow (reproduction=not_tested). 2) The Webhook node requires a publicly reachable n8n instance; use a reverse proxy or tunnel if running internally. 3) The Gmail node can be replaced with SMTP or another channel (Teams/Slack), but the template does not include specific swap instructions. 4) Both LLM nodes require strict JSON output; enable JSON Output and validate schema during testing. 5) The Plan node's User Message uses n8n node-reference expressions—update them if node names change. 6) Credentials (openAiApi, gmailOAuth2) should be stored in n8n Credentials, never hard-coded.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- Classify node: connect OpenAI API credentials.
- Send a message node: connect Gmail OAuth2 credentials.
- Plan node: connect OpenAI API credentials.
Configuration to replace
- Source template is n8n public workflow #7785 (~7 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-24
Steps
Configure the Webhook trigger and test entrypoint
Add a Webhook node in n8n, set HTTP Method to POST and Path to mini-triage. Save and copy the Webhook URL. Use the curl below to send a test payload and confirm the workflow triggers.
Setup guidance · Source text。Sticky Note next to Webhook node; test entrypoint example
📥 ENTRY Send a POST to /mini-triage to get started! Example: curl -X POST "$YOUR_WEBHOOK_URL" \ -H "Content-Type: application/json" \ -d '{ "detail": { "findings": [{ "Title": "Multiple failed logins", "Description": "probable credential stuffing", "AwsAccountId": "111111111111", "Resources": [{ "Id": "user:[email protected]", "Type": "AwsIamUser" }] }] } }'Normalize alert fields (Clean_Finding)
Add an Edit Fields (Set) node named Clean_Finding. Map the following fields from body.detail.findings[0]: Title, Description, account_id (AwsAccountId), resource_id (Resources[0].Id), resource_type (Resources[0].Type), updated_at (UpdatedAt or current time). These fields feed the downstream LLM nodes.
LLM classification and severity (Classify)
Add an OpenAI node named Classify, select model gpt-4o-mini, set temperature to 0.2, and enable JSON Output. Paste the following system prompt to enforce strict JSON output with incident_type, severity, urgency, short_title, and why.
Execution prompt · Source text。Classify node System Message field
You are the SOC Classifier. Output VALID JSON only with keys: { "incident_type": "creds|malware|network|data|cloud|other", "severity": "P0|P1|P2|P3", "urgency": "now|today|this_week", "short_title": "≤12 words", "why": "≤50 words" } Rules: - Prefer "cloud" if resource_type looks like cloud infra (e.g., AwsS3Bucket, SecurityGroup, IAM). - If title contains "public", "exposed", "leak" → data|cloud depending on resource. - If unclear, return "other" and P3, but try to use title/description before giving up. - Be conservative with P0. Examples: Input: {"title":"S3 bucket public READ","description":"ACL allows public READ","resource_type":"AwsS3Bucket"} Output: {"incident_type":"cloud","severity":"P2","urgency":"today","short_title":"Public S3 read","why":"Public READ on bucket risks data exposure."} Input: {"title":"Multiple failed logins","description":"probable credential stuffing"} Output: {"incident_type":"creds","severity":"P2","urgency":"today","short_title":"Credential stuffing suspected","why":"Repeated failures indicate attack; monitor & protect accounts."}LLM remediation planning (Plan)
Add a second OpenAI node named Plan, again using gpt-4o-mini with temperature 0.2 and JSON Output enabled. The System Message defines the remediation JSON schema; the User Message references Classify output and original Webhook data via n8n expressions.
Execution prompt · Source text。Plan node System Message field
You are the Remediation Planner. Based on the classifier output and original finding, return VALID JSON: { "next_actions": ["step 1", "step 2", "step 3"], "owner_hint": "who should act first (e.g., Cloud On-Call, IAM, EDR)", "success_criteria": "what proves it's resolved" } Keep it to 3 atomic steps max. No speculation.Execution prompt · Source text。Plan node User Message field; n8n expression evaluated at runtime
=Classifier: ```json {{$node["Classify"].json}} {{$node["Webhook"].json}}Send HTML email brief (Gmail)
Add a Gmail node named Send a message. Set the recipient address. Use the following n8n expressions for Subject and Message to dynamically assemble classification results and the remediation plan. Select the pre-configured gmailOAuth2 credential.
Execution prompt · Source text。Gmail node Message field (HTML email body)
=<h3> {{ $('Classify').item.json.message.content.short_title }} ({{ $('Classify').item.json.message.content.severity }}) </h3> <p> <b>Type:</b> {{ $('Classify').item.json.message.content.incident_type }} | <b>Resource Name:</b> {{ $('Clean_Finding').item.json.resource_id }} </p> <p> <b>Account:</b> {{ $('Clean_Finding').item.json.account_id }} </p> <p> <b>Urgency:</b> {{ $('Classify').item.json.message.content.urgency }} </p> <p> <b>Why:</b> {{ $('Classify').item.json.message.content.why }} </p> <p><b>Next Actions</b></p> <ol> <li>{{ $json.message.content.next_actions[0] }}</li> <li>{{ $json.message.content.next_actions[1] }}</li> <li>{{ $json.message.content.next_actions[2] }}</li> </ol> <p> <b>Owner:</b> {{ $json.message.content.owner_hint }} <br/> <b>Success:</b> {{ $json.message.content.success_criteria }} </p>Execution prompt · Source text。Gmail node Subject field
={{ $('Classify').item.json.message.content.short_title }}- {{ $('Clean_Finding').item.json.resource_id }} in {{ $('Clean_Finding').item.json.account_id }}
Prompt you can copy
Setup guidance · Editorial suggestion。Hand to a setup assistant to confirm inputs and permissions, then validate each node step by step
This block is the prompt. Ads are never placed here.
You are setting up n8n template 7785 for automated security incident triage. Confirm in order: 1) n8n is publicly reachable; 2) OpenAI and Gmail credentials are created; 3) import workflow.json or build nodes manually; 4) send a test curl to /mini-triage and verify outputs from Webhook, Classify, Plan, and Gmail before connecting real Security Hub traffic.
Run the curl test first, then switch to production traffic. Keep credentials in n8n Credentials, never hard-code them into nodes.
Source
Automate security incident triage with GPT-4o-mini and Gmail notifications · ca7ai · n8n.io · 2025-08-24
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.