]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blob - modules/role/files/cryptoportfolio/slack-notify.py
Remove cleanup files
[perso/Immae/Projets/Puppet.git] / modules / role / files / cryptoportfolio / slack-notify.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 import json
6 import urllib3
7
8 project = os.environ["P_PROJECT"]
9 url = os.environ["P_WEBHOOK"]
10 version = os.environ["P_VERSION"]
11 host = os.environ["P_HOST"]
12 if os.environ["P_HTTPS"] == "true":
13 scheme = "https://"
14 else:
15 scheme = "http://"
16
17 def post(url, data):
18 urllib3.disable_warnings()
19 http = urllib3.PoolManager()
20
21 encoded = data.encode('utf-8')
22
23 r = http.request("POST", url,
24 headers={'Content-Type': 'application/json'},
25 body=encoded)
26
27 data = {
28 "username": "Puppet",
29 "icon_url": "https://learn.puppet.com/static/images/logos/Puppet-Logo-Mark-Amber.png",
30 "text": "Deployed {} of {} on {}{}".format(
31 version,
32 project,
33 scheme,
34 host,
35 ),
36 }
37
38 json_data = json.dumps(data)
39 post(url, json_data)