Skip to content

ichthyx/prometheus-xmpp-alerts

 
 

Repository files navigation

prometheus-xmpp-alerts

A simple web hook that forwards prometheus alerts over XMPP.

Usage

To use, configure a web hook in alertmanager. E.g.:

receivers:
- name: 'jelmer-xmpp'
  webhook_configs:
  - url: 'http://192.168.2.1:9199/alert'

Edit the configuration file (defaults to /etc/prometheus/xmpp-alerts.yml):

jid: '[email protected]'
password: 'PASSWORD'
# Alternatively, set a 'password_command' that should write a password to
# stdout
# password_command: 'pass show xmpp-alertmanager'
to_jid: '[email protected]'
listen_address: '192.168.2.1'
listen_port: 9199

# Text message template as jinja2; defaults to html_template with tags stripped (optional)
text_template: |
 {{ status.upper() }}: *{{ labels.alertname }}* at {{ labels.host or labels.instance }}:\
 {{ annotations.message }}. {{ generatorURL }}

You can also set the following environment variables instead:

  • XMPP_ID - XMPP JID

  • XMPP_PASS - Password

  • XMPP_RECIPIENTS - comma-separated list of recipients

  • XMPP_AMTOOL_ALLOWED - comma-separated list of users (optional)

  • WEBHOOK_HOST - Address to listen on (optional)

  • WEBHOOK_PORT - Port to listen on (optional)

  • TEXT_TEMPLATE - Template for text messages (see above, optional)

  • HTML_TEMPALTE - Template for HTML messages (see above, optional)

And run the web hook::

$ python3 -m prometheus_xmpp --config=/etc/prometheus/xmpp-alerts.yaml

If you have amtool set up, then you can also allow users to see existing alerts and manage silences. Set the amtool_allowed option to JIDs that are allowed to use amtool.

Docker file

You can build your own docker images using the Dockerfile in this directory, or use ghcr.io/jelmer/prometheus-xmpp-alerts. Provide your configuration in /config.yaml or through environment variables.

Message Format

The default message format looks something like this:

FIRING: AlertName at somehost: Alert Summary. https://prometheus.example.com/expr?...

The text_template option in the configuration can be used to customize the format, using jinja2.

Testing

The web hook can be accessed on three paths:

  • /alert: used by Prometheus to deliver alerts, expects POST requests with JSON body
  • /test: delivers a test message
  • /metrics: exposes statistics about number of alerts received

About

XMPP Web hook for Prometheus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.0%
  • Makefile 1.6%
  • Dockerfile 1.4%