aboutsummaryrefslogtreecommitdiff
path: root/modules/role/files/cryptoportfolio/slack-notify.py
blob: 1b3cd51006598e91f4a2276093bc7e27d125bc94 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3

import os
import sys
import json
import urllib3

project = os.environ["P_PROJECT"]
url     = os.environ["P_WEBHOOK"]
version = os.environ["P_VERSION"]
host    = os.environ["P_HOST"]
if os.environ["P_HTTPS"] == "true":
    scheme = "https://"
else:
    scheme = "http://"

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 = {
        "username": "Puppet",
        "icon_url": "https://learn.puppet.com/static/images/logos/Puppet-Logo-Mark-Amber.png",
        "text": "Deployed {} of {} on {}{}".format(
            version,
            project,
            scheme,
            host,
            ),
        }

json_data = json.dumps(data)
post(url, json_data)