How to Create Auto-Alerts for Breached SLAs with n8n

admin1234 Avatar

## Introduction

In operations management, maintaining service level agreements (SLAs) is critical for customer satisfaction and regulatory compliance. Breached SLAs can result in penalties, damaged reputation, or loss of customers. Manually tracking SLA compliance across teams and projects is time-consuming and error-prone.

This tutorial explains how to build an automated workflow with n8n—an open-source workflow automation tool—that detects SLA breaches and sends timely alerts to relevant stakeholders. Operations teams and automation engineers will benefit from this guide by reducing manual overhead, increasing responsiveness, and improving SLA compliance.

## Tools and Services Used

– **n8n**: Core automation platform to orchestrate the workflow.
– **Google Sheets**: To store and track ticket or task data including SLA deadlines.
– **Slack**: To send alert messages to operations or support teams.
– **Email (SMTP)**: Optional alternative notification channel.

This example assumes your SLA data is maintained in Google Sheets with key columns like Ticket ID, Assigned Team, SLA Due Date, and Status.

## Problem Statement

Operations receive hundreds or thousands of tickets/tasks daily, each with an SLA due date. It’s challenging to monitor which tickets are approaching or have breached their SLAs manually.

An automated alert system that:

– Periodically checks active tickets.
– Detects breached or nearly breached SLAs.
– Notifies the right teams via Slack and/or Email.

will significantly improve response times and reduce SLA violations.

## Workflow Overview

The workflow triggers on a schedule (e.g., every 15 minutes) and:

1. Queries Google Sheets for all tickets with an upcoming or past SLA due date and status not marked as completed.
2. Compares the current time against SLA due dates.
3. Filters tickets with breached or approaching SLA breaches (customizable thresholds like SLA due in less than 30 minutes or already past).
4. Sends alerts containing ticket details to Slack channels and optionally email addresses.

## Step-By-Step Technical Tutorial

### 1. Set Up Your Google Sheet

Create a Google Sheet with columns:

| Ticket ID | Assigned Team | SLA Due Date | Status |
|———–|—————|————–|——–|
| 12345 | Support | 2024-06-15T14:00:00Z | Open |

SLA Due Date must be in ISO-8601 UTC timestamp format for consistency.

### 2. Create n8n Workflow and Add the Trigger Node

– Add a **Cron** node in n8n.
– Configure it to run every 15 minutes (or any preferred frequency).

### 3. Add Google Sheets Node to Retrieve SLA Data

– Add a **Google Sheets** node.
– Connect it to the Cron node.
– Configure authentication with your Google account.
– Set the action to “Read Rows” from the sheet that contains your ticket data.

### 4. Add a Function Node to Filter Relevant Tickets

– Add a **Function** node connected to Google Sheets node.
– Use this JavaScript code to filter tickets where:
– Status is not ‘Completed’ or ‘Closed’
– SLA Due Date is less than current time + threshold (e.g., 30 minutes for warnings)
– Or SLA Due Date is already passed (breached)

“`javascript
const now = new Date();
const warningThresholdMinutes = 30;

return items.filter(item => {
const status = item.json[‘Status’].toLowerCase();
if (status === ‘completed’ || status === ‘closed’) return false;

const slaDue = new Date(item.json[‘SLA Due Date’]);

const timeDiffMinutes = (slaDue – now) / 60000; // minutes

// Return tickets breaching SLA or nearing breach
return timeDiffMinutes <= warningThresholdMinutes; }); ``` --- ### 5. Add Slack Node to Send Alerts - Add a **Slack** node connected to the Function node. - Configure with your Slack workspace credentials. - Set action to “Post Message”. - Choose the channel relevant to the Assigned Team or operations channel. - Customize message with details: ```text 🚨 SLA Alert for Ticket {{ $json["Ticket ID"] }} Status: {{ $json["Status"] }} SLA Due: {{ $json["SLA Due Date"] }} Assigned Team: {{ $json["Assigned Team"] }} Please prioritize accordingly. ``` --- ### 6. Optional: Add SMTP Email Node - Add an SMTP node connected to the Function node. - Send email to assigned team emails or operations managers. - Format the email with the same ticket information. --- ### 7. Test Your Workflow - Run the workflow manually to verify it correctly identifies tickets and sends alerts. - Adjust the warning threshold or filtering as needed. --- ## Common Errors and Tips for Robustness - **Timestamp format mismatch**: Ensure SLA Due Dates use ISO-8601 UTC format. Local timezones may cause incorrect comparisons. - **Handling empty rows or malformed data**: Add additional validation in Function node to skip rows with missing SLA dates or status. - **Slack rate limits**: If alerting many tickets simultaneously, batch messages or add delays to avoid rate limits. - **Avoid duplicate alerts**: Implement state tracking via a database or Google Sheets column (e.g., Alert Sent) to avoid repeated alerts for the same ticket. - **Timezone considerations**: Standardize all times in UTC or convert to a single timezone before comparison. --- ## Scaling and Adaptation - **Integrate with other ticketing platforms** such as Jira, Zendesk, or HubSpot instead of Google Sheets using their APIs. - **Add escalation logic** to notify higher management if SLA breaches persist. - **Customize notification channels**: SMS notifications, Microsoft Teams, or PagerDuty. - **Dashboard Integration**: Visualize SLA status on dashboards by integrating with tools like Grafana or Google Data Studio. --- ## Summary and Bonus Tip Automating SLA breach alerts with n8n frees operations teams from manual tracking, ensuring rapid response and helping meet business commitments. **Bonus Tip:** To further optimize, enrich alerts with direct ticket links or next-step suggestions using conditional logic in n8n, empowering your team to resolve issues faster.