|
|
@ -9,10 +9,12 @@ import ch.qos.logback.core.spi.FilterReply; |
|
|
|
import com.epmet.commons.tools.dto.form.DingTalkTextMsg; |
|
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
|
import com.epmet.commons.tools.utils.DingdingMsgSender; |
|
|
|
import com.epmet.commons.tools.utils.IpUtils; |
|
|
|
import com.epmet.commons.tools.utils.SpringContextUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.cloud.commons.util.InetUtils; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
|
|
@ -27,9 +29,11 @@ public class LogMsgSendFilter extends LevelFilter { |
|
|
|
private DingdingMsgSender msgSender = new DingdingMsgSender(); |
|
|
|
private String webHook; |
|
|
|
private String secret; |
|
|
|
private String activeEnv; |
|
|
|
private String appName; |
|
|
|
|
|
|
|
private String activeEnv; |
|
|
|
private String serverIp; |
|
|
|
|
|
|
|
@Override |
|
|
|
public FilterReply decide(ILoggingEvent event) { |
|
|
|
//如果日志级别等于设置的日志级别 则发送消息
|
|
|
@ -46,11 +50,12 @@ public class LogMsgSendFilter extends LevelFilter { |
|
|
|
stringBuilder.append("服务名称:" + appName); |
|
|
|
stringBuilder.append("\n"); |
|
|
|
} |
|
|
|
getServerInfo(); |
|
|
|
if (StringUtils.isNotBlank(activeEnv)) { |
|
|
|
stringBuilder.append("告警环境:" + EnvEnum.getEnum(activeEnv).getName()); |
|
|
|
stringBuilder.append("\n"); |
|
|
|
} |
|
|
|
String serverIp = IpUtils.getServerIp(); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(serverIp)) { |
|
|
|
stringBuilder.append("IP地址:" + serverIp); |
|
|
|
stringBuilder.append("\n"); |
|
|
@ -83,6 +88,26 @@ public class LogMsgSendFilter extends LevelFilter { |
|
|
|
} |
|
|
|
//交给其他filter继续向下处理
|
|
|
|
return super.decide(event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:获取服务 ip及profile信息 |
|
|
|
* |
|
|
|
*/ |
|
|
|
private void getServerInfo() { |
|
|
|
if (serverIp == null) { |
|
|
|
InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); |
|
|
|
serverIp = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|
|
|
} |
|
|
|
if (activeEnv == null) { |
|
|
|
Environment environment = SpringContextUtils.getBean(Environment.class); |
|
|
|
String[] activeProfiles = environment.getActiveProfiles(); |
|
|
|
if (activeProfiles != null && activeProfiles.length > 0) { |
|
|
|
logger.info("activeProfiles:{}", activeProfiles); |
|
|
|
activeEnv = activeProfiles[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void apendStackInfo(StringBuilder stringBuilder, IThrowableProxy throwableProxy) { |
|
|
|