import os from pathlib import Path import slack 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") if results_file.is_file(): open_file = open("/shared/alerts.log", "r") for line in open_file: post_to_slack(line) os.remove("/shared/alerts.log") if __name__ == '__main__': while True: react_to_monitoring()