Skip to content

Commit f5f21eb

Browse files
committed
Describe how to test the Alertmanager interface
1 parent 1a6e96b commit f5f21eb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/docs/developer-guide.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,44 @@ Running tests for all PushBits module is done like this:
3232
```bash
3333
make test
3434
```
35+
36+
## Testing the Alertmanager interface
37+
38+
Setting up a local [Alertmanager](https://prometheus.io/docs/alerting/latest/alertmanager/) instance is done quickly using Docker or Podman.
39+
We first create the file `config.yml` that tells Alertmanger where to send alerts.
40+
Don't forget to replace `<PB_TOKEN>` with your application's token.
41+
```yaml
42+
route:
43+
receiver: default
44+
45+
receivers:
46+
- name: default
47+
webhook_configs:
48+
- url: http://localhost:8080/alert?token=<PB_TOKEN> # Replace <PB_TOKEN> with your application's token.
49+
```
50+
51+
We mount this file into a container running Alertmanager.
52+
For convenience, let's use this Makefile:
53+
```make
54+
CONTAINER_NAME := alertmanager
55+
IMAGE_NAME := quay.io/prometheus/alertmanager
56+
57+
.PHONY: up
58+
up:
59+
podman run --name $(CONTAINER_NAME) --rm --network host -v $(PWD)/config.yml:/etc/alertmanager/alertmanager.yml:Z $(IMAGE_NAME)
60+
61+
.PHONY: down
62+
down:
63+
podman container stop $(CONTAINER_NAME)
64+
65+
.PHONY: send
66+
send:
67+
amtool alert add alertname=testmessage --annotation=title='My Title' --annotation=message='My Message'
68+
69+
.PHONY: setup
70+
setup:
71+
go install github.com/prometheus/alertmanager/cmd/amtool@latest
72+
```
73+
74+
So first you would install the client using `make setup`, followed by starting Alertmanager with `make up`.
75+
When PushBits is running, a `make send` would create a new alert in Alertmanager, which is then passed to PushBits via the defined webhook.

0 commit comments

Comments
 (0)