Add dedicated post to slack function.

master
jowj 4 years ago
parent c003f8d6b1
commit 5fdccada37

@ -2,18 +2,27 @@ import os
from pathlib import Path from pathlib import Path
import slack import slack
def react_to_monitoring(): slack_token = os.environ.get("SLACK_BOT_TOKEN")
client = slack.WebClient(token=os.environ['SLACK_BOT_TOKEN'])
def post_to_slack(message_list):
if message_list:
client.chat_postMessage(
channel = "#bots-like-gaston",
text = message_list
)
def react_to_monitoring():
results_file = Path("/shared/alerts.log") results_file = Path("/shared/alerts.log")
does_file_exist = results_file.is_file()
if results_file.is_file(): if results_file.is_file():
open_file = open("/shared/alerts.log","r") open_file = open("/shared/alerts.log", "r")
for line in open_file: for line in open_file:
webclient.chat_postMessage( post_to_slack(line)
channel = channel_id,
text = line
)
os.remove("/shared/alerts.log") os.remove("/shared/alerts.log")
if __name__ == '__main__': if __name__ == '__main__':
while True: while True:
react_to_monitoring() react_to_monitoring()

Loading…
Cancel
Save