Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
210b24e4
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,发现更多精彩内容 >>
提交
210b24e4
编写于
7月 18, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor send alert module
上级
41921fd0
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
195 addition
and
66 deletion
+195
-66
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
...in/java/com/dianping/cat/report/task/alert/BaseAlert.java
+11
-4
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
...a/com/dianping/cat/report/task/alert/BaseAlertConfig.java
+13
-5
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
...ianping/cat/report/task/alert/business/BusinessAlert.java
+6
-19
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
...nping/cat/report/task/alert/exception/ExceptionAlert.java
+2
-2
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlert.java
.../dianping/cat/report/task/alert/network/NetworkAlert.java
+1
-18
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/BaseSender.java
...com/dianping/cat/report/task/alert/sender/BaseSender.java
+161
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlert.java
...om/dianping/cat/report/task/alert/system/SystemAlert.java
+1
-18
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlert.java
浏览文件 @
210b24e4
...
...
@@ -30,7 +30,9 @@ 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.service.ModelPeriod
;
import
com.dianping.cat.service.ModelRequest
;
import
com.dianping.cat.system.config.BaseRuleConfigManager
;
...
...
@@ -69,6 +71,9 @@ public abstract class BaseAlert {
@Inject
private
ProjectDao
m_projectDao
;
@Inject
protected
BaseSender
m_baseSender
;
protected
static
final
int
DATA_AREADY_MINUTE
=
1
;
protected
static
final
long
DURATION
=
TimeUtil
.
ONE_MINUTE
;
...
...
@@ -282,12 +287,16 @@ 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
));
String
domain
=
extractDomain
(
metricKey
);
String
contactInfo
=
buildContactInfo
(
domain
);
alertResult
.
setContent
(
alertResult
.
getContent
()
+
contactInfo
);
String
content
=
alertResult
.
getContent
();
m_alertInfo
.
addAlertInfo
(
productlineName
,
metricKey
,
new
Date
().
getTime
());
storeAlert
(
productlineName
,
metricTitle
,
mailTitle
,
alertResult
);
sendAlertInfo
(
productLine
,
mailTitle
,
alertResult
.
getContent
(),
alertResult
.
getAlertType
());
String
configId
=
getAlertConfig
().
getId
();
m_baseSender
.
sendAllAlert
(
productLine
,
domain
,
mailTitle
,
content
,
alertResult
.
getAlertType
(),
configId
);
Cat
.
logEvent
(
configId
,
productlineName
,
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
}
}
}
...
...
@@ -381,6 +390,4 @@ public abstract class BaseAlert {
protected
abstract
String
getName
();
protected
abstract
BaseAlertConfig
getAlertConfig
();
protected
abstract
void
sendAlertInfo
(
ProductLine
productLine
,
String
mailTitle
,
String
content
,
String
alertType
);
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/BaseAlertConfig.java
浏览文件 @
210b24e4
...
...
@@ -33,9 +33,9 @@ public abstract class BaseAlertConfig {
return
smsReceivers
;
}
public
List
<
String
>
buildMailReceivers
(
ProductLine
productLine
)
{
public
List
<
String
>
buildMailReceivers
(
ProductLine
productLine
,
String
configId
)
{
List
<
String
>
mailReceivers
=
new
ArrayList
<
String
>();
Receiver
receiver
=
m_manager
.
queryReceiverById
(
getId
()
);
Receiver
receiver
=
m_manager
.
queryReceiverById
(
configId
);
if
(
receiver
!=
null
&&
!
receiver
.
isEnable
())
{
return
mailReceivers
;
...
...
@@ -47,6 +47,10 @@ public abstract class BaseAlertConfig {
}
}
public
List
<
String
>
buildMailReceivers
(
ProductLine
productLine
)
{
return
buildMailReceivers
(
productLine
,
getId
());
}
private
List
<
String
>
buildProductlineMailReceivers
(
ProductLine
productLine
)
{
return
split
(
productLine
.
getEmail
());
}
...
...
@@ -55,9 +59,9 @@ public abstract class BaseAlertConfig {
return
split
(
productLine
.
getPhone
());
}
public
List
<
String
>
buildSMSReceivers
(
ProductLine
productLine
)
{
public
List
<
String
>
buildSMSReceivers
(
ProductLine
productLine
,
String
configId
)
{
List
<
String
>
smsReceivers
=
new
ArrayList
<
String
>();
Receiver
receiver
=
m_manager
.
queryReceiverById
(
getId
()
);
Receiver
receiver
=
m_manager
.
queryReceiverById
(
configId
);
if
(
receiver
!=
null
&&
!
receiver
.
isEnable
())
{
return
smsReceivers
;
...
...
@@ -68,7 +72,11 @@ public abstract class BaseAlertConfig {
return
smsReceivers
;
}
}
public
List
<
String
>
buildSMSReceivers
(
ProductLine
productLine
)
{
return
buildSMSReceivers
(
productLine
,
getId
());
}
protected
abstract
String
buildMailTitle
(
String
artifactName
,
String
configTitle
);
public
abstract
String
getId
();
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/business/BusinessAlert.java
浏览文件 @
210b24e4
...
...
@@ -25,8 +25,6 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
@Inject
protected
BusinessAlertConfig
m_alertConfig
;
private
Logger
m_logger
;
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
...
...
@@ -73,10 +71,14 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
String
mailTitle
=
m_alertConfig
.
buildMailTitle
(
productLine
.
getTitle
(),
config
.
getTitle
());
String
contactInfo
=
buildContactInfo
(
domain
);
alertResult
.
setContent
(
alertResult
.
getContent
()
+
contactInfo
);
m_alertInfo
.
addAlertInfo
(
productLine
.
getId
(),
metricKey
,
new
Date
().
getTime
());
String
content
=
alertResult
.
getContent
();
m_alertInfo
.
addAlertInfo
(
product
,
metricKey
,
new
Date
().
getTime
());
storeAlert
(
domain
,
metric
,
mailTitle
,
alertResult
);
sendAlertInfo
(
productLine
,
mailTitle
,
alertResult
.
getContent
(),
alertResult
.
getAlertType
());
String
configId
=
getAlertConfig
().
getId
();
m_baseSender
.
sendAllAlert
(
productLine
,
domain
,
mailTitle
,
content
,
alertResult
.
getAlertType
(),
configId
);
Cat
.
logEvent
(
configId
,
product
,
Event
.
SUCCESS
,
mailTitle
+
" "
+
content
);
}
}
}
...
...
@@ -148,21 +150,6 @@ public class BusinessAlert extends BaseAlert implements Task, LogEnabled {
}
}
@Override
public
void
sendAlertInfo
(
ProductLine
productLine
,
String
title
,
String
content
,
String
alertType
)
{
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
productLine
);
m_logger
.
info
(
title
+
" "
+
content
+
" "
+
emails
);
m_mailSms
.
sendEmail
(
title
,
content
,
emails
);
if
(
alertType
!=
null
&&
alertType
.
equals
(
"error"
))
{
List
<
String
>
phones
=
m_alertConfig
.
buildSMSReceivers
(
productLine
);
m_mailSms
.
sendSms
(
title
+
" "
+
content
,
content
,
phones
);
}
Cat
.
logEvent
(
"MetricAlert"
,
productLine
.
getId
(),
Event
.
SUCCESS
,
title
+
" "
+
content
);
}
@Override
public
void
shutdown
()
{
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
浏览文件 @
210b24e4
...
...
@@ -205,6 +205,8 @@ public class ExceptionAlert implements Task, LogEnabled {
String
contactInfo
=
buildContactInfo
(
domain
);
String
mailContent
=
m_alertBuilder
.
buildMailContent
(
exceptions
.
toString
(),
domain
,
contactInfo
);
storeAlerts
(
domain
,
exceptions
,
mailTitle
+
"<br/>"
+
mailContent
);
m_mailSms
.
sendEmail
(
mailTitle
,
mailContent
,
emails
);
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
emails
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[邮件告警] "
+
mailTitle
+
" "
+
mailContent
);
...
...
@@ -214,8 +216,6 @@ public class ExceptionAlert implements Task, LogEnabled {
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[微信告警] "
+
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
storeAlerts
(
domain
,
exceptions
,
mailTitle
+
"<br/>"
+
mailContent
);
List
<
AlertException
>
errorExceptions
=
m_alertBuilder
.
buildErrorException
(
exceptions
);
if
(!
errorExceptions
.
isEmpty
())
{
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/network/NetworkAlert.java
浏览文件 @
210b24e4
package
com.dianping.cat.report.task.alert.network
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.Map
;
import
org.codehaus.plexus.logging.LogEnabled
;
...
...
@@ -11,7 +10,6 @@ import org.unidal.lookup.annotation.Inject;
import
com.dianping.cat.Cat
;
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.BaseAlert
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
...
...
@@ -30,7 +28,7 @@ public class NetworkAlert extends BaseAlert implements Task, LogEnabled {
public
String
getName
()
{
return
"network-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
...
...
@@ -87,21 +85,6 @@ public class NetworkAlert extends BaseAlert implements Task, LogEnabled {
}
}
@Override
protected
void
sendAlertInfo
(
ProductLine
productLine
,
String
title
,
String
content
,
String
alertType
)
{
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
productLine
);
m_logger
.
info
(
title
+
" "
+
content
+
" "
+
emails
);
m_mailSms
.
sendEmail
(
title
,
content
,
emails
);
if
(
alertType
!=
null
&&
alertType
.
equals
(
"error"
))
{
List
<
String
>
phones
=
m_alertConfig
.
buildSMSReceivers
(
productLine
);
m_mailSms
.
sendSms
(
title
+
" "
+
content
,
content
,
phones
);
}
Cat
.
logEvent
(
"NetworkAlert"
,
productLine
.
getId
(),
Event
.
SUCCESS
,
title
+
" "
+
content
);
}
@Override
public
void
shutdown
()
{
}
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/sender/BaseSender.java
0 → 100644
浏览文件 @
210b24e4
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.report.task.alert.BaseAlertConfig
;
import
com.dianping.cat.system.tool.MailSMS
;
public
enum
BaseSender
{
MailSender
{
@Override
protected
void
logSend
(
String
title
,
String
content
,
List
<
String
>
receivers
)
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
title
).
append
(
","
).
append
(
content
).
append
(
","
);
for
(
String
receiver
:
receivers
)
{
builder
.
append
(
receiver
).
append
(
" "
);
}
Cat
.
logEvent
(
"SendMail"
,
builder
.
toString
());
}
@Override
protected
List
<
String
>
queryReceivers
(
ProductLine
productLine
,
String
configId
)
{
return
m_alertConfig
.
buildMailReceivers
(
productLine
,
configId
);
}
@Override
protected
boolean
sendAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
)
{
try
{
List
<
String
>
receivers
=
queryReceivers
(
productLine
,
configId
);
m_mailSms
.
sendEmail
(
title
,
content
,
receivers
);
logSend
(
title
,
content
,
receivers
);
return
true
;
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"send mail error"
+
productLine
+
" "
+
title
+
" "
+
content
,
ex
);
return
false
;
}
}
},
WeixinSender
{
@Override
protected
void
logSend
(
String
title
,
String
content
,
List
<
String
>
receivers
)
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
title
).
append
(
" "
).
append
(
content
).
append
(
" "
);
for
(
String
receiver
:
receivers
)
{
builder
.
append
(
receiver
).
append
(
" "
);
}
Cat
.
logEvent
(
"SendWeixin"
,
builder
.
toString
());
}
@Override
protected
List
<
String
>
queryReceivers
(
ProductLine
productLine
,
String
configId
)
{
return
m_alertConfig
.
buildMailReceivers
(
productLine
,
configId
);
}
@Override
protected
boolean
sendAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
)
{
if
(
alertType
==
null
||
!
alertType
.
equals
(
"error"
))
{
return
true
;
}
try
{
List
<
String
>
receivers
=
queryReceivers
(
productLine
,
configId
);
m_mailSms
.
sendWeiXin
(
title
,
content
,
domain
,
mergeList
(
receivers
));
logSend
(
title
,
content
,
receivers
);
return
true
;
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"send weixin error"
+
productLine
+
" "
+
title
+
" "
+
content
,
ex
);
return
false
;
}
}
private
String
mergeList
(
List
<
String
>
receivers
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
receiver
:
receivers
)
{
builder
.
append
(
receiver
).
append
(
","
);
}
String
tmpResult
=
builder
.
toString
();
if
(
tmpResult
.
endsWith
(
","
))
{
return
tmpResult
.
substring
(
0
,
tmpResult
.
length
()
-
1
);
}
else
{
return
tmpResult
;
}
}
},
SmsSender
{
@Override
protected
void
logSend
(
String
title
,
String
content
,
List
<
String
>
receivers
)
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
title
).
append
(
" "
).
append
(
content
).
append
(
" "
);
for
(
String
receiver
:
receivers
)
{
builder
.
append
(
receiver
).
append
(
" "
);
}
Cat
.
logEvent
(
"SendSms"
,
builder
.
toString
());
}
@Override
protected
List
<
String
>
queryReceivers
(
ProductLine
productLine
,
String
configId
)
{
return
m_alertConfig
.
buildSMSReceivers
(
productLine
,
configId
);
}
@Override
protected
boolean
sendAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
)
{
if
(
alertType
==
null
||
!
alertType
.
equals
(
"error"
))
{
return
true
;
}
try
{
List
<
String
>
receivers
=
queryReceivers
(
productLine
,
configId
);
m_mailSms
.
sendSms
(
title
,
content
,
receivers
);
logSend
(
title
,
content
,
receivers
);
return
true
;
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"send sms error"
+
productLine
+
" "
+
title
+
" "
+
content
,
ex
);
return
false
;
}
}
};
@Inject
protected
BaseAlertConfig
m_alertConfig
;
@Inject
protected
MailSMS
m_mailSms
;
public
boolean
sendAllAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
)
{
boolean
sendResult
=
true
;
for
(
BaseSender
sender
:
BaseSender
.
values
())
{
if
(!
sender
.
sendAlert
(
productLine
,
domain
,
title
,
content
,
alertType
,
configId
))
{
sendResult
=
false
;
}
}
return
sendResult
;
}
protected
abstract
List
<
String
>
queryReceivers
(
ProductLine
productLine
,
String
configId
);
protected
abstract
void
logSend
(
String
title
,
String
content
,
List
<
String
>
receivers
);
protected
abstract
boolean
sendAlert
(
ProductLine
productLine
,
String
domain
,
String
title
,
String
content
,
String
alertType
,
String
configId
);
}
cat-home/src/main/java/com/dianping/cat/report/task/alert/system/SystemAlert.java
浏览文件 @
210b24e4
package
com.dianping.cat.report.task.alert.system
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.Map
;
import
org.codehaus.plexus.logging.LogEnabled
;
...
...
@@ -11,7 +10,6 @@ import org.unidal.lookup.annotation.Inject;
import
com.dianping.cat.Cat
;
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.BaseAlert
;
import
com.dianping.cat.report.task.alert.BaseAlertConfig
;
...
...
@@ -30,7 +28,7 @@ public class SystemAlert extends BaseAlert implements Task, LogEnabled {
public
String
getName
()
{
return
"system-alert"
;
}
@Override
public
BaseAlertConfig
getAlertConfig
()
{
return
m_alertConfig
;
...
...
@@ -87,21 +85,6 @@ public class SystemAlert extends BaseAlert implements Task, LogEnabled {
}
}
@Override
protected
void
sendAlertInfo
(
ProductLine
productLine
,
String
title
,
String
content
,
String
alertType
)
{
List
<
String
>
emails
=
m_alertConfig
.
buildMailReceivers
(
productLine
);
m_logger
.
info
(
title
+
" "
+
content
+
" "
+
emails
);
m_mailSms
.
sendEmail
(
title
,
content
,
emails
);
if
(
alertType
!=
null
&&
alertType
.
equals
(
"error"
))
{
List
<
String
>
phones
=
m_alertConfig
.
buildSMSReceivers
(
productLine
);
m_mailSms
.
sendSms
(
title
+
" "
+
content
,
content
,
phones
);
}
Cat
.
logEvent
(
"SystemAlert"
,
productLine
.
getId
(),
Event
.
SUCCESS
,
title
+
" "
+
content
);
}
@Override
public
void
shutdown
()
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录