-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslack_connector.py
More file actions
executable file
·36 lines (32 loc) · 882 Bytes
/
slack_connector.py
File metadata and controls
executable file
·36 lines (32 loc) · 882 Bytes
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
import slack, socket
#init some variables for later use
cfg = {}
isSet = False
#load config
def setConf(conf):
global cfg
cfg = conf
return True
#create the connection to slack
def setClient():
global isSet
global client
if isSet == False:
client = slack.WebClient(cfg['slack']['api-key'])
isSet = True
return True
else:
return False
#format and send the message
def sendMsg(stat, value, limit, cap):
if cfg['slack']['enabled'] == False:
return False
else:
msg = f"Alarm:\n{stat} triggered an alarm! ({value}/{limit})\nThis is a {cap} on {socket.gethostname()}"
setClient()
response = client.chat_postMessage(
channel=cfg['slack']['channel'],
text=msg)
#make sure the message got through
assert response["ok"]
return True