예제 #1
0
def sendNotification(results):
    """
	input: [List] results
	output: send notification email to recipients about the results.
	"""
    if results == []:
        return

    sendMail(resultsToString(results), toSubject(results), getMailSender(),
             getMailRecipients(), getMailServer(), getMailTimeout())
예제 #2
0
def sendMailToId(id):
    if request.is_json:
        form = request.get_json()
        message = form.get("content")
        subject = form.get("subject")
        user = userService.getUserById(id)
        sendMail(subjectText=subject,
                 contentText=message,
                 recipientsList=[user.email])
        return make_response(jsonify(form), 200)
    return abort(400)
예제 #3
0
def sendNotification(subject):
    """
	input: [String] result (file name)
	
	side effect: send notification email to recipients about the results.
	"""
    try:
        sendMail('', subject, getMailSender(), getMailRecipients(),
                 getMailServer(), getMailTimeout())

    except:
        logger.exception('sendNotification()')
예제 #4
0
def sendNotification(result, outputFile=None):
    """
    [int] result, [String] outputFile => no return value.

    The function send a notification email about the conversion result.
    """
    if result == SUCCESS:
        emailSubject = 'Bloomberg AIM trade file {0} uploaded to Geneva'.format(
            outputFile)
    else:
        emailSubject = 'Error occurred on flowing Bloomberg AIM trades to Geneva'

    sendMail('', emailSubject, getMailSender(), getMailRecipients(),
             getMailServer(), getMailTimeout())
예제 #5
0
def sendMailToList():
    if request.is_json:
        form = request.get_json()
        userids = form.get("ids")
        message = form.get("content")
        subject = form.get("subject")
        users = list(
            map(lambda userid: userService.getUserById(userid), userids))
        usersEmail = list(map(lambda user: user.email, users))
        sendMail(subjectText=subject,
                 contentText=message,
                 recipientsList=[usersEmail])
        return make_response(jsonify(form), 200)
    return abort(400)
예제 #6
0
def sendNotification(result):
    """
	input: [String] result (file name)
	
	side effect: send notification email to recipients about the results.
	"""
    if result == '':
        sendMail( '', 'Error occurred during nomura trade conversion'
          , getMailSender(), getMailRecipients()\
          , getMailServer(), getMailTimeout())
    else:
        sendMail( 'result file: {0}'.format(result)
          , 'Successfully performed nomura trade conversion'
          , getMailSender(), getMailRecipients()\
          , getMailServer(), getMailTimeout())
예제 #7
0
def deliverResult(success, failure):
    """
    [List] success, [List] failure => send email notification about the
    status.
    """
    logger.debug('sendMail(): {0}, {1}'.format(success, failure))
    list2string = lambda title, L: '{0}: {1} file(s)'.format(title, len(L)) \
                                   + '\n' \
                                   + '\n'.join(L)
    body = lambda success, failure: list2string('success', success) \
                                    + '\n\n' \
                                    + list2string('failure', failure)

    good = 'Web server backup copy result'
    bad = 'Error occurred during web server backup copy process'
    subject = lambda success, failture: bad if len(success) == 0 or \
                                                len(failure) > 0 \
                                            else good

    sendMail(body(success, failure), subject(success, failure),
             getMailSender(), getMailRecipients(), getMailServer(),
             getMailTimeout())
