Alerting & Security

Webhooks & HMAC Verification

Logix continuously evaluates threshold rules. When conditions trigger, payload events are signed using HMAC-SHA256 and POSTed to your webhook URL.

Webhook Verification Route

Verify the signature using logger.verifyWebhook() to confirm the payload originated from Logix:

// app/api/webhooks/logix-alerts/route.ts
import { NextResponse } from 'next/server';
import { logger } from '@/lib/logger';

export async function POST(req: Request) {
  const body = await req.json();
  const signature = req.headers.get('x-signature') || '';
  const timestamp = req.headers.get('x-timestamp') || '';

  const { valid, error } = await logger.verifyWebhook({
    signature,
    timestamp,
    body,
  });

  if (!valid) {
    return NextResponse.json({ error: `Invalid signature: ${error}` }, { status: 401 });
  }

  // Handle verified alert event
  console.log('Verified Logix Alert:', body);
  return NextResponse.json({ received: true });
}