This workflow efficiently processes logs to detect anomalies.
Scheduled Check (Cron Node): This is the primary trigger. It schedules the workflow to run at a defined interval (e.g., every 15 minutes), ensuring logs are routinely scanned for suspicious activity.
Fetch Logs (HTTP Request Node): This node is responsible for retrieving logs from an external source. It sends a request to your log API endpoint to get a batch of the most recent logs.
Count Failed Logins (Code Node): This is the core of the detection logic. The JavaScript code filters the logs for a specific event ("login_failure"
), counts the total, and identifies unique IPs involved. This information is then passed to the next node.
Failed Logins > Threshold? (If Node): This node serves as the final filter. It checks if the number of failed logins exceeds a threshold you set (e.g., more than 5 attempts). If it does, the workflow is routed to the notification node; if not, the workflow ends safely.
Send Anomaly Alert (Slack Node): This node sends an alert to your team if an anomaly is detected. The Slack message includes a summary of the anomaly, such as the number of failed attempts and the IPs involved, enabling a swift response.
Implementing this essential log anomaly detector in your n8n instance is quick and straightforward.
Prepare Your Credentials & API:
#security-alerts
).Import the Workflow JSON:
Configure the Nodes:
log.event === 'login_failure'
if your log events use a different name.5
) based on your risk tolerance.Test and Activate:
0
to ensure the alert is triggered.