前提
- 我采用的是XXL-JOB+JAVA语言扫库+http调用短信接口
并不是必须跟我一样,只要满足能扫库+能通知就行
代码
- 修改jdbcUrl
- 修改driverClassName
- 修改userName
- 修改password
- 修改smsAlertUrl,以及调整发通知的方式
package com.xxl.job.executor.service.jobhandler;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.toolkit.MapUtils;
import com.baomidou.mybatisplus.toolkit.StringEscape;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.http.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
public class KettleExecuteMonitorJobHandler extends IJobHandler {
public static final ReturnT SUCCESS = new ReturnT<>(null);
public static final ReturnT FAIL = new ReturnT<>(ReturnT.FAIL_CODE, null);
private static final String jdbcUrl = "xxxJdbcUrl";
private static final String driverClassName = "xxxDriver";
private static final String userName = "xxxUserName";
private static final String password = "xxxPassword";
private DruidDataSource dataSource = null;
private JdbcTemplate jdbcTemplate = null;
private int initialSize = 1;
private int minIdle = 1;
private int maxActive = 1;
private int queryTimeout = 3;// seconds
private int maxWait = 12 * 1000;
private Long timeBetweenEvictionRunsMillis = 60 * 1000L;
private Long minEvictableIdleTimeMillis = 5 * 60 * 1000L;
private Boolean useUnfairLock = true;
private Boolean poolPreparedStatements = true;
private Integer maxOpenPreparedStatements = 200;
private String validationQuery = "select 1 from dual;";
private Boolean testOnBorrow = false;
private Boolean testOnReturn = false;
private Boolean testWhileIdle = true;
private String filters = "wall";
private Boolean logAbandoned = true;
//查找错误的步骤日志
private static final String stepQuerySql = "select t.TRANSNAME,t.STEPNAME,t.CHANNEL_ID,to_char(t.log_date,'yyyy-MM-dd HH24:mi:ss') as LOGDATE from t_kettle_step_log t where t.errors >?";
//查询作业通道日志(包含步骤),用作跳板,二次查询转换日志、作业日志
private static final String jobChannelQuerySql = "select t.ROOT_CHANNEL_ID,t.PARENT_CHANNEL_ID from t_kettle_job_channel_log t where t.channel_id=?";
//查询转换日志
private static final String transformationQuerySql = "select t.LOG_FIELD from t_kettle_transformation_log t where t.channel_id=?";
//查询作业日志
private static final String jobQuerySql = "select t.JOBNAME,t.START_JOB_ENTRY,t.EXECUTING_SERVER,t.EXECUTING_USER,t.CLIENT from t_kettle_job_log t where t.channel_id=?";
private static final String smsAlertUrl = "xxxSmsAlertUrl";
private final RestTemplate restTemplate = new RestTemplate();
private final ObjectMapper jackson = new ObjectMapper();
private StopWatch stopWatch = null;
@Override
public ReturnT execute(String param) throws Exception {
List errorLogList = null;
try {
stopWatch = new StopWatch(String.format("%n----------------开始扫描错误日志"));
dataSource = buildDbSource();
jdbcTemplate = new JdbcTemplate(dataSource);
//1、获取存在错误的步骤日志
List
配置定时任务
- 采用XXL-JOB的GLUE(Java)方式
- 编辑代码
报警内容
因为日志内容包含特殊字符,http无法接收,短信对内容长度也有限制,因此详细内容要去到XXL-JOB的调度日志查看
日志表查询和关联关系
select t.*,rowid from t_kettle_job_log t;--作业日志
select t.*,rowid from t_kettle_job_channel_log t;--作业日志通道
select t.*,rowid from t_kettle_transformation_log t;--转换日志
select t.*,rowid from t_kettle_step_log t;--转换步骤日志
-
查询是否有异常的步骤
select t.TRANSNAME,t.STEPNAME,t.CHANNEL_ID,to_char(t.log_date,'yyyy-MM-dd HH24:mi:ss') as LOGDATE from t_kettle_step_log t where t.errors >0;
-
跳板:查询出转换日志id和作业日志id
拿到CHANNEL_ID字段的值,带入查询
select t.ROOT_CHANNEL_ID,t.PARENT_CHANNEL_ID from t_kettle_job_channel_log t where t.channel_id=?;
-
查询详细报错日志
拿到PARENT_CHANNEL_ID字段的值,导入查询
select t.LOG_FIELD from t_kettle_transformation_log t where t.channel_id=?;
-
查询全局性信息
比如日志、所属主机、用户、客户端方式
拿到ROOT_CHANNEL_ID字段的值,导入查询
select t.JOBNAME,t.START_JOB_ENTRY,t.EXECUTING_SERVER,t.EXECUTING_USER,t.CLIENT from t_kettle_job_log t where t.channel_id=?;