Git Product home page Git Product logo

alertmanager-irc-relay's Introduction

Alertmanager IRC Relay

Alertmanager IRC Relay is a bot relaying Prometheus alerts to IRC. Alerts are received from Prometheus using Webhooks and are relayed to an IRC channel.

Configuring and running the bot

To configure and run the bot you need to create a YAML configuration file and pass it to the service. Running the service without a configuration will use the default test values and connect to a default IRC channel, which you probably do not want to do.

Example configuration:

# Start the HTTP server receiving alerts from Prometheus Webhook binding to
# this host/port.
#
http_host: localhost
http_port: 8000

# Connect to this IRC host/port.
#
# Note: SSL is enabled by default, use "irc_use_ssl: no" to disable.
# Set "irc_verify_ssl: no" to accept invalid SSL certificates (not recommended)
irc_host: irc.example.com
irc_port: 7000
# Optionally set the server password
irc_host_password: myserver_password

# Use this IRC nickname.
irc_nickname: myalertbot
# Password used to identify with NickServ
irc_nickname_password: mynickserv_key
# Use this IRC real name
irc_realname: myrealname

# Optionally pre-join certain channels.
#
# Note: If an alert is sent to a non # pre-joined channel the bot will join
# that channel anyway before sending the message. Of course this cannot work
# with password-protected channels.
irc_channels:
  - name: "#mychannel"
  - name: "#myprivatechannel"
    password: myprivatechannel_key

# Define how IRC messages should be sent.
#
# Send only one message when webhook data is received.
# Note: By default a message is sent for each alert in the webhook data.
msg_once_per_alert_group: no
#
# Use PRIVMSG instead of NOTICE (default) to send messages.
# Note: Sending PRIVMSG from bots is bad practice, do not enable this unless
# necessary (e.g. unless NOTICEs would weaken your channel moderation policies)
use_privmsg: yes

# Define how IRC messages should be formatted.
#
# The formatting is based on golang's text/template .
msg_template: "Alert {{ .Labels.alertname }} on {{ .Labels.instance }} is {{ .Status }}"
# Note: When sending only one message per alert group the default
# msg_template is set to
# "Alert {{ .GroupLabels.alertname }} for {{ .GroupLabels.job }} is {{ .Status }}"

# Set the internal buffer size for alerts received but not yet sent to IRC.
alert_buffer_size: 2048

# Patterns used to guess whether NickServ is asking us to IDENTIFY
# Note: If you need to change this because the bot is not catching a request
# from a rather common NickServ, please consider sending a PR to update the
# default config instead.
nickserv_identify_patterns:
  - "identify via /msg NickServ identify <password>"
  - "type /msg NickServ IDENTIFY password"
  - "authenticate yourself to services with the IDENTIFY command"

# Rarely NickServ or ChanServ is reached at a specific hostname.  Specify an
# override here
nickserv_name: NickServ
chanserv_name: ChanServ

Running the bot (assuming $GOPATH and $PATH are properly setup for go):

$ go install github.com/google/alertmanager-irc-relay
$ alertmanager-irc-relay --config /path/to/your/config/file

The configuration file can reference environment variables. It is then possible to specify certain parameters directly when running the bot:

$ cat /path/to/your/config/file
...
http_port: $MY_SERVICE_PORT
...
irc_nickname_password: $NICKSERV_PASSWORD
...
$ export MY_SERVICE_PORT=8000 NICKSERV_PASSWORD=mynickserv_key
$ alertmanager-irc-relay --config /path/to/your/config/file

Prometheus configuration

Prometheus can be configured following the official Webhooks documentation. The url must specify the IRC channel name that alerts should be sent to:

send_resolved: false
url: http://localhost:8000/mychannel

alertmanager-irc-relay's People

Contributors

dependabot[bot] avatar erikmack avatar filippog avatar gouthamve avatar jelmer avatar shammash avatar superq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

alertmanager-irc-relay's Issues

Support for IDENTIFY after getting 005 / ISUPPORT code

Hello,
I'm running alertmanager-irc-relay on libera.chat and nickserv apparently doesn't send NOTICE anymore after the first connection. The end result being the bot never identifies to nickserv; apparently it should be ok to (attempt to) IDENTIFY to nickserv after receiving 005 (aka ISUPPORT) from the server on first connection. The proper solution is of course SASL in #12 although this seems an easier fix/implementation

Unable to exit when not yet connected to IRC?

I'm running into a potential issue where the relay is not yet connected to irc (and backing off, using an empty/default configuration file) and upon receiving SIGTERM from systemd the daemon doesn't exit:

