コード例 #1
0
ファイル: webhook.py プロジェクト: sdgdsffdsfff/guardian-1
    def send_alert(self, level, subject, objects, content):

        alert_config = self.config['webhook']
        url = alert_config['url']
        params = {
            'subject': subject,
            'objects': objects,
            'content': content
        }

        headers = {
            'content-type': 'application/json;charset=UTF-8',
            'Accept': 'text/plain'
        }

        if match_alert(alert_config['routes'], level):
            url_info = urlparse(url)
            port = 80 if url_info.port is None else url_info.port
            try:
                http_client = httplib.HTTPConnection(url_info.hostname,
                                                     port, timeout=5)
                http_client.request("POST", url_info.path,
                                    json.dumps(params), headers)
            except Exception as e:
                raise AlertException(e)
コード例 #2
0
ファイル: emails.py プロジェクト: sdgdsffdsfff/guardian-1
    def send_alert(self, level, subject, objects, content):

        config = self.config
        config = config['emails']
        sender = config['sender']
        receivers = config['receivers']
        smtpserver = config['smtp_server']
        username = config['auth_username']
        password = config['auth_password']

        if match_alert(config['routes'], level):

            message = MIMEText('{0}: {1}'.format(objects, content), 'plain',
                               'utf-8')
            message['Subject'] = Header(subject, 'utf-8')
            message['To'] = ';'.join(config['receivers'])

            try:
                smtp = smtplib.SMTP()
                smtp.connect(smtpserver)
                smtp.login(username, password)
                smtp.sendmail(sender, receivers, message.as_string())

            except Exception as e:
                logging.error(str(e))
                raise AlertException(e)
コード例 #3
0
ファイル: emails.py プロジェクト: ostarsier/waterdrop
    def send_alert(config, level, subject, objects, content):
        config = config['emails']
        sender = config['sender']
        receivers = config['receivers']
        smtpserver = config['smtp_server']
        username = config['auth_username']
        password = config['auth_password']

        if match_alert(config['routes'], level):

            message = MIMEText(content, 'text', 'utf-8')
            message['Subject'] = Header(subject + objects, 'utf-8')

            smtp = smtplib.SMTP()
            smtp.connect(smtpserver)
            smtp.login(username, password)
            smtp.sendmail(sender, receivers, message.as_string())