Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3901791a6e | |||
| dddd7392b2 | |||
|
|
0af95a105b |
3 changed files with 24 additions and 9 deletions
14
.woodpecker.yml
Normal file
14
.woodpecker.yml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
pipeline:
|
||||||
|
build:
|
||||||
|
image: git.petardo.dk/runejuhl/dockerfiles/buildah/stable:v1.28.0
|
||||||
|
privileged: true
|
||||||
|
commands:
|
||||||
|
- |-
|
||||||
|
echo $${WOODPECKER_CI} | buildah login --username runejuhl --password-stdin git.petardo.dk
|
||||||
|
- |-
|
||||||
|
buildah build -f ./Dockerfile -t git.petardo.dk/runejuhl/grafana-webhook-to-matrix
|
||||||
|
- |-
|
||||||
|
buildah push git.petardo.dk/runejuhl/grafana-webhook-to-matrix
|
||||||
|
secrets:
|
||||||
|
- woodpecker_ci
|
||||||
|
|
@ -21,7 +21,6 @@ RUN pip --disable-pip-version-check install --no-cache-dir -r /requirements.txt
|
||||||
# Set up app
|
# Set up app
|
||||||
RUN mkdir -p /usr/src/app
|
RUN mkdir -p /usr/src/app
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
COPY grafana_webhook_to_matrix.py ./
|
|
||||||
|
|
||||||
# Set up user
|
# Set up user
|
||||||
RUN mkdir -p /usr/src/app/home && \
|
RUN mkdir -p /usr/src/app/home && \
|
||||||
|
|
@ -32,4 +31,7 @@ ENV PYTHONFAULTHANDLER=1
|
||||||
|
|
||||||
USER 998
|
USER 998
|
||||||
EXPOSE 8003
|
EXPOSE 8003
|
||||||
|
|
||||||
|
COPY grafana_webhook_to_matrix.py ./
|
||||||
|
|
||||||
CMD ["python3", "grafana_webhook_to_matrix.py"]
|
CMD ["python3", "grafana_webhook_to_matrix.py"]
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,13 @@ from aiohttp import web
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
homeserver = os.environ['MATRIX_HOMESERVER']
|
homeserver = os.environ['MATRIX_HOMESERVER']
|
||||||
access_token = os.environ['MATRIX_ACCESS_TOKEN']
|
access_token = os.environ['MATRIX_ACCESS_TOKEN']
|
||||||
room = os.environ['MATRIX_ROOM']
|
room = os.environ['MATRIX_ROOM']
|
||||||
|
|
||||||
|
|
||||||
_last_timestamp = 0
|
_last_timestamp = 0
|
||||||
_counter = 0
|
_counter = 0
|
||||||
|
|
||||||
|
|
||||||
def unique_number():
|
def unique_number():
|
||||||
global _last_timestamp
|
global _last_timestamp
|
||||||
global _counter
|
global _counter
|
||||||
|
|
@ -41,10 +39,10 @@ async def send_message(text):
|
||||||
|
|
||||||
async def handle_alert(request):
|
async def handle_alert(request):
|
||||||
body = await request.json()
|
body = await request.json()
|
||||||
for alert in body['alerts']:
|
title = body['title']
|
||||||
status = alert['status']
|
status = body['status']
|
||||||
name = alert['labels']['alertname']
|
print(body)
|
||||||
await send_message(f'[{status}] {name}')
|
await send_message(f'[{status}] {title}')
|
||||||
return web.Response(text='Ok')
|
return web.Response(text='Ok')
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -55,4 +53,5 @@ app.add_routes([
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
web.run_app(app, host='127.0.0.1', port=8003)
|
print('grafana_webhook_to_matrix.py starting')
|
||||||
|
web.run_app(app, host='0.0.0.0', port=8003)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue