]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blobdiff - modules/role/files/cryptoportfolio/slack-notify.py
Add notification for app deployment
[perso/Immae/Projets/Puppet.git] / modules / role / files / cryptoportfolio / slack-notify.py
diff --git a/modules/role/files/cryptoportfolio/slack-notify.py b/modules/role/files/cryptoportfolio/slack-notify.py
new file mode 100644 (file)
index 0000000..fe64fb6
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import sys
+import json
+import urllib3
+
+project = sys.argv[1]
+url     = sys.argv[2]
+version = sys.argv[3]
+
+def post(url, data):
+    urllib3.disable_warnings()
+    http = urllib3.PoolManager()
+
+    encoded = data.encode('utf-8')
+
+    r = http.request("POST", url,
+            headers={'Content-Type': 'application/json'},
+            body=encoded)
+
+data = {
+        "icon_url": "https://learn.puppet.com/static/images/logos/Puppet-Logo-Mark-Amber.png",
+        "text": "Deployed {} on {}".format(version, project),
+        }
+
+json_data = json.dumps(data)
+post(url, json_data)