告警邮件中展示失败告警信息;

This commit is contained in:
xuxueli 2018-06-24 19:23:30 +08:00
parent 239d3e684c
commit caf3888118
6 changed files with 32 additions and 66 deletions

View File

@ -1215,7 +1215,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
### 6.22 版本 V1.9.2 特性[迭代中]
- 1、[迭代中]支持通过API服务操作任务信息
- 2、[迭代中]任务告警逻辑调整任务调度以及任务回调失败时均推送监控队列。后期考虑通过任务Log字段控制告警状态
- 2、告警邮件中展示失败告警信息
- 3、任务超时控制支持设置任务超时时间任务运行超时的情况下将会主动中断任务
- 4、任务属性枚举 "任务模式、阻塞策略" 国际化优化;
- 5、任务日志表状态字段类型优化
@ -1248,16 +1248,16 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 13、任务依赖增强新增任务类型 "流程任务",流程节点可挂载普通类型任务,承担任务依赖功能。现有子任务模型取消;需要考虑任务依赖死循环问题;
- 14、分片任务某一分片失败支持分片转移
- 15、调度中心触发任务后先推送触发队列异步触发然后立即返回。降低quartz线程占用时长。
- 16、新增API服务 "XxlJobService" 支持通过API服务来维护管理任务信息
- 16、任务告警逻辑调整任务调度以及任务回调失败时均推送监控队列。后期考虑通过任务Log字段控制告警状态
- 17、新增任务默认运行状态任务更新时运行状态保持不变
- 18、告警邮件中展示失败告警信息
- 19、提供多版本执行器不依赖容器版本、不内嵌Jetty版本通过配置executoraddress替换jetty通讯等;
- 20、注册中心支持扩展除默认基于DB之外支持扩展接入第三方注册中心如zk、eureka等
- 21、依赖Core内部国际化处理
- 22、故障转移、失败重试等策略,规范化合并归类
- 23、流程任务,支持参数传递
- 24、SimpleTrigger 支持;
- 25、springboot热部署支持
- 18、提供多版本执行器不依赖容器版本、不内嵌Jetty版本通过配置executoraddress替换jetty通讯
- 19、注册中心支持扩展除默认基于DB之外支持扩展接入第三方注册中心如zk、eureka等;
- 20、依赖Core内部国际化处理
- 21、故障转移、失败重试等策略,规范化合并归类
- 22、流程任务,支持参数传递
- 23、SimpleTrigger 支持
- 24、springboot热部署支持;
## 七、其他

View File

