Guides / n8n

Change-only alerts in n8n: snapshot, compare, and stay quiet when nothing moved

Intermediate, 9 min read,

An alert that fires every run gets muted by day three. What you want is a workflow that stays silent while things stay the same, and speaks up the moment something moves. The trick is a snapshot: remember what you saw last time, compare, and alert only on the difference.

The example watches the public GitHub status page and tells you when a component's status changes. The same pattern watches anything that comes back as a list with IDs: users in a group, open tickets, prices, a team roster.

ScheduleEvery 5 min
Data TableGet snapshot
HTTP RequestFetch status
CodeCompare
HTTP RequestPost alert
CodeRows to save
Data TableSave snapshot

The four rules

  1. Compare on stable IDs, never names. Names get renamed, reformatted and repeated. IDs don't.
  2. Compare only the fields that mean something. Leave out timestamps and counters, or every run is a "change".
  3. The first run reports what's already wrong. A baseline that stays silent hides the problems that existed before you started watching.
  4. A bad fetch is not "everything disappeared". If too much vanishes at once, warn and keep the old snapshot.

1. Create the snapshot table

Create a Data Table called snapshots with four string columns: watch, item_id, name and status. One row per item you watch. The watch column lets one table serve every watcher you build.

One row per item, not one big JSON blob, because you can read it, sort it, and edit a single row by hand to test the workflow.

2. Build the workflow

Schedule Trigger: Every 5 min

Match the interval to how fast the thing you watch changes, and to how fast you need to know.

Data Table: Get snapshot

Operation Get, table snapshots, one condition: watch Equals github-status. Turn on Return All. In Settings, turn on Always Output Data, so the very first run, with an empty table, still continues.

HTTP Request: Fetch status

GET https://www.githubstatus.com/api/v2/components.json. In Settings, turn on Execute Once.

This one matters. Get snapshot outputs one item per row, and n8n runs the next node once per item. Without Execute Once, twelve rows mean twelve identical calls.

Code: Compare

Run Once for All Items mode:

const WATCH = 'github-status';
const LABELS = {
  operational: 'operational',
  degraded_performance: 'degraded',
  partial_outage: 'partial outage',
  major_outage: 'major outage',
  under_maintenance: 'maintenance',
};
const label = s => LABELS[s] || s;

// Last snapshot. The empty item from Always Output Data has no item_id.
const prevRows = $('Get snapshot').all().map(i => i.json)
  .filter(r => r.item_id && r.status !== 'removed');
const prev = new Map(prevRows.map(r => [r.item_id, r]));

// What the source says now, cut down to the fields worth comparing.
const current = ($input.first().json.components || [])
  .filter(c => !c.group)
  .map(c => ({ watch: WATCH, item_id: c.id, name: c.name, status: c.status }));
const now = new Map(current.map(r => [r.item_id, r]));

const removed = prevRows.filter(r => !now.has(r.item_id));

// Safety stop: an empty or half-empty answer is a bad fetch, not mass removal.
if (current.length === 0 || removed.length > Math.max(2, prev.size / 2)) {
  return [{ json: {
    notify: true,
    text: `Status watch: ${removed.length} of ${prev.size} items missing from the answer. Snapshot kept. Check the source.`,
    rows: [],
  } }];
}

// First run: say what you're watching, and what's already wrong.
if (prev.size === 0) {
  const notOk = current.filter(r => r.status !== 'operational');
  const lines = notOk.map(r => `${r.name}: ${label(r.status)}`);
  return [{ json: {
    notify: true,
    text: `Now watching ${current.length} components.` +
      (lines.length ? `\nAlready not operational:\n${lines.join('\n')}` : ' All operational.'),
    rows: current,
  } }];
}

const lines = [];
for (const r of current) {
  const old = prev.get(r.item_id);
  if (!old) lines.push(`New: ${r.name} (${label(r.status)})`);
  else if (old.status !== r.status) lines.push(`${r.name}: ${label(old.status)} -> ${label(r.status)}`);
  else if (old.name !== r.name) lines.push(`Renamed: ${old.name} -> ${r.name}`);
}
for (const r of removed) lines.push(`Gone: ${r.name}`);

return [{ json: {
  notify: lines.length > 0,
  text: `Status changes:\n${lines.join('\n')}`,
  rows: [...current, ...removed.map(r => ({ ...r, status: 'removed' }))],
} }];

Items that disappear are kept as removed instead of deleted. You see when they left, they don't alert twice, and if one comes back it shows up as new.

IF: Anything to say?

Condition: {{ $json.notify }}, Boolean, is true. Connect only the true output. When nothing changed, the run simply ends, with nothing posted and nothing written.

HTTP Request: Post alert

Post {{ $json.text }} to your chat webhook, as in the error workflow guide.

Filter: Production only

Condition: {{ $execution.mode }} is equal to production. Test runs in the editor stop here and never touch the snapshot. The polling guide explains why this guard matters.

Code: Rows to save

return $('Compare').first().json.rows.map(row => ({ json: row }));

One item per row to write. After a safety stop, rows is empty, no items come out, and the old snapshot stays exactly as it was.

Data Table: Save snapshot

Operation Upsert, table snapshots, Must Match All Conditions: watch Equals {{ $json.watch }} and item_id Equals {{ $json.item_id }}. Under Values to upsert, Map Each Column Manually: set all four columns from $json, including watch and item_id. The conditions only find a row. A new row gets only the values you map.

Set an error workflow in the workflow settings and publish. A failed fetch now alerts you through the error workflow and leaves the snapshot alone.

3. Test it by editing the snapshot

Real changes are rare, so make your own. Manual runs never save, so you can repeat each test as often as you like.

  1. Publish and let one scheduled run create the baseline. You get the "Now watching" message.
  2. Unpublish, so a scheduled run doesn't save over your edits before you test them. In the table, change one row's status to major_outage. Run by hand: Compare reports it going back to operational.
  3. Delete a row: the next manual run reports it as new. Add a row with a made-up item_id: it reports it as gone.
  4. Publish again and let the next scheduled run save the changes, then check that the run after that is quiet. Delete the made-up row afterwards: it stays in the table as removed.

Use Execute workflow for these tests, not Execute step. A single step reuses the cached output of the nodes before it, so it doesn't see your table edits.

The traps

Why it's built this way