← Back to Home

🔔 n8n Teams Alerts Setup Guide

Automated Microsoft Teams notifications when routers go offline

📋 What you'll learn: How to set up n8n to monitor your Cradlepoint routers and send Microsoft Teams notifications when they go offline or come back online.

Prerequisites

Step 1: Install n8n on Your Linode VM

Option A: Docker Installation (Recommended)

SSH into your Linode VM and run:

# Install Docker if not already installed
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Run n8n with Docker
docker run -it --rm \\
  --name n8n \\
  -p 5678:5678 \\
  -v ~/.n8n:/home/node/.n8n \\
  n8nio/n8n

Access n8n at: http://your-linode-ip:5678

Option B: Using n8n Cloud (Easier)

If you don't want to manage your own server:

  1. Go to n8n.cloud
  2. Sign up for a free account (includes 5,000 workflow executions/month)
  3. Create a new workflow

Step 2: Create Microsoft Teams Incoming Webhook

Setting up Teams Webhook
  1. Open Microsoft Teams and go to the channel where you want alerts
  2. Click the ••• (three dots) next to the channel name
  3. Select Connectors or Workflows
  4. Search for "Incoming Webhook"
  5. Click Add or Configure
  6. Give it a name: "Router Alerts"
  7. Upload a custom icon (optional)
  8. Click Create
  9. Copy the webhook URL - you'll need this!
⚠️ Important: Keep your webhook URL secret! Anyone with this URL can post to your Teams channel.

Step 3: Create the n8n Workflow

Building Your Monitoring Workflow

1. Add a Schedule Trigger

This will run your workflow every 5 minutes to check router status.

  1. In n8n, click the + button to add a node
  2. Search for "Schedule Trigger"
  3. Set it to run every 5 minutes

2. Add HTTP Request Node

This fetches your router data.

  1. Add a new node → HTTP Request
  2. Method: GET
  3. URL: https://api.kerchunknetworks.com/data/routers.json
  4. Click Execute Node to test

3. Add Function Node (Process Router Data)

This checks if any routers changed state.

  1. Add a new node → Function
  2. Paste this code:
// Get current router data
const currentRouters = $input.all()[0].json.routers;

// Get previous state from workflow static data (persisted between runs)
const previousState = $workflow.staticData.routerStates || {};

// Initialize if first run
if (Object.keys(previousState).length === 0) {
  currentRouters.forEach(router => {
    previousState[router.id] = router.state;
  });
  $workflow.staticData.routerStates = previousState;
  return []; // Don't send alerts on first run
}

// Check for state changes
const alerts = [];

currentRouters.forEach(router => {
  const previousRouterState = previousState[router.id];

  if (previousRouterState !== router.state) {
    alerts.push({
      name: router.name,
      id: router.id,
      previousState: previousRouterState,
      currentState: router.state,
      timestamp: new Date().toISOString()
    });

    // Update state
    previousState[router.id] = router.state;
  }
});

// Save updated state
$workflow.staticData.routerStates = previousState;

// Return alerts (if any)
return alerts.map(alert => ({ json: alert }));

4. Add Microsoft Teams Node

  1. Add a new node → HTTP Request (we'll use webhook)
  2. Method: POST
  3. URL: Your Teams Webhook URL from Step 2
  4. Headers: Content-Type: application/json
  5. Body → JSON:
{
  "@type": "MessageCard",
  "@context": "https://schema.org/extensions",
  "summary": "Router Status Alert",
  "themeColor": "{{$json.currentState === 'offline' ? 'FF0000' : '00FF00'}}",
  "title": "🚨 Router Status Change",
  "sections": [{
    "activityTitle": "{{$json.name}}",
    "activitySubtitle": "Status changed from {{$json.previousState}} to {{$json.currentState}}",
    "facts": [
      {
        "name": "Router Name:",
        "value": "{{$json.name}}"
      },
      {
        "name": "Router ID:",
        "value": "{{$json.id}}"
      },
      {
        "name": "Previous State:",
        "value": "{{$json.previousState}}"
      },
      {
        "name": "Current State:",
        "value": "{{$json.currentState}}"
      },
      {
        "name": "Time:",
        "value": "{{$json.timestamp}}"
      }
    ],
    "markdown": true
  }],
  "potentialAction": [{
    "@type": "OpenUri",
    "name": "View Dashboard",
    "targets": [{
      "os": "default",
      "uri": "https://kerchunknetworks.com/monitor.html"
    }]
  }]
}

Step 4: Test Your Workflow

Testing
  1. Click Execute Workflow in n8n
  2. Check each node for errors (green = success)
  3. On first run, no alerts should be sent (initializing state)
  4. When a router goes offline/online, you should receive a Teams notification
✅ Success! If you see a message in Teams, your workflow is working!

Step 5: Activate the Workflow

Enable Automation
  1. Save your workflow (give it a name like "Router Status Monitor")
  2. Toggle the Active switch in the top right
  3. Your workflow will now run automatically every 5 minutes

Advanced Customization

Change Alert Frequency

In the Schedule Trigger node, adjust the interval:

Add More Alert Types

You can modify the Function node to alert on:

Send Daily Status Reports

Create a second workflow with a daily schedule that sends a summary:

Troubleshooting

⚠️ Workflow not running?
⚠️ Not receiving Teams notifications?

Next Steps


Need help? Contact IT at [email protected]