view mod_pubsub_alertmanager/README.md @ 4651:8231774f5bfd

mod_cloud_notify_encrypted: Ensure body substring remains valid UTF-8 The `body:sub()` call risks splitting the string in the middle of a multi-byte UTF-8 sequence. This should have been caught by util.stanza validation, but that would have caused some havoc, at the very least causing the notification to not be sent. There have been no reports of this happening. Likely because this module isn't widely deployed among users with languages that use many longer UTF-8 sequences. The util.encodings.utf8.valid() function is O(n) where only the last sequence really needs to be checked, but it's in C and expected to be fast.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Aug 2021 13:22:59 +0200
parents eba7e68120d8
children 67190744b1eb
line wrap: on
line source

---
labels:
- 'Stage-Alpha'
summary: Alertmanager webhook receiver for pubsub
---

# Introduction

This module lets
[Alertmanager](https://prometheus.io/docs/alerting/latest/alertmanager/)
publish alerts to [pubsub][doc:pubsub] via
[webhooks](https://prometheus.io/docs/alerting/latest/configuration/#webhook_config).

# Setup

The relevant pubsub nodes must be created and configured somehow.
Because the request IP address is used to publish, the `publisher`
affiliation should be given to the IP address Alertmanager sends
webhooks from.

# Configuration

## Prometheus

A Prometheus `rule_files` might contain something along these lines:

``` yaml
groups:
- name: Stuff
  rules:
  - alert: Down
    expr: up == 0
    for: 5m
    annotations:
      title: 'Stuff is down!'
    labels:
      severity: 'critical'
```

## Alertmanager
On the Alertmanager site the webhook configuration may look something
like this:

``` yaml
receivers:
- name: pubsub
  webhook_configs:
  - url: http://pubsub.localhost:5280/pubsub_alertmanager
```

And then finally some Alertmanager routes would point at that receiver:

``` yaml
route:
  receiver: pubsub
```

## Prosody

On the Prosody side, apart from creating and configuring the node(s)
that will be used, configure your pubsub service like this:

``` lua
Component "pubsub.example.com" "pubsub"
modules_enabled = {
    "pubsub_alertmanager",
}

-- optional extra settings:
alertmanager_body_template = [[
*ALARM!* {annotations.title?Alert} is {status}
Since {startsAt}{endsAt& until {endsAt}}
Labels: {labels%
  {idx}: {item}}
Annotations: {annotations%
  {idx}: {item}}
]]

alertmanager_node_template = "alerts/{alert.labels.severity}"
```

If no node template is given, either an optional part after
"pubsub_alertmanager" in the HTTP path is used as node, or the string
"alerts". Here, an alerts would be published to different nodes based on
the 'severity' label, so e.g. `alerts/critical` in this example.

## All Options

Available configuration options:

`alertmanager_body_template`
:   Template for the textual representation of alerts.

`alertmanager_node_template`
:   Template for the pubsub node name, defaults to `"{path?alerts}"`