forked from bimlendu/AWSHelperScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.python.py
executable file
·64 lines (59 loc) · 2.26 KB
/
slack.python.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
'''
POST msg to Slack.
'''
import sys
import requests
import json
import os
import socket
role = 'webc-paperless'
slack_webhook_url = 'https://hooks.slack.com/services/JHFJDFGSFJ/HHFJHJFFHF/kjhfkjgdsggsdgjg'
channel = '#channelName'
username = 'TheMessenger'
def slack(color, event):
message = 'Deployment status :: ' + os.environ['APPLICATION_NAME']
payload = { 'channel': channel,
'username': username,
'text': message,
'icon_url': 'http://img.stackshare.io/service/1888/aws-codedeploy.png',
'attachments': [ {
'fallback': os.environ['APPLICATION_NAME'] + ', ' + os.environ['DEPLOYMENT_GROUP_NAME'] + ', ' + os.environ['DEPLOYMENT_ID'] + ', ' + os.environ['LIFECYCLE_EVENT'],
'color': color,
'fields': [
{
'title': 'Application Name',
'value': os.environ['APPLICATION_NAME'],
'short': 'false'
},
{
'title': 'Deployment Group Name',
'value': os.environ['DEPLOYMENT_GROUP_NAME'],
'short': 'false'
},
{
'title': 'Deployment ID',
'value': os.environ['DEPLOYMENT_ID'],
'short': 'false'
},
{
'title': 'LifeCycle Event',
'value': os.environ['LIFECYCLE_EVENT'],
'short': 'false'
},
{
'title': 'Deployment Event',
'value': event + ' ' + role,
'short': 'false'
},
{
'title': 'Machine Details',
'value': socket.gethostname() + ' : ' + socket.gethostbyname(socket.gethostname()),
'short': 'false'
}
]
} ]
}
r = requests.post(slack_webhook_url, data=json.dumps(payload))
if __name__ == "__main__":
slack('good', 'tomcat restarted successfully')