~xenrox/ntfy-alertmanager

fa1a7916f05dd4ee3e12e0fdae2289d8f3705749 — Thorben Günther a month ago b3d5045
Add testing setup
3 files changed, 174 insertions(+), 1 deletions(-)

M .justfile
A contrib/test_payload.json
A contrib/test_resolved_payload.json
M .justfile => .justfile +14 -1
@@ 1,3 1,6 @@
default:
  @just --choose

test:
    go test -v ./...



@@ 8,7 11,7 @@ lint:

gofmt:
    gofmt -l .
    test -z $(gofmt -l .)
    @test -z $(gofmt -l .)

build:
    go build


@@ 16,3 19,13 @@ build:
upgrade-deps:
    go get -u ./...
    go mod tidy

@run:
    go run . --config ./devconfig.scfg

@curl:
    curl --user "user:pass" -X 'POST' \
        '127.0.0.1:8080' \
        -H 'Content-Type: application/json' \
        -d @contrib/test_payload.json


A contrib/test_payload.json => contrib/test_payload.json +80 -0
@@ 0,0 1,80 @@
{
    "receiver": "test-receiver",
    "status": "firing",
    "alerts": [
        {
            "status": "firing",
            "labels": {
                "alertname": "systemd_unit_failed",
                "instance": "example.com",
                "job": "node_exporter",
                "name": "example.service",
                "severity": "critical",
                "state": "failed",
                "type": "oneshot"
            },
            "annotations": {
                "description": "Instance example.com: Service example.service failed",
                "summary": "Systemd unit failed"
            },
            "startsAt": "2022-10-09T08:31:47.929Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "http://example.com:9090/graph?g0.expr=node_systemd_unit_state%7Bstate%3D%22failed%22%7D+%3E+0\u0026g0.tab=1",
            "fingerprint": "6f1c1a905a91802b"
        },
        {
            "status": "firing",
            "labels": {
                "alertname": "systemd_unit_failed",
                "instance": "example.com",
                "job": "node_exporter",
                "name": "bar.service",
                "severity": "critical",
                "state": "failed",
                "type": "oneshot"
            },
            "annotations": {
                "description": "Instance example.com: Service bar.service failed",
                "summary": "Systemd unit failed"
            },
            "startsAt": "2022-10-06T12:48:47.929Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "http://example.com:9090/graph?g0.expr=node_systemd_unit_state%7Bstate%3D%22failed%22%7D+%3E+0\u0026g0.tab=1",
            "fingerprint": "0b17134bedc094da"
        },
        {
            "status": "firing",
            "labels": {
                "alertname": "systemd_unit_failed",
                "instance": "example.com",
                "job": "node_exporter",
                "name": "foo.service",
                "severity": "critical",
                "state": "failed",
                "type": "oneshot"
            },
            "annotations": {
                "description": "Instance example.com: Service foo.service failed",
                "summary": "Systemd unit failed"
            },
            "startsAt": "2022-10-09T00:03:47.929Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "http://example.com:9090/graph?g0.expr=node_systemd_unit_state%7Bstate%3D%22failed%22%7D+%3E+0\u0026g0.tab=1",
            "fingerprint": "aaaabf78228dbbc6"
        }
    ],
    "groupLabels": { "instance": "example.com", "severity": "critical" },
    "commonLabels": {
        "alertname": "systemd_unit_failed",
        "instance": "example.com",
        "job": "node_exporter",
        "severity": "critical",
        "state": "failed",
        "type": "oneshot"
    },
    "commonAnnotations": { "summary": "Systemd unit failed" },
    "externalURL": "http://example.com:9093",
    "version": "4",
    "groupKey": "{}:{instance=\"example.com\", severity=\"critical\"}",
    "truncatedAlerts": 0
}

A contrib/test_resolved_payload.json => contrib/test_resolved_payload.json +80 -0
@@ 0,0 1,80 @@
{
    "receiver": "test-receiver",
    "status": "firing",
    "alerts": [
        {
            "status": "resolved",
            "labels": {
                "alertname": "systemd_unit_failed",
                "instance": "example.com",
                "job": "node_exporter",
                "name": "example.service",
                "severity": "critical",
                "state": "failed",
                "type": "oneshot"
            },
            "annotations": {
                "description": "Instance example.com: Service example.service failed",
                "summary": "Systemd unit failed"
            },
            "startsAt": "2022-10-09T08:31:47.929Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "http://example.com:9090/graph?g0.expr=node_systemd_unit_state%7Bstate%3D%22failed%22%7D+%3E+0\u0026g0.tab=1",
            "fingerprint": "6f1c1a905a91802b"
        },
        {
            "status": "firing",
            "labels": {
                "alertname": "systemd_unit_failed",
                "instance": "example.com",
                "job": "node_exporter",
                "name": "bar.service",
                "severity": "critical",
                "state": "failed",
                "type": "oneshot"
            },
            "annotations": {
                "description": "Instance example.com: Service bar.service failed",
                "summary": "Systemd unit failed"
            },
            "startsAt": "2022-10-06T12:48:47.929Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "http://example.com:9090/graph?g0.expr=node_systemd_unit_state%7Bstate%3D%22failed%22%7D+%3E+0\u0026g0.tab=1",
            "fingerprint": "0b17134bedc094da"
        },
        {
            "status": "firing",
            "labels": {
                "alertname": "systemd_unit_failed",
                "instance": "example.com",
                "job": "node_exporter",
                "name": "foo.service",
                "severity": "critical",
                "state": "failed",
                "type": "oneshot"
            },
            "annotations": {
                "description": "Instance example.com: Service foo.service failed",
                "summary": "Systemd unit failed"
            },
            "startsAt": "2022-10-09T00:03:47.929Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "http://example.com:9090/graph?g0.expr=node_systemd_unit_state%7Bstate%3D%22failed%22%7D+%3E+0\u0026g0.tab=1",
            "fingerprint": "aaaabf78228dbbc6"
        }
    ],
    "groupLabels": { "instance": "example.com", "severity": "critical" },
    "commonLabels": {
        "alertname": "systemd_unit_failed",
        "instance": "example.com",
        "job": "node_exporter",
        "severity": "critical",
        "state": "failed",
        "type": "oneshot"
    },
    "commonAnnotations": { "summary": "Systemd unit failed" },
    "externalURL": "http://example.com:9093",
    "version": "4",
    "groupKey": "{}:{instance=\"example.com\", severity=\"critical\"}",
    "truncatedAlerts": 0
}