/webhook-forwarder

Forward the webhook request

Primary LanguageGoGNU General Public License v3.0GPL-3.0

webhook-forwarder

Build Test Docker Quality Gate Status Go Report Card

Forward the webhook request.

webhook-forwarder (2)

Usage

I suppose your webhook request body looks like this:

{
  "alerts": [
    {
      "status": "resolved",
      "labels": {
        "alertname": "325i alert"
      }
    }
  ]
}

And your backend wanted:

{
  "body": "Test Bark Server",
  "title": "bleem"
}

Now you can use webhook-forwarder to receive and redirect and modify the webhook request like this:

// ~/.config/webhook-forwarder/test.js
function convert(origin) {
    alert = origin.alerts[0];
    return {
        target: ["https://api.day.app/asd/"],
        payload: {
            title: alert.labels.alertname,
            body: "",
        }
    }
};

Finally your backend will got correct body.

Replace :name with the name of the file in the templates directory.

curl -X POST http://localhost:8080/forward/:name -d '{"alerts":[{"status":"resolved","labels":{"alertname":"325i alert"}}]}'

Docker Deploy

version: '3'
services:
  webhook-forwarder:
    image: ghcr.io/bpazy/webhook-forwarder:master
    environment:
      - PORT=:8080
    restart: always
    ports:
      - "8080:8080"
    volumes:
      - /home/ubuntu/webhook-forwarder/templates:/root/.config/webhook-forwarder/templates