def send_email(from_='*****@*****.**',
               to='',
               subject='',
               message='',
               server='',
               port=25,
               username='',
               password=''):
    logger.debug('Emailing %s' % to)

    if not server:
        return

    msg = MIMEText(message)

    msg['Subject'] = subject
    msg['From'] = from_
    msg['To'] = to

    try:
        s = smtplib.SMTP(server, port)
        s.ehlo()
        s.starttls()
        s.ehlo()
        # Log in if appropriate
        if username and password:
            s.login(username, password)
        s.sendmail(from_, [to], msg.as_string())
        logger.info('Email sent to %s' % (to))
    except Exception as e:
        logger.error('Email sending produced exception %r' % e)
    finally:
        s.quit()
Beispiel #2
0
def notify(incident):
    if c.config.getVal('console.email_notification_enable', False):
        logger.debug('Email notifications enabled')
        addresses = c.config.getVal('console.email_notification_address', default=[])
        if c.config.getVal('console.mandrill_key', default=''):
            for address in addresses:
                logger.debug('Email sent to %s' % address)
                mandrill_send(to=address,
                              subject=incident.format_title(),
                              message=incident.format_report())
        else:
            server  = c.config.getVal('console.email_host', default='')
            port = int(c.config.getVal('console.email_port', default=25))
            if len(addresses) > 0 and server:
                for address in addresses:
                    send_email(to=address,
                               subject=incident.format_title(),
                               message=incident.format_report(),
                               server=server,
                               port=port)

    if c.config.getVal('console.sms_notification_enable', default=False):
        logger.debug('SMS notifications enabled')
        sms = SMS()
        sms_numbers = c.config.getVal('console.sms_notification_numbers', [])
        for to in sms_numbers:
            logger.debug('SMS sent to %s' % to)
            sms.send(to, incident.format_report_short())
Beispiel #3
0
def notify(incident):
    if c.config.getVal('console.email_notification_enable', False):
        logger.debug('Email notifications enabled')
        addresses = c.config.getVal('console.email_notification_addresses',
                                    default=[])
        if c.config.getVal('console.mandrill_key', False):
            for address in addresses:
                logger.debug('Email sent to %s' % address)
                mandrill_send(to=address,
                              subject=incident.format_title(),
                              message=incident.format_report())
        else:
            server = c.config.getVal('console.email_host', default='')
            port = int(c.config.getVal('console.email_port', default=25))
            from_ = c.config.getVal('console.email_from_address', default='')
            credentials = c.config.getVal('console.email_credentials',
                                          default=[])
            username = credentials[0]
            password = credentials[1]
            if len(addresses) > 0 and server:
                for address in addresses:
                    send_email(from_=from_,
                               to=address,
                               subject=incident.format_title(),
                               message=incident.format_report(),
                               server=server,
                               port=port,
                               username=username,
                               password=password)

    if c.config.getVal('console.sms_notification_enable', default=False):
        logger.debug('SMS notifications enabled')
        sms = SMS()
        sms_numbers = c.config.getVal('console.sms_notification_numbers', [])
        for to in sms_numbers:
            logger.debug('SMS sent to %s' % to)
            sms.send(to, incident.format_report_short())

    if c.config.getVal('console.slack_notification_enable', default=False):
        logger.debug('Slack notifications enabled')
        webhooks = c.config.getVal('console.slack_notification_webhook',
                                   default=[])
        for to in webhooks:
            response = requests.post(
                to, json={"text": incident.format_report_short()})
            if response.status_code != 200:
                logger.error(
                    "Error %s sending Slack message, the response was:\n%s" %
                    (response.status_code, response.text))
def send_email(from_='*****@*****.**', to='', subject='', message='', server=''):
    logger.debug('Emailing %s' % to)
    if not server:
        return

    msg = MIMEText(message)

    msg['Subject'] = subject
    msg['From'] = from_
    msg['To'] = to

    s = smtplib.SMTP(server)
    try:
        s.sendmail(from_, [to], msg.as_string())
        logger.info('Email sent to %s' % (to))
    except Exception as e:
        logger.error('Email sending produced exception %r' % e)
    s.quit()
Beispiel #5
0
def send_email(from_='*****@*****.**', to='', subject='', message='', server='', port=25):
    logger.debug('Emailing %s' % to)
    if not server:
        return

    msg = MIMEText(message)

    msg['Subject'] = subject
    msg['From'] = from_
    msg['To'] = to

    s = smtplib.SMTP(server, port)
    try:
        s.sendmail(from_, [to], msg.as_string())
        logger.info('Email sent to %s' % (to))
    except Exception as e:
        logger.error('Email sending produced exception %r' % e)
    s.quit()
def notify(incident):
    if c.config.getVal('console.email_notification_enable', False):
        logger.debug('Email notifications enabled')
        addresses = c.config.getVal('console.email_notification_address',
                                    default=[])
        if c.config.getVal('console.mandrill_key', False):
            for address in addresses:
                logger.debug('Email sent to %s' % address)
                mandrill_send(to=address,
                              subject=incident.format_title(),
                              message=incident.format_report())
        else:
            server = c.config.getVal('console.email_host', default='')
            port = int(c.config.getVal('console.email_port', default=25))
            if len(addresses) > 0 and server:
                for address in addresses:
                    send_email(to=address,
                               subject=incident.format_title(),
                               message=incident.format_report(),
                               server=server,
                               port=port)

    if c.config.getVal('console.sms_notification_enable', default=False):
        logger.debug('SMS notifications enabled')
        sms = SMS()
        sms_numbers = c.config.getVal('console.sms_notification_numbers', [])
        for to in sms_numbers:
            logger.debug('SMS sent to %s' % to)
            sms.send(to, incident.format_report_short())

    if c.config.getVal('console.slack_notification_enable', default=False):
        logger.debug('Slack notifications enabled')
        webhooks = c.config.getVal('console.slack_notification_webhook',
                                   default=[])
        for to in webhooks:
            response = requests.post(
                to, json={"text": incident.format_report_short()})
            if response.status_code != 200:
                logger.error(
                    "Error %s sending Slack message, the response was:\n%s" %
                    (response.status_code, response.text))

    if c.config.getVal('console.twitter_notification_enable', default=False):
        logger.debug('Twitter notifications enabled')
        auth = tweepy.OAuthHandler(
            c.config.getVal('consumer_key', default=''),
            c.config.getVal('consumer_secret', default=''))
        auth.set_access_token(
            c.config.getVal('access_token', default=''),
            c.config.getVal('access_token_secret', default=''))
        api = tweepy.API(auth)
        tweet = incident.format_report_short()[:280]
        status = api.update_status(status=tweet)
        logger.log(status)

    if c.config.getVal('console.file_notification_enable', default=False):
        logger.debug('File notifications enabled')
        with open(c.config.getVal('file_path', default=''), "a") as myfile:
            myfile.write(incident.format_report() + '\r\n')