pushbits / server

A simple server for push notifications via Matrix (and a minimalistic alternative to Pushover and Gotify) 🚀📯
https://www.pushbits.io
ISC License
314 stars 18 forks source link

Add an altermanager compatible interface #52

Closed CubicrootXYZ closed 2 years ago

CubicrootXYZ commented 2 years ago

This PR adds a new endpoint at /alert that is compatible with the alertmanager webhook. Thus alerts can now be send directly to a pushbits channel without any third party involved.

eikendev commented 2 years ago

This is a great addition! Happy for you to let me know once this is ready for review.

eikendev commented 2 years ago

Thanks @CubicrootXYZ, will take a look on the weekend. How do I best test this, assuming I don't have a running Prometheus instance?

CubicrootXYZ commented 2 years ago

Thanks @CubicrootXYZ, will take a look on the weekend. How do I best test this, assuming I don't have a running Prometheus instance?

I used the built in alertmanager in grafana, this is the test notification from there:

{
  "receiver": "",
  "status": "firing",
  "alerts": [
    {
      "status": "firing",
      "labels": {
        "alertname": "TestAlert",
        "instance": "Grafana"
      },
      "annotations": {
        "summary": "Notification test"
      },
      "startsAt": "2022-04-22T19:56:18.965287262Z",
      "endsAt": "0001-01-01T00:00:00Z",
      "generatorURL": "",
      "fingerprint": "57c6d9296de2ad39",
      "silenceURL": "http://localhost:3000/alerting/silence/new?alertmanager=grafana&matchers=alertname%3DTestAlert%2Cinstance%3DGrafana",
      "dashboardURL": "",
      "panelURL": "",
      "valueString": "[ metric='foo' labels={instance=bar} value=10 ]"
    }
  ],
  "groupLabels": {},
  "commonLabels": {
    "alertname": "TestAlert",
    "instance": "Grafana"
  },
  "commonAnnotations": {
    "summary": "Notification test"
  },
  "externalURL": "http://localhost:3000/",
  "version": "1",
  "groupKey": "{alertname=\"TestAlert\", instance=\"Grafana\"}2022-04-22 19:56:18.965287262 +0000 UTC m=+174143.108334255",
  "truncatedAlerts": 0,
  "orgId": 1,
  "title": "[FIRING:1]  (TestAlert Grafana)",
  "state": "alerting",
  "message": "**Firing**\n\nValue: [ metric='foo' labels={instance=bar} value=10 ]\nLabels:\n - alertname = TestAlert\n - instance = Grafana\nAnnotations:\n - summary = Notification test\nSilence: http://localhost:3000/alerting/silence/new?alertmanager=grafana&matchers=alertname%3DTestAlert%2Cinstance%3DGrafana\n"
}

You might want to add labels (title, message) and use that as a payload to /test?token=$APPLICATION_TOKEN

eikendev commented 2 years ago

Where are the top-level keys title, state, and message coming from in your JSON? Is this something you added with Grafana? Just asking because the code reads as if we read title and message from the annotations of each individual alert.

CubicrootXYZ commented 2 years ago

Where are the top-level keys title, state, and message coming from in your JSON? Is this something you added with Grafana? Just asking because the code reads as if we read title and message from the annotations of each individual alert.

Yes, this seems to be added by grafana.