Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
28aa56e9
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
28aa56e9
编写于
7月 23, 2014
作者:
Y
youyong205
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #412 from leonindy/master
refactor alert module
上级
54a5171a
4f31163a
变更
43
显示空白变更内容
内联
并排
Showing
43 changed file
with
777 addition
and
387 deletion
+777
-387
.gitignore
.gitignore
+4
-0
cat-client/src/main/resources/com/dianping/cat/configuration/client/config.xsd
...esources/com/dianping/cat/configuration/client/config.xsd
+1
-2
cat-client/src/main/resources/com/dianping/cat/status/model/status.xsd
...c/main/resources/com/dianping/cat/status/model/status.xsd
+1
-2
cat-home/pom.xml
cat-home/pom.xml
+1
-0
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
...n/java/com/dianping/cat/build/ComponentsConfigurator.java
+17
-9
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
...com/dianping/cat/report/task/alert/AlertResultEntity.java
+0
-7
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
...in/java/com/dianping/cat/report/task/alert/BaseAlert.java
+15
-106
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
...a/com/dianping/cat/report/task/alert/BaseAlertConfig.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/DataChecker.java
.../java/com/dianping/cat/report/task/alert/DataChecker.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
...om/dianping/cat/report/task/alert/DefaultDataChecker.java
+5
-8
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
...ianping/cat/report/task/alert/business/BusinessAlert.java
+8
-13
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlertConfig.java
...g/cat/report/task/alert/business/BusinessAlertConfig.java
+2
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/AlertExceptionBuilder.java
...at/report/task/alert/exception/AlertExceptionBuilder.java
+19
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
...nping/cat/report/task/alert/exception/ExceptionAlert.java
+18
-137
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
...cat/report/task/alert/exception/ExceptionAlertConfig.java
+6
-5
cat-home/src/main/java/com/dianping/cat/report/task/alert/manager/AlertManager.java
.../dianping/cat/report/task/alert/manager/AlertManager.java
+45
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlertConfig.java
...ing/cat/report/task/alert/network/NetworkAlertConfig.java
+2
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/BaseSender.java
...com/dianping/cat/report/task/alert/sender/BaseSender.java
+1
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/ExceptionPostman.java
...anping/cat/report/task/alert/sender/ExceptionPostman.java
+75
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/MailSender.java
...com/dianping/cat/report/task/alert/sender/MailSender.java
+1
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/Postman.java
...va/com/dianping/cat/report/task/alert/sender/Postman.java
+98
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/SmsSender.java
.../com/dianping/cat/report/task/alert/sender/SmsSender.java
+2
-6
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/WeixinSender.java
...m/dianping/cat/report/task/alert/sender/WeixinSender.java
+1
-5
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlertConfig.java
...nping/cat/report/task/alert/system/SystemAlertConfig.java
+2
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/thirdParty/ThirdPartyAlert.java
...ing/cat/report/task/alert/thirdParty/ThirdPartyAlert.java
+1
-1
cat-home/src/main/java/com/dianping/cat/system/config/AlertTypeManager.java
...java/com/dianping/cat/system/config/AlertTypeManager.java
+125
-0
cat-home/src/main/java/com/dianping/cat/system/page/config/Action.java
...main/java/com/dianping/cat/system/page/config/Action.java
+2
-0
cat-home/src/main/java/com/dianping/cat/system/page/config/Handler.java
...ain/java/com/dianping/cat/system/page/config/Handler.java
+14
-0
cat-home/src/main/java/com/dianping/cat/system/page/config/JspFile.java
...ain/java/com/dianping/cat/system/page/config/JspFile.java
+4
-2
cat-home/src/main/java/com/dianping/cat/system/page/config/JspViewer.java
...n/java/com/dianping/cat/system/page/config/JspViewer.java
+2
-0
cat-home/src/main/resources/META-INF/dal/model/alert-type-codegen.xml
.../main/resources/META-INF/dal/model/alert-type-codegen.xml
+21
-0
cat-home/src/main/resources/META-INF/dal/model/alert-type-manifest.xml
...main/resources/META-INF/dal/model/alert-type-manifest.xml
+6
-0
cat-home/src/main/resources/META-INF/dal/model/alert-type-model.xml
...rc/main/resources/META-INF/dal/model/alert-type-model.xml
+25
-0
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+65
-38
cat-home/src/main/resources/META-INF/wizard/model/wizard.xml
cat-home/src/main/resources/META-INF/wizard/model/wizard.xml
+3
-0
cat-home/src/main/resources/config/default-alert-type.xml
cat-home/src/main/resources/config/default-alert-type.xml
+26
-0
cat-home/src/main/webapp/jsp/system/alert/types.jsp
cat-home/src/main/webapp/jsp/system/alert/types.jsp
+54
-0
cat-home/src/main/webapp/jsp/system/configTree.jsp
cat-home/src/main/webapp/jsp/system/configTree.jsp
+2
-1
cat-home/src/test/java/com/dianping/cat/report/alert/RuleConfigTest.java
...st/java/com/dianping/cat/report/alert/RuleConfigTest.java
+20
-5
cat-home/src/test/java/com/dianping/cat/report/alert/summary/AlertSummaryDecorator.java
...nping/cat/report/alert/summary/AlertSummaryDecorator.java
+7
-0
cat-home/src/test/java/com/dianping/cat/report/alert/summary/AlertSummaryStringDecorator.java
...cat/report/alert/summary/AlertSummaryStringDecorator.java
+1
-1
cat-home/src/test/java/com/dianping/cat/report/task/metric/AlertConfigTest.java
.../com/dianping/cat/report/task/metric/AlertConfigTest.java
+47
-27
cat-home/src/test/resources/config/alert-type.xml
cat-home/src/test/resources/config/alert-type.xml
+26
-0
未找到文件。
.gitignore
浏览文件 @
28aa56e9
...
...
@@ -7,3 +7,7 @@
.*
/*.bat
!.travis.yml
cat-client/src/main/resources/com/dianping/cat/configuration/client/config.xsd
cat-client/src/main/resources/com/dianping/cat/status/model/status.xsd
cat-client/src/main/resources/com/dianping/cat/configuration/client/config.xsd
浏览文件 @
28aa56e9
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
elementFormDefault=
"qualified"
attributeFormDefault=
"unqualified"
>
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
elementFormDefault=
"qualified"
attributeFormDefault=
"unqualified"
>
<xs:element
name=
"config"
type=
"ConfigType"
/>
<xs:complexType
name=
"ConfigType"
>
<xs:sequence>
...
...
cat-client/src/main/resources/com/dianping/cat/status/model/status.xsd
浏览文件 @
28aa56e9
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
elementFormDefault=
"qualified"
attributeFormDefault=
"unqualified"
>
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
elementFormDefault=
"qualified"
attributeFormDefault=
"unqualified"
>
<xs:element
name=
"status"
type=
"StatusType"
/>
<xs:complexType
name=
"StatusType"
>
<xs:sequence>
...
...
cat-home/pom.xml
浏览文件 @
28aa56e9
...
...
@@ -161,6 +161,7 @@
${basedir}/src/main/resources/META-INF/dal/model/monitor-rules-manifest.xml,
${basedir}/src/main/resources/META-INF/dal/model/alertconfig-manifest.xml,
${basedir}/src/main/resources/META-INF/dal/model/alertsummary-manifest.xml,
${basedir}/src/main/resources/META-INF/dal/model/alert-type-manifest.xml,
${basedir}/src/main/resources/META-INF/dal/model/thirdParty-manifest.xml,
</manifest>
</configuration>
...
...
cat-home/src/main/java/com/dianping/cat/build/ComponentsConfigurator.java
浏览文件 @
28aa56e9
...
...
@@ -64,9 +64,12 @@ import com.dianping.cat.report.task.alert.business.BusinessAlertConfig;
import
com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder
;
import
com.dianping.cat.report.task.alert.exception.ExceptionAlert
;
import
com.dianping.cat.report.task.alert.exception.ExceptionAlertConfig
;
import
com.dianping.cat.report.task.alert.manager.AlertManager
;
import
com.dianping.cat.report.task.alert.network.NetworkAlert
;
import
com.dianping.cat.report.task.alert.network.NetworkAlertConfig
;
import
com.dianping.cat.report.task.alert.sender.ExceptionPostman
;
import
com.dianping.cat.report.task.alert.sender.MailSender
;
import
com.dianping.cat.report.task.alert.sender.Postman
;
import
com.dianping.cat.report.task.alert.sender.SmsSender
;
import
com.dianping.cat.report.task.alert.sender.WeixinSender
;
import
com.dianping.cat.report.task.alert.summary.AlertSummaryDecorator
;
...
...
@@ -83,6 +86,7 @@ import com.dianping.cat.report.task.product.ProjectUpdateTask;
import
com.dianping.cat.report.view.DomainNavManager
;
import
com.dianping.cat.service.IpService
;
import
com.dianping.cat.system.config.AlertConfigManager
;
import
com.dianping.cat.system.config.AlertTypeManager
;
import
com.dianping.cat.system.config.BugConfigManager
;
import
com.dianping.cat.system.config.BusinessRuleConfigManager
;
import
com.dianping.cat.system.config.ConfigReloadTask
;
...
...
@@ -289,33 +293,37 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
WeixinSender
.
class
).
req
(
MailSMS
.
class
));
all
.
add
(
C
(
AlertManager
.
class
).
req
(
AlertDao
.
class
));
all
.
add
(
C
(
Postman
.
class
).
req
(
ProjectDao
.
class
,
MailSMS
.
class
,
MailSender
.
class
,
WeixinSender
.
class
,
SmsSender
.
class
,
AlertTypeManager
.
class
));
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
,
ProjectDao
.
class
)
.
req
(
MailSender
.
class
,
SmsSender
.
class
,
WeixinSend
er
.
class
));
.
req
(
RemoteMetricReportService
.
class
,
BusinessRuleConfigManager
.
class
,
DataChecker
.
class
)
.
req
(
Postman
.
class
,
AlertManag
er
.
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
,
ProjectDao
.
class
)
.
req
(
MailSender
.
class
,
SmsSender
.
class
,
WeixinSend
er
.
class
));
.
req
(
RemoteMetricReportService
.
class
,
NetworkRuleConfigManager
.
class
,
DataChecker
.
class
)
.
req
(
Postman
.
class
,
AlertManag
er
.
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
,
ProjectDao
.
class
)
.
req
(
MailSender
.
class
,
SmsSender
.
class
,
WeixinSend
er
.
class
));
.
req
(
RemoteMetricReportService
.
class
,
SystemRuleConfigManager
.
class
,
DataChecker
.
class
)
.
req
(
Postman
.
class
,
AlertManag
er
.
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
)
.
req
(
MailSender
.
class
,
SmsSender
.
class
,
WeixinSender
.
class
));
.
req
(
ExceptionAlertConfig
.
class
,
ExceptionConfigManager
.
class
,
AlertExceptionBuilder
.
class
)
.
req
(
ModelService
.
class
,
TopAnalyzer
.
ID
).
req
(
ExceptionPostman
.
class
,
AlertManager
.
class
));
all
.
add
(
C
(
AlertSummaryExecutor
.
class
).
req
(
AlertSummaryGenerator
.
class
,
AlertSummaryManager
.
class
,
MailSMS
.
class
)
.
req
(
AlertSummaryDecorator
.
class
,
AlertSummaryFTLDecorator
.
ID
));
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/AlertResultEntity.java
浏览文件 @
28aa56e9
...
...
@@ -11,13 +11,6 @@ public class AlertResultEntity {
private
Date
m_alertTime
;
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
)
{
this
.
m_isTriggered
=
result
;
this
.
m_content
=
content
;
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
浏览文件 @
28aa56e9
...
...
@@ -9,7 +9,6 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
org.codehaus.plexus.logging.Logger
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.tuple.Pair
;
...
...
@@ -22,25 +21,16 @@ 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
;
import
com.dianping.cat.home.rule.entity.Condition
;
import
com.dianping.cat.home.rule.entity.Config
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.report.baseline.BaselineService
;
import
com.dianping.cat.report.task.alert.sender.BaseSender
;
import
com.dianping.cat.report.task.alert.sender.MailSender
;
import
com.dianping.cat.report.task.alert.sender.SmsSender
;
import
com.dianping.cat.report.task.alert.sender.WeixinSender
;
import
com.dianping.cat.report.task.alert.manager.AlertManager
;
import
com.dianping.cat.report.task.alert.sender.Postman
;
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
{
...
...
@@ -50,9 +40,6 @@ public abstract class BaseAlert {
@Inject
protected
MailSMS
m_mailSms
;
@Inject
protected
AlertDao
m_alertDao
;
@Inject
protected
AlertInfo
m_alertInfo
;
...
...
@@ -72,16 +59,10 @@ public abstract class BaseAlert {
protected
RemoteMetricReportService
m_service
;
@Inject
private
ProjectDao
m_projectDao
;
@Inject
protected
MailSender
m_mailSender
;
@Inject
protected
SmsSender
m_smsSender
;
protected
Postman
m_postman
;
@Inject
protected
WeixinSender
m_weixinSend
er
;
protected
AlertManager
m_alertManag
er
;
protected
static
final
int
DATA_AREADY_MINUTE
=
1
;
...
...
@@ -95,24 +76,11 @@ public abstract class BaseAlert {
protected
Map
<
String
,
MetricReport
>
m_lastReports
=
new
HashMap
<
String
,
MetricReport
>();
private
Alert
buildAlert
(
String
domainName
,
String
metricTitle
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
new
Alert
();
alert
.
setDomain
(
domainName
);
alert
.
setAlertTime
(
alertResult
.
getAlertTime
());
alert
.
setCategory
(
getName
());
alert
.
setType
(
alertResult
.
getAlertType
());
alert
.
setContent
(
mailTitle
+
"<br/>"
+
alertResult
.
getContent
());
alert
.
setMetric
(
metricTitle
);
return
alert
;
}
private
String
buildMetricTitle
(
String
metricKey
)
{
private
String
buildMetricName
(
String
metricKey
)
{
try
{
return
metricKey
.
split
(
":"
)[
2
];
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"get metric
titl
e error:"
+
metricKey
,
ex
);
Cat
.
logError
(
"get metric
nam
e error:"
+
metricKey
,
ex
);
return
null
;
}
}
...
...
@@ -126,28 +94,6 @@ public abstract class BaseAlert {
}
}
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
]);
...
...
@@ -157,7 +103,7 @@ public abstract class BaseAlert {
return
result
;
}
protected
AlertResultEntity
computeAlertInfo
(
int
minute
,
String
product
,
String
metricKey
,
MetricType
type
)
{
protected
List
<
AlertResultEntity
>
computeAlertInfo
(
int
minute
,
String
product
,
String
metricKey
,
MetricType
type
)
{
double
[]
value
=
null
;
double
[]
baseline
=
null
;
List
<
Config
>
configs
=
m_ruleConfigManager
.
queryConfigs
(
product
,
metricKey
,
type
);
...
...
@@ -291,21 +237,18 @@ public abstract class BaseAlert {
private
void
processMetricItem
(
int
minute
,
ProductLine
productLine
,
String
metricKey
)
{
for
(
MetricType
type
:
MetricType
.
values
())
{
String
productlineName
=
productLine
.
getId
();
AlertResultEntity
alertResult
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
List
<
AlertResultEntity
>
alertResults
=
computeAlertInfo
(
minute
,
productlineName
,
metricKey
,
type
);
if
(
alertResult
!=
null
&&
alertResult
.
isTriggered
())
{
String
metricTitle
=
buildMetricTitle
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metricTitle
);
String
domain
=
extractDomain
(
metricKey
);
String
contactInfo
=
buildContactInfo
(
domain
);
alertResult
.
setContent
(
alertResult
.
getContent
()
+
contactInfo
);
String
content
=
alertResult
.
getContent
();
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
m_alertInfo
.
addAlertInfo
(
productlineName
,
metricKey
,
new
Date
().
getTime
());
storeAlert
(
productlineName
,
metricTitle
,
mailTitle
,
alertResult
);
String
metricName
=
buildMetricName
(
metricKey
);
String
mailTitle
=
getAlertConfig
().
buildMailTitle
(
productLine
.
getTitle
(),
metricName
);
m_alertManager
.
storeAlert
(
getName
(),
productlineName
,
metricName
,
mailTitle
,
alertResult
);
String
domain
=
extractDomain
(
metricKey
);
String
configId
=
getAlertConfig
().
getId
();
sendAllAlert
(
productLine
,
domain
,
mailTitle
,
content
,
alertResult
.
getAlertType
(),
configId
);
Cat
.
logEvent
(
configId
,
productlineName
,
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
m_postman
.
sendAlert
(
getAlertConfig
(),
alertResult
,
productLine
,
domain
,
mailTitle
,
configId
);
}
}
}
...
...
@@ -325,26 +268,6 @@ public abstract class BaseAlert {
}
}
protected
boolean
sendAllAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
)
{
boolean
sendResult
=
true
;
BaseSender
[]
senders
=
{
m_mailSender
,
m_weixinSender
};
List
<
String
>
receivers
=
getAlertConfig
().
buildMailReceivers
(
productLine
);
for
(
BaseSender
sender
:
senders
)
{
if
(!
sender
.
sendAlert
(
receivers
,
domain
,
title
,
content
,
alertType
))
{
sendResult
=
false
;
}
}
receivers
=
getAlertConfig
().
buildSMSReceivers
(
productLine
);
if
(!
m_smsSender
.
sendAlert
(
receivers
,
domain
,
title
,
content
,
alertType
))
{
sendResult
=
false
;
}
return
sendResult
;
}
private
double
[]
queryBaseLine
(
int
start
,
int
end
,
String
baseLineKey
,
Date
date
,
MetricType
type
)
{
double
[]
baseline
=
m_baselineService
.
queryHourlyBaseline
(
MetricAnalyzer
.
ID
,
baseLineKey
+
":"
+
type
,
date
);
int
length
=
end
-
start
+
1
;
...
...
@@ -402,20 +325,6 @@ public abstract class BaseAlert {
return
result
;
}
protected
void
storeAlert
(
String
domainName
,
String
metricTitle
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
buildAlert
(
domainName
,
metricTitle
,
mailTitle
,
alertResult
);
try
{
int
count
=
m_alertDao
.
insert
(
alert
);
if
(
count
!=
1
)
{
Cat
.
logError
(
"insert alert error: "
+
alert
.
toString
(),
new
RuntimeException
());
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
protected
abstract
String
getName
();
protected
abstract
BaseAlertConfig
getAlertConfig
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
浏览文件 @
28aa56e9
...
...
@@ -83,7 +83,7 @@ public abstract class BaseAlertConfig {
}
}
p
rotected
abstract
String
buildMailTitle
(
String
artifactName
,
String
configTitl
e
);
p
ublic
abstract
String
buildMailTitle
(
String
artifactName
,
String
metricNam
e
);
public
abstract
String
getId
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/DataChecker.java
浏览文件 @
28aa56e9
...
...
@@ -5,6 +5,6 @@ import java.util.List;
import
com.dianping.cat.home.rule.entity.Condition
;
public
interface
DataChecker
{
public
AlertResultEntity
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
);
public
List
<
AlertResultEntity
>
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
);
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/DefaultDataChecker.java
浏览文件 @
28aa56e9
package
com.dianping.cat.report.task.alert
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.unidal.tuple.Pair
;
...
...
@@ -25,8 +26,8 @@ public class DefaultDataChecker implements DataChecker {
return
result
;
}
public
AlertResultEntity
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
)
{
AlertResultEntity
result
=
new
AlertResultEntity
();
public
List
<
AlertResultEntity
>
checkData
(
double
[]
value
,
double
[]
baseline
,
List
<
Condition
>
conditions
)
{
List
<
AlertResultEntity
>
alertResults
=
new
ArrayList
<
AlertResultEntity
>
();
for
(
Condition
condition
:
conditions
)
{
int
conditionMinute
=
condition
.
getMinute
();
...
...
@@ -37,15 +38,11 @@ public class DefaultDataChecker implements DataChecker {
if
(
condResult
.
getKey
()
==
true
)
{
String
alertType
=
condition
.
getAlertType
();
if
(
alertType
!=
null
&&
alertType
.
equals
(
"error"
))
{
return
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
}
else
{
result
=
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
);
}
alertResults
.
add
(
new
AlertResultEntity
(
condResult
.
getKey
(),
condResult
.
getValue
(),
alertType
));
}
}
return
result
;
return
alertResults
;
}
private
Pair
<
Boolean
,
String
>
checkDataByCondition
(
double
[]
value
,
double
[]
baseline
,
Condition
condition
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
浏览文件 @
28aa56e9
...
...
@@ -13,7 +13,6 @@ import org.unidal.lookup.annotation.Inject;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.advanced.metric.config.entity.MetricItemConfig
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.BaseAlert
;
...
...
@@ -56,29 +55,25 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
String
metric
=
config
.
getMetricKey
();
String
metricKey
=
m_metricConfigManager
.
buildMetricKey
(
domain
,
config
.
getType
(),
metric
);
AlertResultEntity
alertResult
=
null
;
List
<
AlertResultEntity
>
alertResults
=
null
;
if
(
config
.
isShowAvg
())
{
alertResult
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
AVG
);
alertResult
s
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
AVG
);
}
if
(
config
.
isShowCount
())
{
alertResult
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
COUNT
);
alertResult
s
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
COUNT
);
}
if
(
config
.
isShowSum
())
{
alertResult
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
SUM
);
alertResult
s
=
computeAlertInfo
(
minute
,
product
,
metricKey
,
MetricType
.
SUM
);
}
if
(
alertResult
!=
null
&&
alertResult
.
isTriggered
())
{
String
mailTitle
=
m_alertConfig
.
buildMailTitle
(
productLine
.
getTitle
(),
config
.
getTitle
());
String
contactInfo
=
buildContactInfo
(
domain
);
alertResult
.
setContent
(
alertResult
.
getContent
()
+
contactInfo
);
String
content
=
alertResult
.
getContent
();
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
m_alertInfo
.
addAlertInfo
(
product
,
metricKey
,
new
Date
().
getTime
());
storeAlert
(
domain
,
metric
,
mailTitle
,
alertResult
);
String
mailTitle
=
m_alertConfig
.
buildMailTitle
(
productLine
.
getTitle
(),
metric
);
m_alertManager
.
storeAlert
(
getName
(),
product
,
metric
,
mailTitle
,
alertResult
);
String
configId
=
getAlertConfig
().
getId
();
sendAllAlert
(
productLine
,
domain
,
mailTitle
,
content
,
alertResult
.
getAlertType
(),
configId
);
Cat
.
logEvent
(
configId
,
product
,
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
m_postman
.
sendAlert
(
getAlertConfig
(),
alertResult
,
productLine
,
domain
,
mailTitle
,
configId
);
}
}
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlertConfig.java
浏览文件 @
28aa56e9
...
...
@@ -7,11 +7,11 @@ public class BusinessAlertConfig extends BaseAlertConfig {
private
String
m_id
=
"business"
;
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
productlineName
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[业务告警] [产品线 "
).
append
(
productlineName
).
append
(
"]"
);
sb
.
append
(
"[业务指标 "
).
append
(
configTitl
e
).
append
(
"]"
);
sb
.
append
(
"[业务指标 "
).
append
(
metricNam
e
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/AlertExceptionBuilder.java
浏览文件 @
28aa56e9
...
...
@@ -134,12 +134,30 @@ public class AlertExceptionBuilder {
return
mailContent
;
}
public
String
buildContent
(
String
exceptions
,
String
domain
,
String
contactInfo
)
{
public
String
buildDBContent
(
String
exceptions
,
String
domain
)
{
String
content
=
buildContent
(
exceptions
,
domain
);
String
url
=
"http://cat.dianpingoa.com/cat/r/p?domain="
+
domain
;
String
mailContent
=
content
+
"<br/>"
+
" <a href='"
+
url
+
"'>点击此处查看详情</a>"
;
return
mailContent
;
}
public
String
buildContent
(
String
exceptions
,
String
domain
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
).
format
(
new
Date
());
sb
.
append
(
"[CAT异常告警] [项目: "
).
append
(
domain
).
append
(
"] : "
);
sb
.
append
(
exceptions
).
append
(
"[时间: "
).
append
(
time
).
append
(
"]"
);
return
sb
.
toString
();
}
public
String
buildContent
(
String
exceptions
,
String
domain
,
String
contactInfo
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
time
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
).
format
(
new
Date
());
sb
.
append
(
"[CAT异常告警] [项目: "
).
append
(
domain
).
append
(
"] : "
);
sb
.
append
(
exceptions
).
append
(
"[时间: "
).
append
(
time
).
append
(
"]"
).
append
(
"\n"
);
sb
.
append
(
contactInfo
);
return
sb
.
toString
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
浏览文件 @
28aa56e9
...
...
@@ -8,9 +8,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.lookup.annotation.Inject
;
...
...
@@ -18,41 +15,24 @@ import com.dianping.cat.Cat;
import
com.dianping.cat.Constants
;
import
com.dianping.cat.consumer.top.TopAnalyzer
;
import
com.dianping.cat.consumer.top.model.entity.TopReport
;
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
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.dianping.cat.report.page.top.TopMetric
;
import
com.dianping.cat.report.page.top.TopMetric.Item
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder.AlertException
;
import
com.dianping.cat.report.task.alert.sender.MailSender
;
import
com.dianping.cat.report.task.alert.sender.SmsSender
;
import
com.dianping.cat.report.task.alert.sender.WeixinSender
;
import
com.dianping.cat.report.task.alert.manager.AlertManager
;
import
com.dianping.cat.report.task.alert.sender.ExceptionPostman
;
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
{
@Inject
protected
AlertDao
m_alertDao
;
@Inject
private
ProjectDao
m_projectDao
;
public
class
ExceptionAlert
implements
Task
{
@Inject
private
ExceptionAlertConfig
m_alertConfig
;
@Inject
private
MailSMS
m_mailSms
;
@Inject
private
ExceptionConfigManager
m_exceptionConfigManager
;
...
...
@@ -63,33 +43,15 @@ public class ExceptionAlert implements Task, LogEnabled {
private
ModelService
<
TopReport
>
m_topService
;
@Inject
protected
MailSender
m_mailSender
;
@Inject
protected
SmsSender
m_smsSender
;
protected
ExceptionPostman
m_postman
;
@Inject
protected
WeixinSender
m_weixinSend
er
;
protected
AlertManager
m_alertManag
er
;
private
static
final
long
DURATION
=
TimeUtil
.
ONE_MINUTE
;
private
static
final
int
ALERT_PERIOD
=
1
;
private
Logger
m_logger
;
private
Alert
buildAlert
(
String
domainName
,
AlertException
exception
,
String
mailContent
)
{
Alert
alert
=
new
Alert
();
alert
.
setDomain
(
domainName
);
alert
.
setAlertTime
(
new
Date
());
alert
.
setCategory
(
getName
());
alert
.
setType
(
exception
.
getType
());
alert
.
setContent
(
mailContent
);
alert
.
setMetric
(
exception
.
getName
());
return
alert
;
}
private
TopMetric
buildTopMetric
(
Date
date
)
{
TopReport
topReport
=
queryTopReport
(
date
);
TopMetric
topMetric
=
new
TopMetric
(
ALERT_PERIOD
,
Integer
.
MAX_VALUE
,
m_exceptionConfigManager
);
...
...
@@ -99,47 +61,10 @@ 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
;
}
public
String
getName
()
{
return
"exception-alert"
;
}
private
Project
queryProjectByDomain
(
String
projectName
)
{
Project
project
=
null
;
try
{
project
=
m_projectDao
.
findByDomain
(
projectName
,
ProjectEntity
.
READSET_FULL
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
return
project
;
}
private
TopReport
queryTopReport
(
Date
start
)
{
String
domain
=
Constants
.
CAT
;
String
date
=
String
.
valueOf
(
start
.
getTime
());
...
...
@@ -185,7 +110,18 @@ public class ExceptionAlert implements Task, LogEnabled {
for
(
Entry
<
String
,
List
<
AlertException
>>
entry
:
alertExceptions
.
entrySet
())
{
try
{
sendAndStoreAlert
(
entry
.
getKey
(),
entry
.
getValue
());
String
domain
=
entry
.
getKey
();
List
<
AlertException
>
exceptions
=
entry
.
getValue
();
m_postman
.
sendAlert
(
m_alertConfig
,
m_alertBuilder
,
domain
,
exceptions
);
String
mailTitle
=
m_alertConfig
.
buildMailTitle
(
domain
,
null
);
String
content
=
m_alertBuilder
.
buildDBContent
(
exceptions
.
toString
(),
domain
);
for
(
AlertException
exception
:
exceptions
)
{
AlertResultEntity
alertResult
=
new
AlertResultEntity
(
true
,
content
,
exception
.
getType
());
m_alertManager
.
storeAlert
(
getName
(),
domain
,
exception
.
getName
(),
mailTitle
,
alertResult
);
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
...
...
@@ -208,61 +144,6 @@ public class ExceptionAlert implements Task, LogEnabled {
}
}
private
void
sendAndStoreAlert
(
String
domain
,
List
<
AlertException
>
exceptions
)
{
Project
project
=
queryProjectByDomain
(
domain
);
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
project
);
List
<
String
>
phones
=
m_alertConfig
.
buildSMSReceivers
(
project
);
String
weixins
=
m_alertConfig
.
buildWeiXinReceivers
(
project
);
String
mailTitle
=
m_alertConfig
.
buildMailTitle
(
domain
,
null
);
String
contactInfo
=
buildContactInfo
(
domain
);
String
mailContent
=
m_alertBuilder
.
buildMailContent
(
exceptions
.
toString
(),
domain
,
contactInfo
);
storeAlerts
(
domain
,
exceptions
,
mailTitle
+
"<br/>"
+
mailContent
);
m_mailSender
.
sendAlert
(
emails
,
domain
,
mailTitle
,
mailContent
,
"warning"
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[邮件告警] "
+
mailTitle
+
" "
+
mailContent
);
List
<
AlertException
>
errorExceptions
=
m_alertBuilder
.
buildErrorException
(
exceptions
);
if
(!
errorExceptions
.
isEmpty
())
{
String
weixinContent
=
m_alertBuilder
.
buildContent
(
errorExceptions
.
toString
(),
domain
,
contactInfo
);
m_weixinSender
.
sendAlert
(
emails
,
domain
,
mailTitle
,
weixinContent
,
"error"
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[微信告警] "
+
mailTitle
+
" "
+
weixinContent
+
" "
+
domain
+
" "
+
weixins
);
}
List
<
AlertException
>
errorAndTriggeredExceptions
=
m_alertBuilder
.
buildErrorAndTriggeredException
(
exceptions
);
if
(!
errorAndTriggeredExceptions
.
isEmpty
())
{
String
smsContent
=
m_alertBuilder
.
buildContent
(
errorAndTriggeredExceptions
.
toString
(),
domain
,
contactInfo
);
m_smsSender
.
sendAlert
(
phones
,
domain
,
smsContent
,
smsContent
,
"error"
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[短信告警] "
+
smsContent
);
m_mailSms
.
sendWeiXin
(
mailTitle
,
mailContent
,
domain
,
weixins
);
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
Cat
.
logEvent
(
"WeiXinAlert"
,
domain
,
Event
.
SUCCESS
,
"[微信告警] "
+
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
}
}
private
void
storeAlerts
(
String
domain
,
List
<
AlertException
>
exceptions
,
String
mailContent
)
{
for
(
AlertException
exception
:
exceptions
)
{
storeAlert
(
domain
,
exception
,
mailContent
);
}
}
private
void
storeAlert
(
String
domainName
,
AlertException
exception
,
String
mailContent
)
{
Alert
alert
=
buildAlert
(
domainName
,
exception
,
mailContent
);
try
{
int
count
=
m_alertDao
.
insert
(
alert
);
if
(
count
!=
1
)
{
Cat
.
logError
(
"insert alert error: "
+
alert
.
toString
(),
new
RuntimeException
());
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
@Override
public
void
shutdown
()
{
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
浏览文件 @
28aa56e9
package
com.dianping.cat.report.task.alert.exception
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
com.dianping.cat.core.dal.Project
;
...
...
@@ -25,7 +26,7 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
}
}
public
String
buildWeiXinReceivers
(
Project
project
)
{
public
List
<
String
>
buildWeiXinReceivers
(
Project
project
)
{
StringBuilder
builder
=
new
StringBuilder
();
Receiver
receiver
=
m_manager
.
queryReceiverById
(
getId
());
...
...
@@ -38,10 +39,10 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
String
result
=
builder
.
toString
();
if
(
result
.
endsWith
(
","
))
{
return
result
.
substring
(
0
,
result
.
length
()
-
1
);
}
else
{
return
result
;
result
=
result
.
substring
(
0
,
result
.
length
()
-
1
);
}
return
Arrays
.
asList
(
result
.
split
(
","
));
}
}
...
...
@@ -58,7 +59,7 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
}
@Override
public
String
buildMailTitle
(
String
domain
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
domain
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[CAT异常告警] [项目: "
).
append
(
domain
).
append
(
"]"
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/manager/AlertManager.java
0 → 100644
浏览文件 @
28aa56e9
package
com.dianping.cat.report.task.alert.manager
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.home.dal.report.Alert
;
import
com.dianping.cat.home.dal.report.AlertDao
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
public
class
AlertManager
{
@Inject
private
AlertDao
m_alertDao
;
private
Alert
buildAlert
(
String
categoryName
,
String
domainName
,
String
metricName
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
new
Alert
();
alert
.
setDomain
(
domainName
);
alert
.
setAlertTime
(
alertResult
.
getAlertTime
());
alert
.
setCategory
(
categoryName
);
alert
.
setType
(
alertResult
.
getAlertType
());
alert
.
setContent
(
mailTitle
+
"<br/>"
+
alertResult
.
getContent
());
alert
.
setMetric
(
metricName
);
return
alert
;
}
public
void
storeAlert
(
String
categoryName
,
String
domainName
,
String
metricName
,
String
mailTitle
,
AlertResultEntity
alertResult
)
{
Alert
alert
=
buildAlert
(
categoryName
,
domainName
,
metricName
,
mailTitle
,
alertResult
);
try
{
int
count
=
m_alertDao
.
insert
(
alert
);
if
(
count
!=
1
)
{
Cat
.
logError
(
"insert alert error: "
+
alert
.
toString
(),
new
RuntimeException
());
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlertConfig.java
浏览文件 @
28aa56e9
...
...
@@ -7,11 +7,11 @@ public class NetworkAlertConfig extends BaseAlertConfig {
private
String
m_id
=
"network"
;
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
productlineName
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[网络告警] [产品线 "
).
append
(
productlineName
).
append
(
"]"
);
sb
.
append
(
"[网络指标 "
).
append
(
configTitl
e
).
append
(
"]"
);
sb
.
append
(
"[网络指标 "
).
append
(
metricNam
e
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/BaseSender.java
浏览文件 @
28aa56e9
...
...
@@ -17,8 +17,7 @@ public abstract class BaseSender implements LogEnabled {
protected
abstract
void
sendLog
(
String
title
,
String
content
,
List
<
String
>
receivers
);
public
abstract
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
);
public
abstract
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
);
@Override
public
void
enableLogging
(
Logger
logger
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/ExceptionPostman.java
0 → 100644
浏览文件 @
28aa56e9
package
com.dianping.cat.report.task.alert.sender
;
import
java.util.List
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.core.dal.Project
;
import
com.dianping.cat.core.dal.ProjectEntity
;
import
com.dianping.cat.home.alert.type.entity.Type
;
import
com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder
;
import
com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder.AlertException
;
import
com.dianping.cat.report.task.alert.exception.ExceptionAlertConfig
;
public
class
ExceptionPostman
extends
Postman
{
private
Project
queryProjectByDomain
(
String
projectName
)
{
Project
project
=
null
;
try
{
project
=
m_projectDao
.
findByDomain
(
projectName
,
ProjectEntity
.
READSET_FULL
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
return
project
;
}
public
boolean
sendAlert
(
ExceptionAlertConfig
alertConfig
,
AlertExceptionBuilder
alertBuilder
,
String
domain
,
List
<
AlertException
>
exceptions
)
{
boolean
sendResult
=
true
;
Project
project
=
queryProjectByDomain
(
domain
);
String
mailTitle
=
alertConfig
.
buildMailTitle
(
domain
,
null
);
String
contactInfo
=
buildContactInfo
(
domain
);
Type
type
=
new
Type
();
for
(
AlertException
exception
:
exceptions
)
{
Type
tmpType
=
m_alertTypeManager
.
getType
(
alertConfig
.
getId
(),
domain
,
exception
.
getType
());
if
(
tmpType
.
isSendMail
())
{
type
.
setSendMail
(
true
);
}
if
(
tmpType
.
isSendWeixin
())
{
type
.
setSendWeixin
(
true
);
}
if
(
tmpType
.
isSendSms
())
{
type
.
setSendSms
(
true
);
}
}
if
(
type
.
isSendMail
())
{
List
<
String
>
emails
=
alertConfig
.
buildMailReceivers
(
project
);
String
mailContent
=
alertBuilder
.
buildMailContent
(
exceptions
.
toString
(),
domain
,
contactInfo
);
if
(!
m_mailSender
.
sendAlert
(
emails
,
domain
,
mailTitle
,
mailContent
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendWeixin
())
{
List
<
String
>
weixins
=
alertConfig
.
buildWeiXinReceivers
(
project
);
List
<
AlertException
>
errorExceptions
=
alertBuilder
.
buildErrorException
(
exceptions
);
String
weixinContent
=
alertBuilder
.
buildContent
(
errorExceptions
.
toString
(),
domain
,
contactInfo
);
if
(!
m_weixinSender
.
sendAlert
(
weixins
,
domain
,
mailTitle
,
weixinContent
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendSms
())
{
List
<
String
>
phones
=
alertConfig
.
buildSMSReceivers
(
project
);
List
<
AlertException
>
errorAndTriggeredExceptions
=
alertBuilder
.
buildErrorAndTriggeredException
(
exceptions
);
String
smsContent
=
alertBuilder
.
buildContent
(
errorAndTriggeredExceptions
.
toString
(),
domain
,
contactInfo
);
if
(!
m_smsSender
.
sendAlert
(
phones
,
domain
,
mailTitle
,
smsContent
))
{
sendResult
=
false
;
}
}
return
sendResult
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/MailSender.java
浏览文件 @
28aa56e9
...
...
@@ -20,7 +20,7 @@ public class MailSender extends BaseSender {
}
@Override
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
)
{
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
)
{
try
{
m_mailSms
.
sendEmail
(
title
,
content
,
receivers
);
sendLog
(
title
,
content
,
receivers
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/Postman.java
0 → 100644
浏览文件 @
28aa56e9
package
com.dianping.cat.report.task.alert.sender
;
import
java.util.List
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.consumer.company.model.entity.ProductLine
;
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.home.alert.type.entity.Type
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.report.task.alert.AlertResultEntity
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
import
com.dianping.cat.system.config.AlertTypeManager
;
import
com.site.lookup.util.StringUtils
;
public
class
Postman
{
@Inject
protected
ProjectDao
m_projectDao
;
@Inject
protected
MailSender
m_mailSender
;
@Inject
protected
SmsSender
m_smsSender
;
@Inject
protected
WeixinSender
m_weixinSender
;
@Inject
protected
AlertTypeManager
m_alertTypeManager
;
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
;
}
protected
List
<
String
>
queryReceivers
()
{
return
null
;
}
public
boolean
sendAlert
(
BaseAlertConfig
alertConfig
,
AlertResultEntity
alertResult
,
ProductLine
productline
,
String
domain
,
String
mailTitle
,
String
configId
)
{
String
content
=
alertResult
.
getContent
();
String
contactInfo
=
buildContactInfo
(
domain
);
Type
type
=
m_alertTypeManager
.
getType
(
configId
,
domain
,
alertResult
.
getAlertType
());
boolean
sendResult
=
true
;
if
(
type
.
isSendMail
())
{
String
mailContent
=
content
+
"<br/>"
+
contactInfo
;
List
<
String
>
receivers
=
alertConfig
.
buildMailReceivers
(
productline
);
if
(!
m_mailSender
.
sendAlert
(
receivers
,
domain
,
mailTitle
,
mailContent
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendWeixin
())
{
String
weixinContent
=
content
+
"\n"
+
contactInfo
;
List
<
String
>
receivers
=
alertConfig
.
buildMailReceivers
(
productline
);
if
(!
m_weixinSender
.
sendAlert
(
receivers
,
domain
,
mailTitle
,
weixinContent
))
{
sendResult
=
false
;
}
}
if
(
type
.
isSendSms
())
{
String
smsContent
=
content
+
contactInfo
;
List
<
String
>
receivers
=
alertConfig
.
buildSMSReceivers
(
productline
);
if
(!
m_smsSender
.
sendAlert
(
receivers
,
domain
,
mailTitle
,
smsContent
))
{
sendResult
=
false
;
}
}
Cat
.
logEvent
(
configId
,
productline
.
getId
(),
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
return
sendResult
;
}
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/SmsSender.java
浏览文件 @
28aa56e9
...
...
@@ -20,11 +20,7 @@ public class SmsSender extends BaseSender {
}
@Override
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
)
{
if
(
alertType
==
null
||
!
alertType
.
equals
(
"error"
))
{
return
true
;
}
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
)
{
try
{
m_mailSms
.
sendSms
(
title
,
content
,
receivers
);
sendLog
(
title
,
content
,
receivers
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/WeixinSender.java
浏览文件 @
28aa56e9
...
...
@@ -19,11 +19,7 @@ public class WeixinSender extends BaseSender {
}
@Override
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
,
String
alertType
)
{
if
(
alertType
==
null
||
!
alertType
.
equals
(
"error"
))
{
return
true
;
}
public
boolean
sendAlert
(
List
<
String
>
receivers
,
String
domain
,
String
title
,
String
content
)
{
try
{
content
=
content
.
replaceAll
(
"<br/>"
,
"\n"
);
m_mailSms
.
sendWeiXin
(
title
,
content
,
domain
,
mergeList
(
receivers
));
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlertConfig.java
浏览文件 @
28aa56e9
...
...
@@ -7,11 +7,11 @@ public class SystemAlertConfig extends BaseAlertConfig {
private
String
m_id
=
"system"
;
@Override
public
String
buildMailTitle
(
String
productlineName
,
String
configTitl
e
)
{
public
String
buildMailTitle
(
String
productlineName
,
String
metricNam
e
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"[系统告警] [产品线 "
).
append
(
productlineName
).
append
(
"]"
);
sb
.
append
(
"[系统指标 "
).
append
(
configTitl
e
).
append
(
"]"
);
sb
.
append
(
"[系统指标 "
).
append
(
metricNam
e
).
append
(
"]"
);
return
sb
.
toString
();
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/thirdParty/ThirdPartyAlert.java
浏览文件 @
28aa56e9
...
...
@@ -154,7 +154,7 @@ public class ThirdPartyAlert implements Task, LogEnabled {
String
mailTitle
=
buildMailTitle
(
domain
);
String
mailContent
=
buildMailContent
(
entities
.
toString
(),
domain
);
m_mailSender
.
sendAlert
(
emails
,
domain
,
mailTitle
,
mailContent
,
"warning"
);
m_mailSender
.
sendAlert
(
emails
,
domain
,
mailTitle
,
mailContent
);
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
emails
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[邮件告警] "
+
mailTitle
+
" "
+
mailContent
);
}
...
...
cat-home/src/main/java/com/dianping/cat/system/config/AlertTypeManager.java
0 → 100644
浏览文件 @
28aa56e9
package
com.dianping.cat.system.config
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.unidal.dal.jdbc.DalNotFoundException
;
import
org.unidal.helper.Files
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.core.config.Config
;
import
com.dianping.cat.core.config.ConfigDao
;
import
com.dianping.cat.core.config.ConfigEntity
;
import
com.dianping.cat.home.alert.type.entity.AlertType
;
import
com.dianping.cat.home.alert.type.entity.Category
;
import
com.dianping.cat.home.alert.type.entity.Domain
;
import
com.dianping.cat.home.alert.type.entity.Type
;
import
com.dianping.cat.home.alert.type.transform.DefaultSaxParser
;
public
class
AlertTypeManager
implements
Initializable
{
@Inject
private
ConfigDao
m_configDao
;
private
int
m_configId
;
private
AlertType
m_config
;
private
static
final
String
CONFIG_NAME
=
"alertType"
;
private
static
final
String
DEFAULT_TYPE
=
"default"
;
public
AlertType
getAlertType
()
{
return
m_config
;
}
public
Type
getType
(
String
categoryName
,
String
domainName
,
String
typeName
)
{
try
{
Category
category
=
m_config
.
findCategory
(
categoryName
);
Domain
domain
=
category
.
findDomain
(
domainName
);
if
(
domain
==
null
)
{
domain
=
category
.
findDomain
(
DEFAULT_TYPE
);
}
Type
type
=
domain
.
findType
(
typeName
);
if
(
type
==
null
)
{
type
=
generateDefaultType
();
}
return
type
;
}
catch
(
Exception
ex
)
{
return
generateDefaultType
();
}
}
private
Type
generateDefaultType
()
{
Type
type
=
new
Type
();
type
.
setSendMail
(
true
);
type
.
setSendWeixin
(
true
);
type
.
setSendSms
(
false
);
return
type
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
try
{
Config
config
=
m_configDao
.
findByName
(
CONFIG_NAME
,
ConfigEntity
.
READSET_FULL
);
String
content
=
config
.
getContent
();
m_configId
=
config
.
getId
();
m_config
=
DefaultSaxParser
.
parse
(
content
);
}
catch
(
DalNotFoundException
e
)
{
try
{
String
content
=
Files
.
forIO
().
readFrom
(
this
.
getClass
().
getResourceAsStream
(
"/config/default-alert-type.xml"
),
"utf-8"
);
Config
config
=
m_configDao
.
createLocal
();
config
.
setName
(
CONFIG_NAME
);
config
.
setContent
(
content
);
m_configDao
.
insert
(
config
);
m_configId
=
config
.
getId
();
m_config
=
DefaultSaxParser
.
parse
(
content
);
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
ex
);
}
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
if
(
m_config
==
null
)
{
m_config
=
new
AlertType
();
}
}
public
boolean
insert
(
String
xml
)
{
try
{
m_config
=
DefaultSaxParser
.
parse
(
xml
);
return
storeConfig
();
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
return
false
;
}
}
private
boolean
storeConfig
()
{
synchronized
(
this
)
{
try
{
Config
config
=
m_configDao
.
createLocal
();
config
.
setId
(
m_configId
);
config
.
setKeyId
(
m_configId
);
config
.
setName
(
CONFIG_NAME
);
config
.
setContent
(
m_config
.
toString
());
m_configDao
.
updateByPK
(
config
,
ConfigEntity
.
UPDATESET_FULL
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
return
false
;
}
}
return
true
;
}
}
cat-home/src/main/java/com/dianping/cat/system/page/config/Action.java
浏览文件 @
28aa56e9
...
...
@@ -69,6 +69,8 @@ public enum Action implements org.unidal.web.mvc.Action {
ALERT_DEFAULT_RECEIVERS
(
"alertDefaultReceivers"
),
ALERT_TYPE
(
"alertTypes"
),
EXCEPTION
(
"exception"
),
EXCEPTION_THRESHOLD_UPDATE
(
"exceptionThresholdUpdate"
),
...
...
cat-home/src/main/java/com/dianping/cat/system/page/config/Handler.java
浏览文件 @
28aa56e9
...
...
@@ -47,6 +47,7 @@ import com.dianping.cat.report.service.ReportService;
import
com.dianping.cat.report.view.DomainNavManager
;
import
com.dianping.cat.system.SystemPage
;
import
com.dianping.cat.system.config.AlertConfigManager
;
import
com.dianping.cat.system.config.AlertTypeManager
;
import
com.dianping.cat.system.config.BugConfigManager
;
import
com.dianping.cat.system.config.BusinessRuleConfigManager
;
import
com.dianping.cat.system.config.DomainGroupConfigManager
;
...
...
@@ -115,6 +116,9 @@ public class Handler implements PageHandler<Context> {
@Inject
private
NetGraphConfigManager
m_netGraphConfigManager
;
@Inject
private
AlertTypeManager
m_alertTypeManager
;
@Inject
private
ThirdPartyConfigManager
m_thirdPartyConfigManager
;
...
...
@@ -391,6 +395,16 @@ public class Handler implements PageHandler<Context> {
}
model
.
setContent
(
m_alertConfigManager
.
getAlertConfig
().
toString
());
break
;
case
ALERT_TYPE:
String
alertTypes
=
payload
.
getContent
();
if
(!
StringUtils
.
isEmpty
(
alertTypes
))
{
model
.
setOpState
(
m_alertTypeManager
.
insert
(
alertTypes
));
}
else
{
model
.
setOpState
(
true
);
}
model
.
setContent
(
m_alertTypeManager
.
getAlertType
().
toString
());
break
;
case
EXCEPTION:
loadExceptionConfig
(
model
);
break
;
...
...
cat-home/src/main/java/com/dianping/cat/system/page/config/JspFile.java
浏览文件 @
28aa56e9
...
...
@@ -43,6 +43,8 @@ public enum JspFile {
ALERT_DEFAULT_RECEIVERS
(
"/jsp/system/defaultReceiver/alertDefaultReceivers.jsp"
),
ALERT_TYPE
(
"/jsp/system/alert/types.jsp"
),
EXCEPTION_THRESHOLD
(
"/jsp/system/exception/exceptionThreshold.jsp"
),
EXCEPTION
(
"/jsp/system/exception/exception.jsp"
),
...
...
cat-home/src/main/java/com/dianping/cat/system/page/config/JspViewer.java
浏览文件 @
28aa56e9
...
...
@@ -82,6 +82,8 @@ public class JspViewer extends BaseJspViewer<SystemPage, Action, Context, Model>
return
JspFile
.
SYSTEM_RULE_CONFIG_UPDATE
.
getPath
();
case
ALERT_DEFAULT_RECEIVERS:
return
JspFile
.
ALERT_DEFAULT_RECEIVERS
.
getPath
();
case
ALERT_TYPE:
return
JspFile
.
ALERT_TYPE
.
getPath
();
// Excepton Config
case
EXCEPTION:
case
EXCEPTION_THRESHOLD_UPDATE_SUBMIT:
...
...
cat-home/src/main/resources/META-INF/dal/model/alert-type-codegen.xml
0 → 100644
浏览文件 @
28aa56e9
<?xml version="1.0" encoding="UTF-8"?>
<model>
<entity
name=
"alert-type"
root=
"true"
>
<entity-ref
name=
"category"
type=
"list"
names=
"categories"
/>
</entity>
<entity
name=
"category"
>
<attribute
name=
"id"
value-type=
"String"
/>
<entity-ref
name=
"domain"
type=
"list"
names=
"domains"
/>
</entity>
<entity
name=
"domain"
>
<attribute
name=
"id"
value-type=
"String"
/>
<entity-ref
name=
"type"
type=
"list"
names=
"types"
/>
</entity>
<entity
name=
"type"
>
<attribute
name=
"id"
value-type=
"String"
/>
<attribute
name=
"sendSms"
value-type=
"boolean"
/>
<attribute
name=
"sendMail"
value-type=
"boolean"
/>
<attribute
name=
"sendWeixin"
value-type=
"boolean"
/>
</entity>
</model>
cat-home/src/main/resources/META-INF/dal/model/alert-type-manifest.xml
0 → 100644
浏览文件 @
28aa56e9
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<file
path=
"alert-type-codegen.xml"
/>
<file
path=
"alert-type-model.xml"
/>
</manifest>
cat-home/src/main/resources/META-INF/dal/model/alert-type-model.xml
0 → 100644
浏览文件 @
28aa56e9
<?xml version="1.0" encoding="UTF-8"?>
<model
model-package=
"com.dianping.cat.home.alert.type"
enable-sax-parser=
"true"
enable-xml-parser=
"true"
enable-xml-builder=
"true"
>
<entity
name=
"alert-type"
root=
"true"
>
<entity-ref
name=
"category"
type=
"map"
names=
"categories"
method-find-or-create=
'true'
/>
</entity>
<entity
name=
"category"
>
<attribute
name=
"id"
value-type=
"String"
key=
"true"
/>
<entity-ref
name=
"domain"
type=
"map"
names=
"domains"
method-find-or-create=
'true'
/>
</entity>
<entity
name=
"domain"
>
<attribute
name=
"id"
value-type=
"String"
key=
"true"
/>
<entity-ref
name=
"type"
type=
"map"
names=
"types"
method-find-or-create=
'true'
/>
</entity>
<entity
name=
"type"
>
<attribute
name=
"id"
value-type=
"String"
key=
"true"
/>
<attribute
name=
"sendSms"
value-type=
"boolean"
/>
<attribute
name=
"sendMail"
value-type=
"boolean"
/>
<attribute
name=
"sendWeixin"
value-type=
"boolean"
/>
</entity>
</model>
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
28aa56e9
...
...
@@ -1873,6 +1873,39 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.report.task.alert.manager.AlertManager
</role>
<implementation>
com.dianping.cat.report.task.alert.manager.AlertManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.report.task.alert.sender.Postman
</role>
<implementation>
com.dianping.cat.report.task.alert.sender.Postman
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.core.dal.ProjectDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.tool.MailSMS
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.MailSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.WeixinSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.SmsSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.config.AlertTypeManager
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.report.task.alert.business.BusinessAlert
</role>
<implementation>
com.dianping.cat.report.task.alert.business.BusinessAlert
</implementation>
...
...
@@ -1908,16 +1941,10 @@
<role>
com.dianping.cat.report.task.alert.DataChecker
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.
core.dal.ProjectDao
</role>
<role>
com.dianping.cat.
report.task.alert.sender.Postman
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.MailSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.SmsSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.WeixinSender
</role>
<role>
com.dianping.cat.report.task.alert.manager.AlertManager
</role>
</requirement>
</requirements>
</component>
...
...
@@ -1956,16 +1983,10 @@
<role>
com.dianping.cat.report.task.alert.DataChecker
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.core.dal.ProjectDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.MailSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.SmsSender
</role>
<role>
com.dianping.cat.report.task.alert.sender.Postman
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.
sender.WeixinSend
er
</role>
<role>
com.dianping.cat.report.task.alert.
manager.AlertManag
er
</role>
</requirement>
</requirements>
</component>
...
...
@@ -2004,16 +2025,10 @@
<role>
com.dianping.cat.report.task.alert.DataChecker
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.
core.dal.ProjectDao
</role>
<role>
com.dianping.cat.
report.task.alert.sender.Postman
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.MailSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.SmsSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.WeixinSender
</role>
<role>
com.dianping.cat.report.task.alert.manager.AlertManager
</role>
</requirement>
</requirements>
</component>
...
...
@@ -2030,36 +2045,24 @@
<role>
com.dianping.cat.report.task.alert.exception.ExceptionAlert
</role>
<implementation>
com.dianping.cat.report.task.alert.exception.ExceptionAlert
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.core.dal.ProjectDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.exception.ExceptionAlertConfig
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.tool.MailSMS
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.config.ExceptionConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.home.dal.report.AlertDao
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
top
</role-hint>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.MailSender
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.sender.SmsSender
</role>
<role>
com.dianping.cat.report.task.alert.sender.ExceptionPostman
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.task.alert.
sender.WeixinSend
er
</role>
<role>
com.dianping.cat.report.task.alert.
manager.AlertManag
er
</role>
</requirement>
</requirements>
</component>
...
...
@@ -4173,6 +4176,9 @@
<requirement>
<role>
com.dianping.cat.system.config.NetGraphConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.config.AlertTypeManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.config.ThirdPartyConfigManager
</role>
</requirement>
...
...
@@ -4244,6 +4250,15 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.system.config.AlertTypeManager
</role>
<implementation>
com.dianping.cat.system.config.AlertTypeManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.core.config.ConfigDao
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.system.config.ThirdPartyConfigManager
</role>
<implementation>
com.dianping.cat.system.config.ThirdPartyConfigManager
</implementation>
...
...
@@ -7970,6 +7985,9 @@
<requirement>
<role>
com.dianping.cat.system.config.NetGraphConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.config.AlertTypeManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.system.config.ThirdPartyConfigManager
</role>
</requirement>
...
...
@@ -8041,6 +8059,15 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.system.config.AlertTypeManager
</role>
<implementation>
com.dianping.cat.system.config.AlertTypeManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.core.config.ConfigDao
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.system.config.ThirdPartyConfigManager
</role>
<implementation>
com.dianping.cat.system.config.ThirdPartyConfigManager
</implementation>
...
...
cat-home/src/main/resources/META-INF/wizard/model/wizard.xml
浏览文件 @
28aa56e9
...
...
@@ -54,6 +54,9 @@
<model
package=
"com.dianping.cat.home.alertsummary"
name=
"alertsummary"
>
<sample-model>
/Users/leon/Desktop/AlertSummary.xml
</sample-model>
</model>
<model
package=
"com.dianping.cat.home.alert.type"
name=
"alert-type"
>
<sample-model>
src/test/resources/config/alert-type.xml
</sample-model>
</model>
<model
package=
"com.dianping.cat.home.alert.thirdParty"
name=
"thirdParty"
>
<sample-model>
src/test/resources/config/thirdParty-config.xml
</sample-model>
</model>
...
...
cat-home/src/main/resources/config/default-alert-type.xml
0 → 100644
浏览文件 @
28aa56e9
<alert-type>
<category
id=
"network"
>
<domain
id=
"default"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"warning"
sendSms=
"false"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
</category>
<category
id=
"exception"
>
<domain
id=
"default"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"warning"
sendSms=
"false"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
</category>
<category
id=
"business"
>
<domain
id=
"default"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"warning"
sendSms=
"false"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
</category>
<category
id=
"system"
>
<domain
id=
"default"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"warning"
sendSms=
"false"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
</category>
</alert-type>
\ No newline at end of file
cat-home/src/main/webapp/jsp/system/alert/types.jsp
0 → 100644
浏览文件 @
28aa56e9
<%@ page
contentType=
"text/html; charset=utf-8"
%>
<%@ taglib
prefix=
"a"
uri=
"/WEB-INF/app.tld"
%>
<%@ taglib
prefix=
"c"
uri=
"http://java.sun.com/jsp/jstl/core"
%>
<%@ taglib
prefix=
"res"
uri=
"http://www.unidal.org/webres"
%>
<%@ taglib
prefix=
"w"
uri=
"http://www.unidal.org/web/core"
%>
<a:body>
<res:useJs
value=
"
${
res
.
js
.
local
[
'jquery.validate.min.js'
]
}
"
target=
"head-js"
/>
<res:useJs
value=
"
${
res
.
js
.
local
[
'dependencyConfig.js'
]
}
"
target=
"head-js"
/>
<res:useJs
value=
"
${
res
.
js
.
local
[
'alarm_js'
]
}
"
target=
"head-js"
/>
<res:useCss
value=
"
${
res
.
css
.
local
[
'select2.css'
]
}
"
target=
"head-css"
/>
<res:useJs
value=
"
${
res
.
js
.
local
[
'select2.min.js'
]
}
"
target=
"head-js"
/>
<div
class=
"row-fluid"
>
<div
class=
"span2"
>
<%@include
file=
"../configTree.jsp"
%>
</div>
<div
class=
"span10"
>
<form
name=
"alertTypes"
id=
"form"
method=
"post"
action=
"${model.pageUri}?op=alertTypes"
onsubmit=
"return validate_form(this)"
>
<h4
class=
"text-center text-error"
id=
"state"
>
</h4>
<h4
class=
"text-center text-error"
>
告警类型
</h4>
<table
class=
"table table-striped table-bordered table-condensed table-hover"
>
<tr>
<td><textarea
name=
"content"
style=
"width: auto"
rows=
"20"
cols=
"150"
>
${model.content}
</textarea></td>
</tr>
<tr>
<td
style=
"text-align: center"
><input
class=
'btn btn-primary'
type=
"submit"
name=
"submit"
id=
"submit"
value=
"提交"
/></td>
</tr>
</table>
</form>
</div>
</div>
</a:body>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
'
#types
'
).
addClass
(
'
active
'
);
var
state
=
'
${model.opState}
'
;
if
(
state
==
'
Success
'
)
{
$
(
'
#state
'
).
html
(
'
操作成功
'
);
}
else
{
$
(
'
#state
'
).
html
(
'
操作失败
'
);
}
setInterval
(
function
()
{
$
(
'
#state
'
).
html
(
'
'
);
},
3000
);
});
</script>
\ No newline at end of file
cat-home/src/main/webapp/jsp/system/configTree.jsp
浏览文件 @
28aa56e9
...
...
@@ -23,6 +23,7 @@
<li
class=
"text-right"
id=
"systemRuleConfigUpdate"
><a
href=
"?op=systemRuleConfigUpdate"
><strong>
系统告警配置
</strong></a></li>
<li
class=
'nav-header'
><h4>
系统默认配置
</h4></li>
<li
class=
"text-right"
id=
"alertDefaultReceivers"
><a
href=
"?op=alertDefaultReceivers"
><strong>
默认告警配置
</strong></a></li>
<li
class=
"text-right"
id=
"types"
><a
href=
"?op=alertTypes"
><strong>
告警类型设置
</strong></a></li>
<li
class=
"text-right"
id=
"bugConfigUpdate"
><a
href=
"?op=bugConfigUpdate"
><strong>
异常类型配置
</strong></a></li>
<li
class=
"text-right"
id=
"domainGroupConfigUpdate"
><a
href=
"?op=domainGroupConfigUpdate"
><strong>
机器分组配置
</strong></a></li>
</ul>
...
...
cat-home/src/test/java/com/dianping/cat/report/alert/RuleConfigTest.java
浏览文件 @
28aa56e9
...
...
@@ -75,13 +75,13 @@ public class RuleConfigTest {
double
[]
baseline7
=
{
200
,
200
};
double
[]
value7
=
{
100
,
100
};
result
=
m_check
.
checkData
(
value7
,
baseline7
,
conditionsMap
.
get
(
"conditionCombination"
));
result
=
extractError
(
m_check
.
checkData
(
value7
,
baseline7
,
conditionsMap
.
get
(
"conditionCombination"
)
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline8
=
{
200
,
200
};
double
[]
value8
=
{
100
,
100
};
result
=
m_check
.
checkData
(
value8
,
baseline8
,
conditionsMap
.
get
(
"subconditionCombination"
));
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
m_check
.
checkData
(
value8
,
baseline8
,
conditionsMap
.
get
(
"subconditionCombination"
)
));
Assert
.
assert
Null
(
result
);
}
@Test
...
...
@@ -92,7 +92,7 @@ public class RuleConfigTest {
double
baseline
[]
=
{
50
,
200
,
200
};
double
value
[]
=
{
50
,
100
,
100
};
AlertResultEntity
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"two-minute"
));
AlertResultEntity
result
=
extractError
(
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"two-minute"
)
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
...
...
@@ -104,7 +104,22 @@ public class RuleConfigTest {
double
baseline
[]
=
{
200
,
350
};
double
value
[]
=
{
100
,
50
};
AlertResultEntity
result
=
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"demo1"
));
AlertResultEntity
result
=
extractError
(
m_check
.
checkData
(
value
,
baseline
,
configMap
.
get
(
"demo1"
)
));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
private
AlertResultEntity
extractError
(
List
<
AlertResultEntity
>
alertResults
)
{
int
length
=
alertResults
.
size
();
if
(
length
==
0
)
{
return
null
;
}
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
if
(
alertResult
.
getAlertType
().
equals
(
"error"
))
{
return
alertResult
;
}
}
return
alertResults
.
get
(
length
-
1
);
}
}
cat-home/src/test/java/com/dianping/cat/report/alert/summary/AlertSummaryDecorator.java
0 → 100644
浏览文件 @
28aa56e9
package
com.dianping.cat.report.alert.summary
;
import
com.dianping.cat.home.alert.summary.entity.AlertSummary
;
public
interface
AlertSummaryDecorator
{
public
String
generateHtml
(
AlertSummary
alertSummary
);
}
cat-home/src/
main/java/com/dianping/cat/report/task
/alert/summary/AlertSummaryStringDecorator.java
→
cat-home/src/
test/java/com/dianping/cat/report
/alert/summary/AlertSummaryStringDecorator.java
浏览文件 @
28aa56e9
package
com.dianping.cat.report.
task.
alert.summary
;
package
com.dianping.cat.report.alert.summary
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
...
...
cat-home/src/test/java/com/dianping/cat/report/task/metric/AlertConfigTest.java
浏览文件 @
28aa56e9
...
...
@@ -94,60 +94,60 @@ public class AlertConfigTest {
double
baseline
[]
=
{
100
,
100
};
double
value
[]
=
{
200
,
200
};
AlertResultEntity
result
=
alertConfig
.
checkData
(
value
,
baseline
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
AlertResultEntity
result
=
extractError
(
alertConfig
.
checkData
(
value
,
baseline
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline2
=
{
100
,
100
};
double
[]
value2
=
{
49
,
49
};
result
=
alertConfig
.
checkData
(
value2
,
baseline2
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value2
,
baseline2
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline3
=
{
100
,
100
};
double
[]
value3
=
{
51
,
49
};
result
=
alertConfig
.
checkData
(
value3
,
baseline3
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value3
,
baseline3
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline4
=
{
50
,
50
};
double
[]
value4
=
{
10
,
10
};
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
itemConfig
.
setDecreaseValue
(
41
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
79
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
80
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
itemConfig
.
setDecreaseValue
(
40
);
itemConfig
.
setDecreasePercentage
(
80
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
);
Assert
.
assert
Equals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
alertConfig
.
checkData
(
value4
,
baseline4
,
conditions
)
);
Assert
.
assert
Null
(
result
);
double
[]
baseline5
=
{
117
,
118
};
double
[]
value5
=
{
43
,
48
};
itemConfig
.
setDecreasePercentage
(
50
);
itemConfig
.
setDecreasePercentage
(
50
);
conditions
=
buildConditions
(
convert
(
itemConfig
));
result
=
alertConfig
.
checkData
(
value5
,
baseline5
,
conditions
);
result
=
extractError
(
alertConfig
.
checkData
(
value5
,
baseline5
,
conditions
)
);
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
...
...
@@ -159,7 +159,8 @@ public class AlertConfigTest {
double
baseline
[]
=
{
50
,
200
,
200
};
double
value
[]
=
{
50
,
100
,
100
};
AlertResultEntity
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"two-minute"
)));
AlertResultEntity
result
=
extractError
(
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"two-minute"
))));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
}
...
...
@@ -171,42 +172,61 @@ public class AlertConfigTest {
double
baseline
[]
=
{
200
,
200
};
double
value
[]
=
{
100
,
100
};
AlertResultEntity
result
=
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"decreasePercentage"
)));
AlertResultEntity
result
=
extractError
(
m_checker
.
checkData
(
value
,
baseline
,
buildConditions
(
configMap
.
get
(
"decreasePercentage"
))));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline2
=
{
200
,
300
};
double
[]
value2
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value2
,
baseline2
,
buildConditions
(
configMap
.
get
(
"decreaseValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value2
,
baseline2
,
buildConditions
(
configMap
.
get
(
"decreaseValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline3
=
{
200
,
50
};
double
[]
value3
=
{
400
,
100
};
result
=
m_checker
.
checkData
(
value3
,
baseline3
,
buildConditions
(
configMap
.
get
(
"increasePercentage"
)));
result
=
extractError
(
m_checker
.
checkData
(
value3
,
baseline3
,
buildConditions
(
configMap
.
get
(
"increasePercentage"
))));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline4
=
{
200
,
50
};
double
[]
value4
=
{
400
,
100
};
result
=
m_checker
.
checkData
(
value4
,
baseline4
,
buildConditions
(
configMap
.
get
(
"increaseValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value4
,
baseline4
,
buildConditions
(
configMap
.
get
(
"increaseValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline5
=
{
200
,
200
};
double
[]
value5
=
{
500
,
600
};
result
=
m_checker
.
checkData
(
value5
,
baseline5
,
buildConditions
(
configMap
.
get
(
"absoluteMaxValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value5
,
baseline5
,
buildConditions
(
configMap
.
get
(
"absoluteMaxValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline6
=
{
200
,
200
};
double
[]
value6
=
{
50
,
40
};
result
=
m_checker
.
checkData
(
value6
,
baseline6
,
buildConditions
(
configMap
.
get
(
"absoluteMinValue"
)));
result
=
extractError
(
m_checker
.
checkData
(
value6
,
baseline6
,
buildConditions
(
configMap
.
get
(
"absoluteMinValue"
)
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline7
=
{
200
,
200
};
double
[]
value7
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value7
,
baseline7
,
buildConditions
(
configMap
.
get
(
"conditionCombination"
)));
result
=
extractError
(
m_checker
.
checkData
(
value7
,
baseline7
,
buildConditions
(
configMap
.
get
(
"conditionCombination"
))));
Assert
.
assertEquals
(
result
.
isTriggered
(),
true
);
double
[]
baseline8
=
{
200
,
200
};
double
[]
value8
=
{
100
,
100
};
result
=
m_checker
.
checkData
(
value8
,
baseline8
,
buildConditions
(
configMap
.
get
(
"subconditionCombination"
)));
Assert
.
assertEquals
(
result
.
isTriggered
(),
false
);
result
=
extractError
(
m_checker
.
checkData
(
value8
,
baseline8
,
buildConditions
(
configMap
.
get
(
"subconditionCombination"
))));
Assert
.
assertNull
(
result
);
}
private
AlertResultEntity
extractError
(
List
<
AlertResultEntity
>
alertResults
)
{
int
length
=
alertResults
.
size
();
if
(
length
==
0
)
{
return
null
;
}
for
(
AlertResultEntity
alertResult
:
alertResults
)
{
if
(
alertResult
.
getAlertType
().
equals
(
"error"
))
{
return
alertResult
;
}
}
return
alertResults
.
get
(
length
-
1
);
}
}
cat-home/src/test/resources/config/alert-type.xml
0 → 100644
浏览文件 @
28aa56e9
<alert-type>
<category
id=
"network"
>
<domain
id=
"cat"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"warning"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
<domain
id=
"cat"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
<domain
id=
"cat"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
</category>
<category
id=
"exception"
>
<domain
id=
"cat"
>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
<type
id=
"error"
sendSms=
"true"
sendMail=
"true"
sendWeixin=
"true"
/>
</domain>
</category>
</alert-type>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录