From dddd7392b25102d2fd4293df32d5d53878b47660 Mon Sep 17 00:00:00 2001 From: Rune Juhl Jacobsen Date: Sun, 19 Feb 2023 19:56:06 +0100 Subject: [PATCH 1/2] Tweak, add CI --- .woodpecker.yml | 14 ++++++++++++++ Dockerfile | 4 +++- grafana_webhook_to_matrix.py | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .woodpecker.yml diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..19c652d --- /dev/null +++ b/.woodpecker.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index f2386f6..32f3c5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,6 @@ RUN pip --disable-pip-version-check install --no-cache-dir -r /requirements.txt # Set up app RUN mkdir -p /usr/src/app WORKDIR /usr/src/app -COPY grafana_webhook_to_matrix.py ./ # Set up user RUN mkdir -p /usr/src/app/home && \ @@ -32,4 +31,7 @@ ENV PYTHONFAULTHANDLER=1 USER 998 EXPOSE 8003 + +COPY grafana_webhook_to_matrix.py ./ + CMD ["python3", "grafana_webhook_to_matrix.py"] diff --git a/grafana_webhook_to_matrix.py b/grafana_webhook_to_matrix.py index b27d68b..6331621 100644 --- a/grafana_webhook_to_matrix.py +++ b/grafana_webhook_to_matrix.py @@ -54,4 +54,4 @@ app.add_routes([ if __name__ == '__main__': - web.run_app(app, host='127.0.0.1', port=8003) + web.run_app(app, host='0.0.0.0', port=8003) From 3901791a6edb257e72dd04f658d574caca2b5620 Mon Sep 17 00:00:00 2001 From: Rune Juhl Jacobsen Date: Sun, 19 Feb 2023 21:52:36 +0100 Subject: [PATCH 2/2] debug --- grafana_webhook_to_matrix.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grafana_webhook_to_matrix.py b/grafana_webhook_to_matrix.py index 6331621..7ba72df 100644 --- a/grafana_webhook_to_matrix.py +++ b/grafana_webhook_to_matrix.py @@ -3,15 +3,13 @@ from aiohttp import web from datetime import datetime import os - homeserver = os.environ['MATRIX_HOMESERVER'] access_token = os.environ['MATRIX_ACCESS_TOKEN'] room = os.environ['MATRIX_ROOM'] - - _last_timestamp = 0 _counter = 0 + def unique_number(): global _last_timestamp global _counter @@ -43,6 +41,7 @@ async def handle_alert(request): body = await request.json() title = body['title'] status = body['status'] + print(body) await send_message(f'[{status}] {title}') return web.Response(text='Ok') @@ -54,4 +53,5 @@ app.add_routes([ if __name__ == '__main__': + print('grafana_webhook_to_matrix.py starting') web.run_app(app, host='0.0.0.0', port=8003)