]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/blame - modules/role/files/cryptoportfolio/slack-notify.py
Fix username for slack bot
[perso/Immae/Projets/Puppet.git] / modules / role / files / cryptoportfolio / slack-notify.py
CommitLineData
a4c92ff7
IB
1#!/usr/bin/env python3
2
bd263a98 3import os
a4c92ff7
IB
4import sys
5import json
6import urllib3
7
bd263a98
IB
8project = os.environ["P_PROJECT"]
9url = os.environ["P_WEBHOOK"]
10version = os.environ["P_VERSION"]
11host = os.environ["P_HOST"]
12if os.environ["P_HTTPS"] == "true":
13 scheme = "https://"
14else:
15 scheme = "http://"
a4c92ff7
IB
16
17def 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
27data = {
50812570 28 "username": "Puppet",
a4c92ff7 29 "icon_url": "https://learn.puppet.com/static/images/logos/Puppet-Logo-Mark-Amber.png",
bd263a98
IB
30 "text": "Deployed {} of {} on {}{}".format(
31 version,
32 project,
33 scheme,
34 host,
35 ),
a4c92ff7
IB
36 }
37
38json_data = json.dumps(data)
39post(url, json_data)