def get_dict_from_yaml(file_path): from alice.helper.log_utils import LOG data = {} with open(file_path, 'r') as stream: try: data = yaml.load(stream) except yaml.YAMLError as exc: LOG.error( "\nPlease validate your config file, if it is correct. Can use http://www.yamllint.com/ to debug quicker" ) raise (exc) return data
def get_dict_from_config_file(file_path): from alice.helper.log_utils import LOG if file_path.endswith(".yaml"): data = get_dict_from_yaml(file_path) elif file_path.endswith(".json"): try: with open(file_path) as data_file: data = json.load(data_file) except Exception as e: LOG.error( "\nPlease validate your config file, if it is correct. Can use https://jsonlint.com/ to debug quicker" ) raise (e) else: raise Exception( "Config Format mismatch: The config file should be either yaml or json type" ) return data
def postToSlack(self, channel, msg=None, as_user=True, *args, **kwargs): LOG.info("\n************** NOTIFYING ******************\n" "************** %s *************\n" "Message= %s\n" "******************************************* " % (channel, msg)) try: self.slack.chat.post_message(channel=channel, text=msg, icon_url=self.icon, as_user=as_user, *args, **kwargs) except Exception as ex: LOG.error("Error while posting alert to slack, please check if: \n1. The provided slack/hubot token for alice is correct " \ "and it has access to the channel=%s" \ "\n2.The channel name is correct\n" %(channel)) raise ex