配置.env文件
下载pinpoint-docker项目 https://github.com/naver/pinpoint-docker.git
编辑.env文件, 找到batch块,开启定时任务
image
找到mail块,配置smtp邮件服务器地址
image其它配置项不用动
修改邮件推送文件,支持同时推送钉钉
在钉钉群里申请钉钉机器人,取得webhook url
image解压pinpoint-web/build/mail.zip文件
编辑 com/navercorp/pinpoint/web/alarm/AlarmMessageSenderImple.java 文件 文件内容如下
package com.navercorp.pinpoint.web.alarm;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker;
import com.navercorp.pinpoint.web.service.UserGroupService;
import org.apache.hadoop.hbase.shaded.org.apache.http.HttpResponse;
import org.apache.hadoop.hbase.shaded.org.apache.http.HttpStatus;
import org.apache.hadoop.hbase.shaded.org.apache.http.client.HttpClient;
import org.apache.hadoop.hbase.shaded.org.apache.http.client.methods.HttpPost;
import org.apache.hadoop.hbase.shaded.org.apache.http.entity.StringEntity;
import org.apache.hadoop.hbase.shaded.org.apache.http.impl.client.DefaultHttpClient;
import org.apache.hadoop.hbase.shaded.org.apache.http.util.EntityUtils;
public class AlarmMessageSenderImple implements AlarmMessageSender {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private MailSender mailSender;
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
@Autowired
private UserGroupService userGroupService;
@Override
public void sendSms(AlarmChecker checker, int sequenceCount) {
List<String> receivers = userGroupService.selectPhoneNumberOfMember(checker.getuserGroupId());
if (receivers.size() == 0) {
return;
}
for (Object message : checker.getSmsMessage()) {
logger.info("send SMS : {}", message);
// TODO Implement logic for sending SMS
}
}
@Override
public void sendEmail(AlarmChecker checker, int sequenceCount) {
List<String> receivers = userGroupService.selectEmailOfMember(checker.getuserGroupId());
if (receivers.size() == 0) {
return;
}
logger.info("send email : {}", checker.getEmailMessage());
try{
String content = String.format("%s\n\n%s", checker.getEmailMessage(), checker.getRule().getNotes());
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(receivers.toArray(new String [receivers.size()]));
message.setSubject(String.format("[PINPOINT Alarm - %s]", checker.getRule().getApplicationId()));
message.setText(content);
mailSender.send(message);
sendDingTalk(content);
}catch(Exception e){
logger.error("send email error", e);
}
}
private static String WEBHOOK_TOKEN = "https://oapi.dingtalk.com/robot/send?access_token=你的钉钉token";
private static void sendDingTalk(String content) throws Exception{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(WEBHOOK_TOKEN);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
String textMsg = "{ \"msgtype\": \"text\", \"text\": {\"content\": \"" + content + "\"}}";
StringEntity se = new StringEntity(textMsg, "utf-8");
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
String result= EntityUtils.toString(response.getEntity(), "utf-8");
System.out.println(result);
}
}
}
注意将内容中的钉钉token替换成你自己的,然后编译成class文件
注意:
编译必须在pinpoint项目内的web/src/main/java/com/navercorp/pinpoint/web/alarm内进行
重新打包mail.zip
重新构建pinpoint-web
docker build --no-cache -t pinpointdocker/pinpoint-web:1.8.2 .
网友评论