Jul 27 12:25:54 host alertmanager-irc-relay[19807]: 2020/07/27 12:25:54 Could not connect to IRC: dial tcp 93.184.216.34:7000: i/o timeout
Jul 27 12:25:54 host alertmanager-irc-relay[19807]: 2020/07/27 12:25:54 Connecting to IRC example.com:7000
Jul 27 12:25:54 host alertmanager-irc-relay[19807]: 2020/07/27 12:25:54 Backoff for 3m7s
Jul 27 12:26:00 host systemd[1]: Stopping Send Prometheus Alerts to IRC using Webhooks...
Jul 27 12:26:00 host alertmanager-irc-relay[19807]: 2020/07/27 12:26:00 Received terminated, exiting

Although the exit never comes and systemd eventually issues SIGKILL

Jul 27 12:27:30 host systemd[1]: alertmanager-irc-relay.service: State 'stop-sigterm' timed out. Killing.
Jul 27 12:27:30 host systemd[1]: alertmanager-irc-relay.service: Killing process 19807 (alertmanager-ir) with signal SIGKILL.

Add option to ignore SSL verification

Hey,
Would it be possible to include an option to ignore SSL-certificate when using the 'irc_use_ssl: yes' ?

At the moment we get the following error:

Feb 26 13:50:23 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:23 Starting HTTP server
Feb 26 13:50:23 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:23 Connecting to IRC
Feb 26 13:50:23 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:23 Backoff for 0s
Feb 26 13:50:23 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:23 Could not connect to IRC: x509: certificate has expired or is not yet valid
Feb 26 13:50:23 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:23 Connecting to IRC
Feb 26 13:50:23 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:23 Backoff for 1s
Feb 26 13:50:24 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:24 Could not connect to IRC: x509: certificate has expired or is not yet valid
Feb 26 13:50:24 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:24 Connecting to IRC
Feb 26 13:50:24 prom-am-01.argos.bahnhof.net alertmanager-irc-relay[84194]: 2020/02/26 13:50:24 Backoff for 3s

Thank you.
@shammash

Set password for irc server (not only for channel)

Hello,

I'm not able to connect the bot to the irc server. This server uses SSL but also have a password before connecting to channels. I tried to put this password in irc_channels config (password field) but it does not work...

I always have these errors:

alertmanager-irc-relay    | 2020/09/04 07:31:21 Connecting to IRC myIRCserver:7000
alertmanager-irc-relay    | 2020/09/04 07:31:21 Starting HTTP server
alertmanager-irc-relay    | 2020/09/04 07:31:21 Backoff for 0s
alertmanager-irc-relay    | 2020/09/04 07:31:21 Connected to IRC server, waiting to establish session
alertmanager-irc-relay    | 2020/09/04 07:31:21 Disconnected from IRC
alertmanager-irc-relay    | 2020/09/04 07:31:21 Deregistering all channels

End when an alert is firing:

alertmanager-irc-relay    | 2020/09/04 07:35:14 Connected to IRC server, waiting to establish session
alertmanager-irc-relay    | 2020/09/04 07:35:14 Cannot send alert to #mychannel : IRC not connected

Any idea?

Default server / irc channel?

With the current default configuration the relay will attempt to connect to a real irc server and channel, I believe connecting to a non existent server e.g. irc.example.com would provide better defaults. e.g. in cases where multiple folks try and start the relay and all copies will connect to the same server/channel.

Prometheus metrics support

It would be nice to have support for Prometheus metrics available. A bunch of examples but I'm sure more are possible: on number of webhooks received, errors while processing hooks, number of irc messages sent, server connection status, etc

Take secrets from environment variables

We'd like to run this as a pod in kubernetes; with the base configuration in a configmap, but secrets in a secret.
Could you provide a way to configure secret via environment variable? Options include:

  • Have environment variables override any configuration field
  • Allow config file values to contain references to environment variables, e.g. $NICKSERV_PASSWORD

Support for multiple lines

Newlines currently seem to be broken.
When using a template with multiple lines, only the first line is printed.

   ⚠ ⚠ ⚠ [{{.Labels.instance}}] - {{ .Labels.alertname }} is {{.Status}} ⚠ ⚠ ⚠\n{{.Annotations.description}}\n(@pinpox act accordingly)";

Will result in only the first line being send.

Support SASL authentication

Hi,

Thanks for this nice program!
I would like to submit a feature request: support native SASL authentication (I am aware some IRCd's support SASL through PASS).

Cheers,
Georg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.