diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index b18efa7a..e9a5c270 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -295,19 +295,19 @@ XXL-JOB是一个轻量级分布式任务调度平台,其核心设计目标是 调度中心配置内容说明: ### 调度中心JDBC链接:链接地址请保持和 2.1章节 所创建的调度数据库的地址一致 - xxl.job.db.driverClass=com.mysql.jdbc.Driver - xxl.job.db.url=jdbc:mysql://localhost:3306/xxl-job?useUnicode=true&characterEncoding=UTF-8 - xxl.job.db.user=root - xxl.job.db.password=root_pwd + spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl-job?Unicode=true&characterEncoding=UTF-8 + spring.datasource.username=root + spring.datasource.password=root_pwd + spring.datasource.driver-class-name=com.mysql.jdbc.Driver ### 报警邮箱 - xxl.job.mail.host=smtp.163.com - xxl.job.mail.port=25 - xxl.job.mail.ssl=false - xxl.job.mail.username=ovono802302@163.com - xxl.job.mail.password=asdfzxcv - xxl.job.mail.sendFrom=ovono802302@163.com - xxl.job.mail.sendNick=《任务调度平台XXL-JOB》 + spring.mail.host=smtp.qq.com + spring.mail.port=25 + spring.mail.username=xxx@qq.com + spring.mail.password=xxx + spring.mail.properties.mail.smtp.auth=true + spring.mail.properties.mail.smtp.starttls.enable=true + spring.mail.properties.mail.smtp.starttls.required=true ### 登录账号 xxl.job.login.username=admin @@ -1388,7 +1388,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 5、执行器启动之后jetty停止的问题修复; ### 6.24 版本 v2.0.2 Release Notes[迭代中] -- 1、[迭代中]任务告警逻辑调整:任务调度,以及任务回调失败时,均推送监控队列。考虑通过任务Log字段控制告警状态; +- 1、调度中心告警邮件发送组件改为 “spring-boot-starter-mail”; +- 2、[迭代中]任务告警逻辑调整:任务调度,以及任务回调失败时,均推送监控队列。考虑通过任务Log字段控制告警状态; ### TODO LIST diff --git a/pom.xml b/pom.xml index 9a448fa0..ca4670f0 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,6 @@ 1.3 4.2 3.8.1 - 1.5 2.5.3 2.3.0 diff --git a/xxl-job-admin/pom.xml b/xxl-job-admin/pom.xml index 7a8bedb2..b0139907 100644 --- a/xxl-job-admin/pom.xml +++ b/xxl-job-admin/pom.xml @@ -69,6 +69,12 @@ spring-boot-starter-freemarker + + + org.springframework.boot + spring-boot-starter-mail + + org.mybatis.spring.boot @@ -94,12 +100,9 @@ commons-lang3 ${commons-lang3.version} - - - org.apache.commons - commons-email - ${commons-email.version} - + + + diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java index 727c15d5..4aa2b59e 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java @@ -8,6 +8,7 @@ import com.xxl.job.core.biz.AdminBiz; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import org.springframework.mail.javamail.JavaMailSender; import javax.annotation.Resource; @@ -30,24 +31,6 @@ public class XxlJobAdminConfig implements InitializingBean{ // conf - @Value("${xxl.job.mail.host}") - private String mailHost; - - @Value("${xxl.job.mail.port}") - private String mailPort; - - @Value("${xxl.job.mail.ssl}") - private boolean mailSSL; - - @Value("${xxl.job.mail.username}") - private String mailUsername; - - @Value("${xxl.job.mail.password}") - private String mailPassword; - - @Value("${xxl.job.mail.sendNick}") - private String mailSendNick; - @Value("${xxl.job.login.username}") private String loginUsername; @@ -60,43 +43,23 @@ public class XxlJobAdminConfig implements InitializingBean{ @Value("${xxl.job.accessToken}") private String accessToken; + @Value("${spring.mail.username}") + private String emailUserName; + // dao, service @Resource - public XxlJobLogDao xxlJobLogDao; + private XxlJobLogDao xxlJobLogDao; @Resource - public XxlJobInfoDao xxlJobInfoDao; + private XxlJobInfoDao xxlJobInfoDao; @Resource - public XxlJobRegistryDao xxlJobRegistryDao; + private XxlJobRegistryDao xxlJobRegistryDao; @Resource - public XxlJobGroupDao xxlJobGroupDao; + private XxlJobGroupDao xxlJobGroupDao; @Resource - public AdminBiz adminBiz; - - - public String getMailHost() { - return mailHost; - } - - public String getMailPort() { - return mailPort; - } - - public boolean isMailSSL() { - return mailSSL; - } - - public String getMailUsername() { - return mailUsername; - } - - public String getMailPassword() { - return mailPassword; - } - - public String getMailSendNick() { - return mailSendNick; - } + private AdminBiz adminBiz; + @Resource + private JavaMailSender mailSender; public String getLoginUsername() { return loginUsername; @@ -114,6 +77,10 @@ public class XxlJobAdminConfig implements InitializingBean{ return accessToken; } + public String getEmailUserName() { + return emailUserName; + } + public XxlJobLogDao getXxlJobLogDao() { return xxlJobLogDao; } @@ -134,4 +101,8 @@ public class XxlJobAdminConfig implements InitializingBean{ return adminBiz; } + public JavaMailSender getMailSender() { + return mailSender; + } + } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java index 23fd9fcf..03c614e2 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java @@ -4,16 +4,18 @@ import com.xxl.job.admin.core.conf.XxlJobAdminConfig; import com.xxl.job.admin.core.model.XxlJobGroup; import com.xxl.job.admin.core.model.XxlJobInfo; import com.xxl.job.admin.core.model.XxlJobLog; -import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler; import com.xxl.job.admin.core.trigger.TriggerTypeEnum; import com.xxl.job.admin.core.util.I18nUtil; -import com.xxl.job.admin.core.util.MailUtil; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.IJobHandler; import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.mail.javamail.MimeMessageHelper; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.UnsupportedEncodingException; import java.text.MessageFormat; import java.util.*; import java.util.concurrent.LinkedBlockingQueue; @@ -173,7 +175,7 @@ public class JobFailMonitorHelper { String alarmContent = "Alarm Job LogId=" + jobLog.getId(); if (jobLog.getTriggerCode() != ReturnT.SUCCESS_CODE) { - alarmContent += "
TriggerMsg=" + jobLog.getTriggerMsg(); + alarmContent += "
TriggerMsg=
" + jobLog.getTriggerMsg(); } if (jobLog.getHandleCode()>0 && jobLog.getHandleCode() != ReturnT.SUCCESS_CODE) { alarmContent += "
HandleCode=" + jobLog.getHandleMsg(); @@ -183,6 +185,7 @@ public class JobFailMonitorHelper { for (String email: emailSet) { XxlJobGroup group = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().load(Integer.valueOf(info.getJobGroup())); + String personal = I18nUtil.getString("admin_name_full"); String title = I18nUtil.getString("jobconf_monitor"); String content = MessageFormat.format(mailBodyTemplate, group!=null?group.getTitle():"null", @@ -190,7 +193,22 @@ public class JobFailMonitorHelper { info.getJobDesc(), alarmContent); - MailUtil.sendMail(email, title, content); + + // make mail + try { + MimeMessage mimeMessage = XxlJobAdminConfig.getAdminConfig().getMailSender().createMimeMessage(); + + MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); + helper.setFrom(XxlJobAdminConfig.getAdminConfig().getEmailUserName(), personal); + helper.setTo(email); + helper.setSubject(title); + helper.setText(content, true); + + XxlJobAdminConfig.getAdminConfig().getMailSender().send(mimeMessage); + } catch (UnsupportedEncodingException | MessagingException e) { + logger.error(">>>>>>>>>>> job monitor alarm email send error, JobLogId:{}", jobLog.getId(), e); + } + } } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java deleted file mode 100644 index 7aa11879..00000000 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.xxl.job.admin.core.util; - -import com.xxl.job.admin.core.conf.XxlJobAdminConfig; -import org.apache.commons.mail.DefaultAuthenticator; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.HtmlEmail; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.charset.Charset; - -/** - * 邮件发送.Util - * - * @author xuxueli 2016-3-12 15:06:20 - */ -public class MailUtil { - private static Logger logger = LoggerFactory.getLogger(MailUtil.class); - - /** - * - * @param toAddress 收件人邮箱 - * @param mailSubject 邮件主题 - * @param mailBody 邮件正文 - * @return - */ - public static boolean sendMail(String toAddress, String mailSubject, String mailBody){ - - try { - // Create the email message - HtmlEmail email = new HtmlEmail(); - - //email.setDebug(true); // 将会打印一些log - //email.setTLS(true); // 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验 - //email.setSSL(true); - - email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost()); - - if (XxlJobAdminConfig.getAdminConfig().isMailSSL()) { - email.setSslSmtpPort(XxlJobAdminConfig.getAdminConfig().getMailPort()); - email.setSSLOnConnect(true); - } else { - email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort())); - } - - email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword())); - email.setCharset("UTF-8"); - - email.setFrom(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailSendNick()); - email.addTo(toAddress); - email.setSubject(mailSubject); - email.setMsg(mailBody); - - //email.attach(attachment); // add the attachment - - email.send(); // send the email - return true; - } catch (EmailException e) { - logger.error(e.getMessage(), e); - - } - return false; - } - -} diff --git a/xxl-job-admin/src/main/resources/application.properties b/xxl-job-admin/src/main/resources/application.properties index 81b1b9e1..bccb8e46 100644 --- a/xxl-job-admin/src/main/resources/application.properties +++ b/xxl-job-admin/src/main/resources/application.properties @@ -28,12 +28,14 @@ spring.datasource.tomcat.max-active=30 spring.datasource.tomcat.test-on-borrow=true ### xxl-job email -xxl.job.mail.host=smtp.163.com -xxl.job.mail.port=25 -xxl.job.mail.ssl=false -xxl.job.mail.username=ovono802302@163.com -xxl.job.mail.password=asdfzxcv -xxl.job.mail.sendNick=《任务调度平台XXL-JOB》 +spring.mail.host=smtp.qq.com +spring.mail.port=25 +spring.mail.username=xxx@qq.com +spring.mail.password=xxx +spring.mail.properties.mail.smtp.auth=true +spring.mail.properties.mail.smtp.starttls.enable=true +spring.mail.properties.mail.smtp.starttls.required=true + ### xxl-job login xxl.job.login.username=admin diff --git a/xxl-job-admin/src/main/resources/i18n/message.properties b/xxl-job-admin/src/main/resources/i18n/message.properties index 6938b70c..da643a6a 100644 --- a/xxl-job-admin/src/main/resources/i18n/message.properties +++ b/xxl-job-admin/src/main/resources/i18n/message.properties @@ -209,7 +209,7 @@ jobconf_route_busyover=忙碌转移 jobconf_route_shard=分片广播 jobconf_idleBeat=空闲检测 jobconf_beat=心跳检测 -jobconf_monitor=调度中心监控报警 +jobconf_monitor=任务调度中心监控报警 jobconf_monitor_detail=监控告警明细 jobconf_monitor_alarm_title=告警类型 jobconf_monitor_alarm_type=调度失败 diff --git a/xxl-job-admin/src/main/resources/i18n/message_en.properties b/xxl-job-admin/src/main/resources/i18n/message_en.properties index 5e015553..24f963d2 100644 --- a/xxl-job-admin/src/main/resources/i18n/message_en.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_en.properties @@ -209,7 +209,7 @@ jobconf_route_busyover=Busyover jobconf_route_shard=Sharding Broadcast jobconf_idleBeat=Idle check jobconf_beat=Heartbeats -jobconf_monitor=Scheduling Center monitor alarm +jobconf_monitor=Task Scheduling Center monitor alarm jobconf_monitor_detail=monitor alarm details jobconf_monitor_alarm_title=Alarm Type jobconf_monitor_alarm_type=Trigger Fail