@ -125,10 +125,11 @@ public class JobFailMonitorHelper {
"<table border=\"1\" cellpadding=\"3\" style=\"border-collapse:collapse; width:80%;\" >\n" +
" <thead style=\"font-weight: bold;color: #ffffff;background-color: #ff8c00;\" >" +
" <tr>\n" +
" <td>"+ I18nUtil.getString("jobinfo_field_jobgroup") +"</td>\n" +
" <td>"+ I18nUtil.getString("jobinfo_field_id") +"</td>\n" +
" <td>"+ I18nUtil.getString("jobinfo_field_jobdesc") +"</td>\n" +
" <td>"+ I18nUtil.getString("jobconf_monitor_alarm_title") +"</td>\n" +
" <td width=\"20%\" >"+ I18nUtil.getString("jobinfo_field_jobgroup") +"</td>\n" +
" <td width=\"10%\" >"+ I18nUtil.getString("jobinfo_field_id") +"</td>\n" +
" <td width=\"20%\" >"+ I18nUtil.getString("jobinfo_field_jobdesc") +"</td>\n" +
" <td width=\"10%\" >"+ I18nUtil.getString("jobconf_monitor_alarm_title") +"</td>\n" +
" <td width=\"40%\" >"+ I18nUtil.getString("jobconf_monitor_alarm_content") +"</td>\n" +
" </tr>\n" +
" <thead/>\n" +
" <tbody>\n" +
@ -137,6 +138,7 @@ public class JobFailMonitorHelper {
" <td>{1}</td>\n" +
" <td>{2}</td>\n" +
" <td>"+ I18nUtil.getString("jobconf_monitor_alarm_type") +"</td>\n" +
" <td>{3}</td>\n" +
" </tr>\n" +
" <tbody>\n" +
"</table>";
@ -152,12 +154,24 @@ public class JobFailMonitorHelper {
XxlJobInfo info = XxlJobDynamicScheduler.xxlJobInfoDao.loadById(jobLog.getJobId());
if (info!=null && info.getAlarmEmail()!=null && info.getAlarmEmail().trim().length()>0) {
String alarmContent = "Alarm Job LogId=" + jobLog.getId();
if (jobLog.getTriggerCode() != ReturnT.SUCCESS_CODE) {
alarmContent += "<br>TriggerMsg=" + jobLog.getTriggerMsg();
}
if (jobLog.getHandleCode()>0 && jobLog.getHandleCode() != ReturnT.SUCCESS_CODE) {
alarmContent += "<br>HandleCode=" + jobLog.getHandleMsg();
}
Set<String> emailSet = new HashSet<String>(Arrays.asList(info.getAlarmEmail().split(",")));
for (String email: emailSet) {
XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(Integer.valueOf(info.getJobGroup()));
String title = I18nUtil.getString("jobconf_monitor");
String content = MessageFormat.format(mailBodyTemplate, group!=null?group.getTitle():"null", info.getId(), info.getJobDesc());
String content = MessageFormat.format(mailBodyTemplate,
group!=null?group.getTitle():"null",
info.getId(),
info.getJobDesc(),
alarmContent);
MailUtil.sendMail(email, title, content);
}

View File

@ -215,6 +215,7 @@ jobconf_monitor=调度中心监控报警
jobconf_monitor_detail=监控告警明细
jobconf_monitor_alarm_title=告警类型
jobconf_monitor_alarm_type=调度失败
jobconf_monitor_alarm_content=告警内容
jobconf_trigger_admin_adress=调度机器
jobconf_trigger_exe_regtype=执行器-注册方式
jobconf_trigger_exe_regaddress=执行器-地址列表

View File

@ -215,6 +215,7 @@ jobconf_monitor=Scheduling Center monitor alarm
jobconf_monitor_detail=monitor alarm details
jobconf_monitor_alarm_title=Alarm Type
jobconf_monitor_alarm_type=Trigger Fail
jobconf_monitor_alarm_content=Alarm Content
jobconf_trigger_admin_adress=Trigger machine address
jobconf_trigger_exe_regtype=Execotor-Registry Type
jobconf_trigger_exe_regaddress=Execotor-Registry Address

View File

@ -1,50 +0,0 @@
package com.xxl.job.admin.util;
import com.xxl.job.admin.core.util.MailUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.text.MessageFormat;
/**
* email util test
*
* @author xuxueli 2017-12-22 17:16:23
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
public class MailUtilTest {
@Test
public void mailTest() throws Exception {
String mailBodyTemplate = "<h5>监控告警明细:</span>" +
"<table border=\"1\" cellpadding=\"3\" style=\"border-collapse:collapse; width:80%;\" >\n" +
" <thead style=\"font-weight: bold;color: #ffffff;background-color: #ff8c00;\" >" +
" <tr>\n" +
" <td>执行器</td>\n" +
" <td>任务ID</td>\n" +
" <td>任务描述</td>\n" +
" <td>告警类型</td>\n" +
" </tr>\n" +
" <thead/>\n" +
" <tbody>\n" +
" <tr>\n" +
" <td>{0}</td>\n" +
" <td>{1}</td>\n" +
" <td>{2}</td>\n" +
" <td>调度失败</td>\n" +
" </tr>\n" +
" <tbody>\n" +
"</table>";
String title = "调度中心监控报警";
String content = MessageFormat.format(mailBodyTemplate, "执行器A", "01", "任务A1");
boolean ret = MailUtil.sendMail("931591021@qq.com", title, content);
System.out.println(ret);
}
}

View File

@ -143,7 +143,7 @@ public class JobThread extends Thread{
XxlJobLogger.log("<br>----------- xxl-job job execute timeout");
XxlJobLogger.log(e);
executeResult = new ReturnT<String>(IJobHandler.FAIL_TIMEOUT.getCode(), "job execute timeout " + e.getMessage());
executeResult = new ReturnT<String>(IJobHandler.FAIL_TIMEOUT.getCode(), "job execute timeout ");
} finally {
futureThread.interrupt();
}