-
Notifications
You must be signed in to change notification settings - Fork 1
/
slack_reporter.py
executable file
·33 lines (25 loc) · 1.23 KB
/
slack_reporter.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
#!/usr/bin/env python3
import slack_sdk
import slack_reporter_config as config
def add_preamble(message):
return f"The {config.board_name} says: {message}"
def report_message(message):
text = add_preamble(message)
client = slack_sdk.WebClient(token=config.auth_token)
result = client.chat_postMessage(channel=config.channel_id, text=text)
# If we get a result, things worked. Failure raises exceptions instead.
# Currently, we ignore any errors. The cron job that runs this script
# will write all our output (including a stack trace from an uncaught
# exception) to /var/log/canary_analysis.log, but there's no obvious way to
# tell a human to go look at that. How do we report that we're unable to
# report stuff!?
return result # Maybe whoever called us knows what to do with this.
def report_file(filename, contents, comment):
text = add_preamble(comment)
client = slack_sdk.WebClient(token=config.auth_token)
result = client.files_upload_v2(
channel=config.channel_id, content=contents, snippet_type="text",
filename=filename, initial_comment=text)
# Again, if things fail we'll raise an exception here, but there is no
# obvious resolution for that.
return result