Beispiel #1
0
    def send_alert_email(self, from_email, to_email, subject, alert_message,
                         repo_commit):
        alert_message = alert_message.decode("utf8")
        templateVars = {
            "title": subject,
            "description": "Description",
            "rule": "Rule",
            "github_link": repo_commit.url,
            "code": alert_message
        }

        templateLoader = jinja2.FileSystemLoader(searchpath="/")
        templateEnv = jinja2.Environment(loader=templateLoader)

        html_template_file = os.path.join(os.path.dirname(__file__),
                                          "templates/ruleengine_github.html")
        text_template_file = os.path.join(os.path.dirname(__file__),
                                          "templates/ruleengine_github.txt")

        html_template = templateEnv.get_template(html_template_file)
        text_template = templateEnv.get_template(text_template_file)

        html = html_template.render(templateVars)
        text = text_template.render(templateVars)

        EmailAlert().send(Alert(subject=subject,
                                message=text.encode('utf-8'),
                                message_html=html.encode('utf-8')),
                          to_email=to_email)
Beispiel #2
0
    def send_alert(self,
                   repo_patch,
                   repo_commit,
                   subject,
                   offending_line,
                   message=''):
        # parameter setup
        url = repo_commit.url
        filename = 'NOFILE'
        if repo_patch != None:
            filename = repo_patch.filename
        subject = self.EMAIL_ALERT_SUBJECT + " " + subject + ' in ' + repo_commit.identifier

        # skip if the alert is duplicate
        if url + filename + subject + offending_line == ForceDotComBasePlugin.last_alert:
            return

        # remember the current alert
        ForceDotComBasePlugin.last_alert = url + filename + subject + offending_line

        message = '<a href="' + url + '">' + url + '</a>'+\
        '<br/><br/>OFFENDING LINE<br/>' + self.simple_html_encode(offending_line) +\
        '<br/><br/>FILE NAME<br/>' + filename +\
        message

        # email alert
        alert = Alert(message='',
                      message_html=message,
                      subject=subject,
                      level=Alert.HIGH)
        email_recipients = [self.EMAIL_ALERT_RECIPIENTS]
        EmailAlert().send(alert, to_email=email_recipients)
Beispiel #3
0
 def _alert_callback(alert_action):
     alert_config_key = alert_action.get("alert config")
     alert_config = self._alert_configs.get(alert_config_key)
     if alert_config is None:
         logger.error("Alert config for [%s] is None", alert_config_key);
         return
     if alert_config.get("email"):
         default_email = config.Configuration('config.json').get(('email', 'to'))
         to_email = alert_config.get("email", default_email)
         patch_lines = u'\n'.join(repo_patch.diff.additions).encode('utf-8').strip()
         subject = alert_action.get("subject","Unknown Subject")
         (text, html) = self.create_alert_email(subject, data, repo_patch.repo_commit)
         ea = EmailAlert(Alert(subject=subject, 
                               message=text.encode('utf-8'), 
                               message_html=html.encode('utf-8')), 
                         to_email=to_email)
         if (self.test_mode == True):
             print ea
         else:
             ea.send()
     else:
         logger.warn("Alert type unknown %s" % (alert_config))
Beispiel #4
0
 def send_alert_email(self, from_email, to_email, subject, alert_message,
                      repo_commit):
     # me == my email address
     # you == recipient's email address
     # Create the body of the message (a plain-text and an HTML version).
     url_html = ""
     if repo_commit and repo_commit.sha:  #XXX: modify below to use config vars,
         #XXX: github.com/%s/%s/commit % (config.get('repos','github','owner'),...)
         url_html = "<A HREF='https://github.com/Pardot/pardot/commit/" + repo_commit.sha + "'>" + repo_commit.sha + "</A><br>"
     html = """
     <html>
       <head></head>
       <body>
         """ + url_html + """
         <pre><code>""" + cgi.escape(alert_message) + """
         </pre></code>
       </body>
     </html>
     """
     EmailAlert().send(Alert(subject=subject,
                             message=body,
                             message_html=html),
                       to_email=to_email)