How to Create Auto-Alerts for Breached SLAs with n8n

admin1234 Avatar

## Introduction

Service Level Agreements (SLAs) are critical for Operations teams to ensure that customer commitments are met consistently. Breaching SLAs can lead to dissatisfied customers, financial penalties, and loss of reputation. Automating alerts for SLA breaches allows teams to react proactively and maintain high service standards.

In this guide, we will build a robust automation workflow using n8n, an open-source workflow automation tool, to auto-alert Operations teams of breached SLAs in real-time. The workflow will integrate with Google Sheets (for SLA tracking), Gmail (for email alerts), and Slack (for team notifications). This solution benefits Operations managers, support teams, and automation engineers tasked with SLA oversight.

## What the Automation Solves

Manually tracking SLAs from support tickets or work orders can be error-prone and slow. This automation continuously monitors SLA data stored in Google Sheets, detects breaches, and instantly notifies the relevant stakeholders via email and Slack. It helps teams stay ahead of issues and uphold service quality.

## Prerequisites

– n8n account or self-hosted instance
– Google account with access to Google Sheets
– Gmail account for sending alert emails
– Slack workspace with an incoming webhook set up

## Step-by-Step Technical Tutorial

### Step 1: Prepare SLA Data in Google Sheets

1. Create a Google Sheet named “SLA Monitoring” with columns:
– Ticket ID
– Customer Name
– SLA Due Date (ISO 8601 format, e.g. 2024-06-30T17:00:00Z)
– Status (e.g., Open, Closed)
– Assigned Team
– Alert Sent (Boolean: TRUE or FALSE)

2. Populate the sheet with current ticket SLA data.

### Step 2: Setup Google Sheets Credentials in n8n

1. In n8n, navigate to **Credentials** and add new **Google API** credentials with access to Google Sheets.
2. Ensure the account has edit/read permissions on the “SLA Monitoring” Sheet.

### Step 3: Build the Workflow in n8n

#### Workflow Trigger: Schedule Trigger

– Add a **Schedule Trigger** node.
– Configure it to run every 15 minutes (or frequency that matches your SLA sensitivity).

#### Step 4: Read SLA Data from Google Sheets

– Add a **Google Sheets** node.
– Set operation to **Read Rows**.
– Choose the “SLA Monitoring” spreadsheet and sheet tab.
– Set the range to cover all rows with tickets.
– This node fetches current SLA statuses.

#### Step 5: Filter Breached SLAs

– Add a **Function** node to process the rows and detect breaches.

Example JavaScript code for filtering:

“`javascript
const currentTime = new Date();

return items.filter(item => {
const slaDueDate = new Date(item.json[‘SLA Due Date’]);
const status = item.json[‘Status’];
const alertSent = item.json[‘Alert Sent’];
// Condition: SLA due date passed, ticket still open, and alert not sent
return slaDueDate < currentTime && status !== 'Closed' && alertSent !== true; }); ``` This filters tickets with breached SLAs that have not yet been alerted. #### Step 6: Send Alert Emails via Gmail - Add a **Gmail** node. - Operation: **Send Email**. - Automate recipient address(es) based on 'Assigned Team' or static addresses. - Use expressions to customize subject and body, e.g.: Subject: "[ALERT] SLA Breach for Ticket {{$json["Ticket ID"]}}" Body: ``` Ticket ID: {{$json["Ticket ID"]}} Customer: {{$json["Customer Name"]}} SLA Due Date: {{$json["SLA Due Date"]}} Status: {{$json["Status"]}} Action Required Immediately. ``` Configure the Gmail node to send one email per breached ticket. #### Step 7: Send Slack Notification - Add an **HTTP Request** node to send a Slack message via webhook. - Method: POST - URL: Your Slack Incoming Webhook URL - Body: ``` { "text": "*SLA Breach Alert!*\nTicket ID: {{$json["Ticket ID"]}}\nCustomer: {{$json["Customer Name"]}}\nDue Date: {{$json["SLA Due Date"]}}\nStatus: {{$json["Status"]}} - Please address immediately." } ``` - Headers: `Content-Type: application/json` #### Step 8: Update Google Sheets to Mark Alert Sent - Add another **Google Sheets** node. - Operation: **Update Row** - For each alerted ticket, update the 'Alert Sent' column to TRUE. - Use the Ticket ID or row index for locating the correct row. --- ### Step 9: Connect Nodes - Link **Schedule Trigger** node to **Google Sheets (Read Rows)** node. - Connect to the **Function** node (filtering breaches). - Use a **SplitInBatches** node (optional) if many breached SLAs expected for parallel processing. - For each filtered item, connect to **Gmail** and **HTTP Request (Slack)** nodes to send alerts. - Then connect to **Google Sheets (Update Row)** node to mark alerts sent. --- ## Common Errors and Tips - **Google API Permissions:** Ensure n8n credentials have proper access to Sheets and Gmail. - **Date Parsing:** Use consistent date formats; ISO 8601 is recommended. - **Duplicate Alerts:** The 'Alert Sent' flag prevents re-alerting on the same SLA breach. - **Slack Webhook:** Verify webhook URL and test with a sample payload. - **Batch Processing:** For large data sets, use batch processing to avoid timeout. --- ## Adapting and Scaling the Workflow - **Dynamic Recipients:** Integrate with your CRM or team directory for dynamic email/Slack user mapping. - **Multiple SLA Levels:** Add logic to handle different SLA tiers and thresholds. - **Visual Dashboards:** Combine with Google Data Studio or n8n’s internal reporting for SLA breach trends. - **Additional Channels:** Extend alerts to SMS via Twilio, Microsoft Teams, or PagerDuty. - **Error Handling:** Add error workflows in n8n to retry failed nodes or alert admins. --- ## Summary By building this n8n workflow, Operations teams gain a proactive alerting mechanism for SLA breaches, enabling faster remediation and better customer experience. Leveraging Google Sheets as a data source, Gmail and Slack for alerts, this automation is scalable, customizable, and easy to maintain. Implementing such workflows saves time, reduces manual tracking errors, and enhances accountability. --- ## Bonus Tip: Using Webhooks for Real-Time SLA Monitoring If your SLA data originates from a ticketing system or CRM that supports webhooks, you can further improve this workflow by triggering it via webhook events instead of polling Google Sheets. This reduces latency and resource usage. Configure the source system to send SLA updates to the n8n Webhook node. Then adapt the workflow to process incoming tickets immediately, sending alerts without waiting for schedule runs. This real-time approach is ideal for high-velocity environments where SLA adherence is mission-critical.