提交 9894cea0 编写于 作者: L leon.li

add contact info when storing and sending alerts

上级 8fc07647
......@@ -192,27 +192,27 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all.add(C(BusinessAlert.class).req(MetricConfigManager.class, ProductLineConfigManager.class,
BaselineService.class, MailSMS.class, BusinessAlertConfig.class, AlertInfo.class, AlertDao.class)//
.req(RemoteMetricReportService.class, BusinessRuleConfigManager.class, DataChecker.class));
.req(RemoteMetricReportService.class, BusinessRuleConfigManager.class, DataChecker.class, ProjectDao.class));
all.add(C(NetworkAlert.class).req(MetricConfigManager.class, ProductLineConfigManager.class,
BaselineService.class, MailSMS.class, NetworkAlertConfig.class, AlertInfo.class, AlertDao.class)//
.req(RemoteMetricReportService.class, NetworkRuleConfigManager.class, DataChecker.class));
.req(RemoteMetricReportService.class, NetworkRuleConfigManager.class, DataChecker.class, ProjectDao.class));
all.add(C(SystemAlert.class).req(MetricConfigManager.class, ProductLineConfigManager.class,
BaselineService.class, MailSMS.class, SystemAlertConfig.class, AlertInfo.class, AlertDao.class)//
.req(RemoteMetricReportService.class, SystemRuleConfigManager.class, DataChecker.class));
.req(RemoteMetricReportService.class, SystemRuleConfigManager.class, DataChecker.class, ProjectDao.class));
all.add(C(AlertExceptionBuilder.class).req(ExceptionConfigManager.class));
all.add(C(ExceptionAlert.class).req(ProjectDao.class, ExceptionAlertConfig.class, MailSMS.class,
ExceptionConfigManager.class, AlertExceptionBuilder.class, AlertDao.class).req(ModelService.class,
TopAnalyzer.ID));
ExceptionConfigManager.class, AlertExceptionBuilder.class, AlertDao.class).req(
ModelService.class, TopAnalyzer.ID));
all.add(C(AlertSummaryExecutor.class).req(AlertSummaryGenerator.class, AlertSummaryManager.class, MailSMS.class)
.req(AlertSummaryDecorator.class, AlertSummaryFTLDecorator.ID));
all.add(C(AlertSummaryDecorator.class,AlertSummaryFTLDecorator.ID,AlertSummaryFTLDecorator.class));
all.add(C(AlertSummaryDecorator.class, AlertSummaryFTLDecorator.ID, AlertSummaryFTLDecorator.class));
all.add(C(AlertSummaryGenerator.class).req(AlertDao.class, TopologyGraphManager.class));
all.add(C(AlertSummaryManager.class).req(AlertSummaryDao.class));
......
......@@ -8,17 +8,17 @@ public class AlertResultEntity {
private String m_content;
private String m_alertType;
private Date m_alertTime;
public AlertResultEntity(){
public AlertResultEntity() {
this.m_isTriggered = false;
this.m_content = "";
this.m_alertType = "";
this.m_alertTime = new Date();
}
public AlertResultEntity(boolean result, String content, String alertType){
public AlertResultEntity(boolean result, String content, String alertType) {
this.m_isTriggered = result;
this.m_content = content;
this.m_alertType = alertType;
......@@ -37,6 +37,10 @@ public class AlertResultEntity {
return m_content;
}
public void setContent(String content) {
this.m_content = content;
}
public boolean isTriggered() {
return m_isTriggered;
}
......
......@@ -22,6 +22,9 @@ import com.dianping.cat.consumer.metric.ProductLineConfigManager;
import com.dianping.cat.consumer.metric.model.entity.MetricItem;
import com.dianping.cat.consumer.metric.model.entity.MetricReport;
import com.dianping.cat.consumer.metric.model.entity.Segment;
import com.dianping.cat.core.dal.Project;
import com.dianping.cat.core.dal.ProjectDao;
import com.dianping.cat.core.dal.ProjectEntity;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.home.dal.report.Alert;
import com.dianping.cat.home.dal.report.AlertDao;
......@@ -32,6 +35,7 @@ import com.dianping.cat.service.ModelPeriod;
import com.dianping.cat.service.ModelRequest;
import com.dianping.cat.system.config.BaseRuleConfigManager;
import com.dianping.cat.system.tool.MailSMS;
import com.site.lookup.util.StringUtils;
public abstract class BaseAlert {
......@@ -62,6 +66,9 @@ public abstract class BaseAlert {
@Inject
protected RemoteMetricReportService m_service;
@Inject
private ProjectDao m_projectDao;
protected static final int DATA_AREADY_MINUTE = 1;
protected static final long DURATION = TimeUtil.ONE_MINUTE;
......@@ -96,6 +103,37 @@ public abstract class BaseAlert {
}
}
private String extractDomain(String metricKey) {
try {
return metricKey.split(":")[0];
} catch (Exception ex) {
Cat.logError("extract domain error:" + metricKey, ex);
return null;
}
}
protected String buildContactInfo(String domainName) {
try {
Project project = m_projectDao.findByDomain(domainName, ProjectEntity.READSET_FULL);
String owners = project.getOwner();
String phones = project.getPhone();
StringBuilder builder = new StringBuilder();
if (!StringUtils.isEmpty(owners)) {
builder.append("[业务负责人: ").append(owners).append(" ]");
}
if (!StringUtils.isEmpty(phones)) {
builder.append("[负责人手机号码: ").append(phones).append(" ]");
}
return builder.toString();
} catch (Exception ex) {
Cat.logError("build contact info error for doamin: " + domainName, ex);
}
return null;
}
private Long buildMillsByString(String time) throws Exception {
String[] times = time.split(":");
int hour = Integer.parseInt(times[0]);
......@@ -244,6 +282,8 @@ public abstract class BaseAlert {
if (alertResult != null && alertResult.isTriggered()) {
String metricTitle = buildMetricTitle(metricKey);
String mailTitle = getAlertConfig().buildMailTitle(productLine.getTitle(), metricTitle);
String contactInfo = buildContactInfo(extractDomain(metricKey));
alertResult.setContent(alertResult.getContent() + contactInfo);
m_alertInfo.addAlertInfo(metricKey, new Date().getTime());
storeAlert(productlineName, metricTitle, mailTitle, alertResult);
......@@ -339,7 +379,7 @@ public abstract class BaseAlert {
}
protected abstract String getName();
protected abstract BaseAlertConfig getAlertConfig();
protected abstract void sendAlertInfo(ProductLine productLine, String mailTitle, String content, String alertType);
......
......@@ -36,7 +36,7 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
public String getName() {
return "business-alert";
}
@Override
public BaseAlertConfig getAlertConfig() {
return m_alertConfig;
......@@ -71,6 +71,8 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
if (alertResult != null && alertResult.isTriggered()) {
String mailTitle = m_alertConfig.buildMailTitle(productLine.getTitle(), config.getTitle());
String contactInfo = buildContactInfo(domain);
alertResult.setContent(alertResult.getContent() + contactInfo);
m_alertInfo.addAlertInfo(metricKey, new Date().getTime());
storeAlert(domain, metric, mailTitle, alertResult);
......
......@@ -125,10 +125,10 @@ public class AlertExceptionBuilder {
return limits;
}
public String buildMailContent(String exceptions, String domain) {
public String buildMailContent(String exceptions, String domain, String contactInfo) {
String content = buildContent(exceptions, domain);
String url = "http://cat.dianpingoa.com/cat/r/p?domain=" + domain;
String mailContent = content + " <a href='" + url + "'>点击此处查看详情</a>";
String mailContent = content + "<br/>" + contactInfo + " <a href='" + url + "'>点击此处查看详情</a>";
return mailContent;
}
......
......@@ -34,6 +34,7 @@ import com.dianping.cat.service.ModelRequest;
import com.dianping.cat.service.ModelResponse;
import com.dianping.cat.system.config.ExceptionConfigManager;
import com.dianping.cat.system.tool.MailSMS;
import com.site.lookup.util.StringUtils;
public class ExceptionAlert implements Task, LogEnabled {
......@@ -86,6 +87,28 @@ public class ExceptionAlert implements Task, LogEnabled {
return topMetric;
}
private String buildContactInfo(String domainName) {
try {
Project project = m_projectDao.findByDomain(domainName, ProjectEntity.READSET_FULL);
String owners = project.getOwner();
String phones = project.getPhone();
StringBuilder builder = new StringBuilder();
if (!StringUtils.isEmpty(owners)) {
builder.append("[业务负责人: ").append(owners).append(" ]");
}
if (!StringUtils.isEmpty(phones)) {
builder.append("[负责人手机号码: ").append(phones).append(" ]");
}
return builder.toString();
} catch (Exception ex) {
Cat.logError("build contact info error for doamin: " + domainName, ex);
}
return null;
}
@Override
public void enableLogging(Logger logger) {
m_logger = logger;
......@@ -179,12 +202,13 @@ public class ExceptionAlert implements Task, LogEnabled {
List<String> phones = m_alertConfig.buildSMSReceivers(project);
String weixins = m_alertConfig.buildWeiXinReceivers(project);
String mailTitle = m_alertConfig.buildMailTitle(domain, null);
String mailContent = m_alertBuilder.buildMailContent(exceptions.toString(), domain);
String contactInfo = buildContactInfo(domain);
String mailContent = m_alertBuilder.buildMailContent(exceptions.toString(), domain, contactInfo);
m_mailSms.sendEmail(mailTitle, mailContent, emails);
m_logger.info(mailTitle + " " + mailContent + " " + emails);
Cat.logEvent("ExceptionAlert", domain, Event.SUCCESS, "[邮件告警] " + mailTitle + " " + mailContent);
m_mailSms.sendWeiXin(mailTitle, mailContent, domain, weixins);
m_logger.info(mailTitle + " " + mailContent + " " + domain + " " + weixins);
Cat.logEvent("ExceptionAlert", domain, Event.SUCCESS, "[微信告警] " + mailTitle + " " + mailContent + " " + domain
......
......@@ -1826,6 +1826,9 @@
<requirement>
<role>com.dianping.cat.report.task.alert.DataChecker</role>
</requirement>
<requirement>
<role>com.dianping.cat.core.dal.ProjectDao</role>
</requirement>
</requirements>
</component>
<component>
......@@ -1862,6 +1865,9 @@
<requirement>
<role>com.dianping.cat.report.task.alert.DataChecker</role>
</requirement>
<requirement>
<role>com.dianping.cat.core.dal.ProjectDao</role>
</requirement>
</requirements>
</component>
<component>
......@@ -1898,6 +1904,9 @@
<requirement>
<role>com.dianping.cat.report.task.alert.DataChecker</role>
</requirement>
<requirement>
<role>com.dianping.cat.core.dal.ProjectDao</role>
</requirement>
</requirements>
</component>
<component>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册