Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

webserver: add webhook for prometheus alerts #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ircbot/plugin/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from flask import Flask
from flask import render_template
from flask import request

if TYPE_CHECKING:
from ircbot.ircbot import Listener
Expand Down Expand Up @@ -52,6 +53,25 @@ def route_macros():
)


@app.route('/hook/prometheus', methods=['POST'])
def route_prometheus():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is stopping me from sending a fake alert

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing, but if it becomes a problem we can add an HTTP password check.

body_json = request.get_json()
for alert in body_json['alerts']:
if alert['status'] == 'resolved':
status = '\x02\x0303OK\x0F'
else:
status = '\x02\x0304FIRING\x0F'

alert = '{status} \x02{alertname}\x0F: {summary}'.format(
status=status,
alertname=alert['labels']['alertname'],
summary=alert['annotations']['summary'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be extra safe and do a check here that these exist in the dictionary. The annotations section is entirely optional (if you don't believe me, you can verify this with promtool). Right now all the alerts we have a summary, but we don't have documentation for OCF alert standards, so some could eventually slip in without it.

)
app.bot.say('#rebuild-spam', alert)

return ('', 204)


def start_server(bot):
port = os.getenv('HTTP_PORT', 8888)
app.bot = bot
Expand Down