notify.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:sensu_drive 作者: ilavender 项目源码 文件源码
def __init__(self, message):

        self.entity = message['entity']
        self.status = int(message['status'])
        self.output = message['output']

        if int(message['status']) == 0:
            self.color = '#36a64f'
            self.twilio_msg_prefix = 'recovery notification.'
            self.twilio_msg_postfix = 'is okay!'
        elif int(message['status']) == 1:
            self.color = '#FFA500'
            self.twilio_msg_prefix = 'this is a warning!'
            self.twilio_msg_postfix = 'is in status warning!'
        elif int(message['status']) == 2:
            self.color = '#C74350'
            self.twilio_msg_prefix = 'bad news, this is a critical notification!'
            self.twilio_msg_postfix = 'is in status critical!'
        else:
            self.color = ''
            self.twilio_msg_prefix = 'unknown notification.'
            self.twilio_msg_postfix = 'is in status unknown!'

        slack_alert_template     = get_template('isubscribe/slack_alert.txt')
        self.slack_msg_content_fallback = slack_alert_template.render({ 'entity': self.entity, 'status': self.status, 'output':self.output })



        self.slack_attachments = [{
                    "fallback": self.slack_msg_content_fallback,
                    "title": self.entity,
                    "title_link": "%s%s" % (settings.REGISTRATION_URL_PREFIX, reverse_lazy('events')),
                    "text": self.output,
                    "color": self.color,
                    "author_name": settings.SLACK_BOT_NAME,
                    "author_link": "%s%s" % (settings.REGISTRATION_URL_PREFIX, reverse_lazy('events')),
                    "author_icon": settings.SLACK_BOT_ICON,
        }]

        twilio_msg_formated = self.twilio_msg_prefix + ' ' + self.entity + ' ' + self.twilio_msg_postfix
        self.twilio_params = { 'msg' : twilio_msg_formated,
                               'api_token' : settings.TWILIO_CALLBACK_API_TOKEN,
                               'entity': self.entity, 
                               'status': self.status 
                            }

        self.twilio_client = TwilioRestClient(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)

        self.slack_delivery_to = []
        self.twilio_delivery_to = []
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号