From b10b710cd1cb400981887b1b7fc03b74a310dee0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sven=20M=C3=A4der?= <maeder@phys.ethz.ch>
Date: Tue, 12 Apr 2022 15:55:41 +0200
Subject: [PATCH] Adapt /slack api for checkmk, return 200 plaintext ok

---
 app.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/app.py b/app.py
index c294534..d0d4d1b 100644
--- a/app.py
+++ b/app.py
@@ -19,6 +19,7 @@ def slack(hook):
         title = str(attachment.get('title', ''))
         title_link = str(attachment.get('title_link', ''))
         text = str(attachment.get('text', ''))
+        footer = str(attachment.get('footer', ''))
         fields = attachment.get('fields', [])
 
         html += '<font color="' + color + '">' if color else ''
@@ -26,6 +27,9 @@ def slack(hook):
         if title and title_link:
             plain += title + ' ' + title_link + '\n'
             html += '<b><a href="' + title_link + '">' + title + '</a></b><br/>\n'
+        elif title:
+            plain += title + '\n'
+            html += '<b>' + title + '</b><br/>\n'
 
         if text:
             plain += text + '\n'
@@ -38,6 +42,10 @@ def slack(hook):
                 plain += title + ': ' + value + '\n'
                 html += '<b>' + title + '</b>: ' + value + '<br/>\n'
 
+        if footer:
+            plain += footer + '\n'
+            html += footer + '<br/>\n'
+
         html += '</font>' if color else ''
 
     if plain and html:
@@ -51,7 +59,9 @@ def slack(hook):
         print('Invalid format, sending unmodified.')
         r = requests.post(url + hook, json=incoming)
 
-    return {"ok":True}
+    response = make_response('ok', 200)
+    response.mimetype = "text/plain"
+    return response
 
 @app.route("/webhook/grafana/<hook>", methods=['POST', 'PUT'])
 def grafana(hook):
-- 
GitLab