|
@ -8,11 +8,17 @@ |
|
|
|
|
|
|
|
|
package com.epmet.commons.tools.aspect; |
|
|
package com.epmet.commons.tools.aspect; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient; |
|
|
|
|
|
import com.dingtalk.api.DingTalkClient; |
|
|
|
|
|
import com.dingtalk.api.request.OapiRobotSendRequest; |
|
|
|
|
|
import com.dingtalk.api.response.OapiRobotSendResponse; |
|
|
import com.epmet.commons.tools.dto.form.DingTalkTextMsg; |
|
|
import com.epmet.commons.tools.dto.form.DingTalkTextMsg; |
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.SpringContextUtils; |
|
|
import com.epmet.commons.tools.utils.SpringContextUtils; |
|
|
|
|
|
import com.taobao.api.ApiException; |
|
|
import org.apache.logging.log4j.LogManager; |
|
|
import org.apache.logging.log4j.LogManager; |
|
|
import org.apache.logging.log4j.Logger; |
|
|
import org.apache.logging.log4j.Logger; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
@ -35,32 +41,69 @@ public class CustomerApplicationRunner implements ApplicationRunner { |
|
|
private static Logger logger = LogManager.getLogger(CustomerApplicationRunner.class); |
|
|
private static Logger logger = LogManager.getLogger(CustomerApplicationRunner.class); |
|
|
@Value("${spring.application.name}") |
|
|
@Value("${spring.application.name}") |
|
|
private String appName; |
|
|
private String appName; |
|
|
|
|
|
@Value("${server.version}") |
|
|
|
|
|
private String version; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void run(ApplicationArguments args) { |
|
|
public void run(ApplicationArguments args) { |
|
|
//发送启动成功消息
|
|
|
|
|
|
EnvEnum currentEnv = EnvEnum.getCurrentEnv(); |
|
|
EnvEnum currentEnv = EnvEnum.getCurrentEnv(); |
|
|
logger.info(currentEnv); |
|
|
logger.info(currentEnv); |
|
|
if (!EnvEnum.DEV.getCode().equals(currentEnv.getCode()) && !EnvEnum.LOCAL.getCode().equals(currentEnv.getCode())) { |
|
|
if (!EnvEnum.DEV.getCode().equals(currentEnv.getCode()) && !EnvEnum.LOCAL.getCode().equals(currentEnv.getCode())) { |
|
|
InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); |
|
|
//sendDingTextMsg();
|
|
|
String serverIp = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|
|
sendDingMarkDownMsg(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void sendDingTextMsg() { |
|
|
|
|
|
//发送启动成功消息
|
|
|
|
|
|
InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); |
|
|
|
|
|
String serverIp = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|
|
|
|
|
|
|
|
|
|
|
//开发小组 群机器人地址
|
|
|
|
|
|
String url = "https://oapi.dingtalk.com/robot/send?access_token=ffd7c972b0525e249283df1a16b65a8b9d0012601f3a458dfc588c2eac497bb5"; |
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
|
|
|
stringBuilder.append(EnvEnum.getCurrentEnv().getName()) |
|
|
|
|
|
.append("【") |
|
|
|
|
|
.append(appName) |
|
|
|
|
|
.append("】") |
|
|
|
|
|
.append("ip地址: ") |
|
|
|
|
|
.append(serverIp) |
|
|
|
|
|
.append("部署完毕!"); |
|
|
|
|
|
DingTalkTextMsg msg = new DingTalkTextMsg(); |
|
|
|
|
|
msg.setWebHook(url); |
|
|
|
|
|
msg.setAtAll(true); |
|
|
|
|
|
msg.setContent(stringBuilder.toString()); |
|
|
|
|
|
Result<String> stringResult = HttpClientManager.getInstance().sendPostByJSON(url, msg.getMsgContent()); |
|
|
|
|
|
logger.info(stringResult); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getServerIp() { |
|
|
|
|
|
InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class); |
|
|
|
|
|
return inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void sendDingMarkDownMsg() { |
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=ffd7c972b0525e249283df1a16b65a8b9d0012601f3a458dfc588c2eac497bb5"); |
|
|
|
|
|
OapiRobotSendRequest request = new OapiRobotSendRequest(); |
|
|
|
|
|
request.setMsgtype("markdown"); |
|
|
|
|
|
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown(); |
|
|
|
|
|
markdown.setTitle("部署成功通知"); |
|
|
|
|
|
|
|
|
//开发小组 群机器人地址
|
|
|
markdown.setText("部署成功通知 \n" + |
|
|
String url = "https://oapi.dingtalk.com/robot/send?access_token=ffd7c972b0525e249283df1a16b65a8b9d0012601f3a458dfc588c2eac497bb5"; |
|
|
"> 服务:" + appName + "\n\n" + |
|
|
StringBuilder stringBuilder = new StringBuilder(); |
|
|
"> 版本:" + version + "\n\n" + |
|
|
stringBuilder.append(EnvEnum.getCurrentEnv().getName()) |
|
|
"> 环境:" + EnvEnum.getCurrentEnv().getName() + "\n\n" + |
|
|
.append("【") |
|
|
"> IP: " + getServerIp() + "\n\n" |
|
|
.append(appName) |
|
|
); |
|
|
.append("】") |
|
|
request.setMarkdown(markdown); |
|
|
.append("ip地址: ") |
|
|
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); |
|
|
.append(serverIp) |
|
|
at.setIsAtAll(true); |
|
|
.append("部署完毕!"); |
|
|
request.setAt(at); |
|
|
DingTalkTextMsg msg = new DingTalkTextMsg(); |
|
|
try { |
|
|
msg.setWebHook(url); |
|
|
OapiRobotSendResponse execute = client.execute(request); |
|
|
msg.setAtAll(true); |
|
|
logger.info("=====通知结果===>" + JSON.toJSONString(execute)); |
|
|
msg.setContent(stringBuilder.toString()); |
|
|
} catch (ApiException e) { |
|
|
Result<String> stringResult = HttpClientManager.getInstance().sendPostByJSON(url, msg.getMsgContent()); |
|
|
logger.error("sendDingMarkDownMsg exception", e); |
|
|
logger.info(stringResult); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|