调度中心告警邮件发送组件改为 “spring-boot-starter-mail”;

master
xuxueli 6 years ago
parent 715a407544
commit 502e650300
  1. 25
      doc/XXL-JOB官方文档.md
  2. 1
      pom.xml
  3. 15
      xxl-job-admin/pom.xml
  4. 67
      xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java
  5. 26
      xxl-job-admin/src/main/java/com/xxl/job/admin/core/thread/JobFailMonitorHelper.java
  6. 65
      xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java
  7. 14
      xxl-job-admin/src/main/resources/application.properties
  8. 2
      xxl-job-admin/src/main/resources/i18n/message.properties
  9. 2
      xxl-job-admin/src/main/resources/i18n/message_en.properties

@ -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

@ -40,7 +40,6 @@
<commons-exec.version>1.3</commons-exec.version>
<commons-collections4.version>4.2</commons-collections4.version>
<commons-lang3.version>3.8.1</commons-lang3.version>
<commons-email.version>1.5</commons-email.version>
<groovy-all.version>2.5.3</groovy-all.version>
<quartz.version>2.3.0</quartz.version>

@ -69,6 +69,12 @@
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<!-- mail-starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- mybatis-starter:mybatis + mybatis-spring + tomcat-jdbc(default) -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
@ -94,12 +100,9 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<!-- commons-email -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>${commons-email.version}</version>
</dependency>
<!-- quartz :quartz-2.2.3/c3p0-0.9.1.1/slf4j-api-1.6.6 -->
<dependency>

@ -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;
}
}

@ -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 += "<br>TriggerMsg=" + jobLog.getTriggerMsg();
alarmContent += "<br>TriggerMsg=<br>" + jobLog.getTriggerMsg();
}
if (jobLog.getHandleCode()>0 && jobLog.getHandleCode() != ReturnT.SUCCESS_CODE) {
alarmContent += "<br>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);
}
}
}

@ -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;
}
}

@ -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

@ -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=调度失败

@ -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

Loading…
Cancel
Save