예제 #8
0
def genPDF(mode=None, conf=None, filename=None):
    #from config import settings
    from report import oraclerpt
    from utils import wechat, mail

    rptsettings = settings.ReportSetting(conf).getReportSetting()

    # 附件文件
    if filename is not None:
        report_filename = filename
    else:
        report_filename = rptsettings['report_filename']

    # 邮件设置信息
    mail_host = rptsettings['mail_host']
    mail_user = rptsettings['mail_user']
    mail_pass = rptsettings['mail_pass']
    mail_sender = rptsettings['mail_sender']
    mail_receiver = rptsettings['mail_receiver']
    mail_subject = rptsettings['mail_subject']
    mail_content = rptsettings['mail_content']

    # 微信企业号文件共享
    corpid = rptsettings['corpid']
    corpsecret = rptsettings['corpsecret']
    #     token = wechat.get_token(corpid, corpsecret)
    tag = rptsettings['tag']
    touser = rptsettings['touser']
    toparty = rptsettings['toparty']
    agentid = rptsettings['agentid']
    subject = rptsettings['subject']
    content = rptsettings['content']

    content_error = rptsettings['content_error']

    status = 0

    try:
        rpt = oraclerpt.OracleReport(settings.ReportSetting(conf),
                                     report_filename)
        if mode is not None:
            rpt.run(mode)
        else:
            rpt.run()
    except Exception as e:
        status = 1
        print(e)
        print('生成PDF巡检报告失败!')

    # 发送信息及附件
    try:
        if status == 1:
            wechat.send_msg(corpid, corpsecret, tag, touser, toparty, agentid,
                            subject, content_error)
        else:
            wechat.send_msg(corpid, corpsecret, tag, touser, toparty, agentid,
                            subject, content)
            wechat.send_file(corpid, corpsecret, tag, touser, toparty, agentid,
                             report_filename)
    except Exception as e:
        print(e)
        print('微信消息及附件发送失败,您可能现在无法连接到互联网!')

    print(status)

    try:
        if status == 1:
            mail.sendMail(mail_host, mail_user, mail_pass, mail_sender,
                          mail_receiver, mail_subject, content_error,
                          report_filename)
        else:
            mail.sendMail(mail_host, mail_user, mail_pass, mail_sender,
                          mail_receiver, mail_subject, mail_content,
                          report_filename)
    except Exception as e:
        print(e)
        print('邮件消息及附件发送失败,您可能现在无法连接到互联网!')
예제 #9
0
def genMonitor(conf=None, mode='alert'):
    from report import monitoring

    from utils import wechat, mail

    rptsettings = settings.ReportSetting(conf).getReportSetting()

    # 邮件设置信息
    mail_host = rptsettings['mail_host']
    mail_user = rptsettings['mail_user']
    mail_pass = rptsettings['mail_pass']
    mail_sender = rptsettings['mail_sender']
    mail_receiver = rptsettings['mail_receiver']
    mail_subject = '数据库监控'
    mail_content = ''

    # 微信企业号文件共享
    corpid = rptsettings['corpid']
    corpsecret = rptsettings['corpsecret']
    #     token = wechat.get_token(corpid, corpsecret)
    tag = rptsettings['tag']
    touser = rptsettings['touser']
    toparty = rptsettings['toparty']
    agentid = rptsettings['agentid']
    subject = rptsettings['subject']
    content = ''

    content_error = ''

    status = 0

    om = monitoring.OracleMonitor().test_connect_oracle()
    for oralist in om:
        content = content + '***********************\n' + '主机名:' + oralist[
            'host'] + '\n' + '实例名称:' + oralist['instance'][
                0] + '\n' + '实例状态:' + oralist['instance'][
                    3] + '\n' + '数据库名:' + oralist['database'][
                        0] + '\n' + '数据状态:' + oralist['database'][
                            2] + '\n' + '可连接性:' + str(
                                oralist['connectability']) + '\n'
        if oralist['instance'][3] != 'OPEN' or oralist['database'][
                2] != 'READ WRITE' or oralist['connectability'] != 1:
            status = 1
            content_error = content_error + '***********************\n' + '主机名:' + oralist[
                'host'] + '\n' + '实例名称:' + oralist['instance'][
                    0] + '\n' + '实例状态:' + oralist['instance'][
                        3] + '\n' + '数据库名:' + oralist['database'][
                            0] + '\n' + '数据状态:' + oralist['database'][
                                2] + '\n' + '可连接性:' + str(
                                    oralist['connectability']) + '\n'

    # 发送信息及附件
    try:
        if mode == 'alert' and status == 1:
            wechat.send_msg(corpid, corpsecret, tag, touser, toparty, agentid,
                            subject, content_error)

        if mode == 'daily':
            wechat.send_msg(corpid, corpsecret, tag, touser, toparty, agentid,
                            subject, content)
    except Exception as e:
        print(e)
        print('微信消息及附件发送失败,您可能现在无法连接到互联网!')

    try:
        if mode == 'alert' and status == 1:
            mail.sendMail(mail_host, mail_user, mail_pass, mail_sender,
                          mail_receiver, mail_subject, content_error)

        if mode == 'daily':
            mail.sendMail(mail_host, mail_user, mail_pass, mail_sender,
                          mail_receiver, mail_subject, content)
    except Exception as e:
        print(e)
        print('邮件消息及附件发送失败,您可能现在无法连接到互联网!')
예제 #10
0
 def handleSendMailSMTP(self, sender, pword, recip, cont, iters):
     """Call the function which actually sends the email."""
     if sendMail(sender, pword, recip, cont, iters):
         messagebox.showinfo("Success", "Your email has been sent")
     else:
         messagebox.showerror("Error", "Please check the values and retry")