Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
cd6035f3
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,发现更多精彩内容 >>
提交
cd6035f3
编写于
7月 09, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add send weixins for ExceptionAlert
上级
d01caaf7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
109 addition
and
1 deletion
+109
-1
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
...nping/cat/report/task/alert/exception/ExceptionAlert.java
+6
-0
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
...cat/report/task/alert/exception/ExceptionAlertConfig.java
+32
-0
cat-home/src/main/java/com/dianping/cat/system/tool/DefaultMailImpl.java
...in/java/com/dianping/cat/system/tool/DefaultMailImpl.java
+67
-1
cat-home/src/main/java/com/dianping/cat/system/tool/MailSMS.java
...e/src/main/java/com/dianping/cat/system/tool/MailSMS.java
+2
-0
cat-home/src/main/resources/META-INF/dal/model/alertconfig-codegen.xml
...main/resources/META-INF/dal/model/alertconfig-codegen.xml
+1
-0
cat-home/src/main/resources/META-INF/dal/model/alertconfig-model.xml
...c/main/resources/META-INF/dal/model/alertconfig-model.xml
+1
-0
未找到文件。
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlert.java
浏览文件 @
cd6035f3
...
...
@@ -177,6 +177,7 @@ public class ExceptionAlert implements Task, LogEnabled {
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
mailContent
=
m_alertBuilder
.
buildMailContent
(
exceptions
.
toString
(),
domain
);
...
...
@@ -184,6 +185,11 @@ public class ExceptionAlert implements Task, LogEnabled {
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
emails
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[邮件告警] "
+
mailTitle
+
" "
+
mailContent
);
m_mailSms
.
sendWeiXin
(
mailTitle
,
mailContent
,
domain
,
weixins
);
m_logger
.
info
(
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
Cat
.
logEvent
(
"ExceptionAlert"
,
domain
,
Event
.
SUCCESS
,
"[微信告警] "
+
mailTitle
+
" "
+
mailContent
+
" "
+
domain
+
" "
+
weixins
);
storeAlerts
(
domain
,
exceptions
,
mailTitle
+
"<br/>"
+
mailContent
);
List
<
AlertException
>
errorExceptions
=
m_alertBuilder
.
buildErrorException
(
exceptions
);
...
...
cat-home/src/main/java/com/dianping/cat/report/task/alert/exception/ExceptionAlertConfig.java
浏览文件 @
cd6035f3
...
...
@@ -25,6 +25,38 @@ public class ExceptionAlertConfig extends BaseAlertConfig {
}
}
public
String
buildWeiXinReceivers
(
Project
project
)
{
StringBuilder
builder
=
new
StringBuilder
();
Receiver
receiver
=
m_manager
.
queryReceiverById
(
getId
());
if
(
receiver
!=
null
&&
!
receiver
.
isEnable
())
{
return
null
;
}
else
{
builder
.
append
(
buildDefaultWeixinReceivers
(
receiver
));
builder
.
append
(
project
.
getEmail
());
String
result
=
builder
.
toString
();
if
(
result
.
endsWith
(
","
))
{
return
result
.
substring
(
0
,
result
.
length
()
-
1
);
}
else
{
return
result
;
}
}
}
private
String
buildDefaultWeixinReceivers
(
Receiver
receiver
)
{
StringBuilder
builder
=
new
StringBuilder
();
if
(
receiver
!=
null
)
{
for
(
String
weixin
:
receiver
.
getWeixins
())
{
builder
.
append
(
weixin
+
","
);
}
}
return
builder
.
toString
();
}
@Override
public
String
buildMailTitle
(
String
domain
,
String
configTitle
)
{
StringBuilder
sb
=
new
StringBuilder
();
...
...
cat-home/src/main/java/com/dianping/cat/system/tool/DefaultMailImpl.java
浏览文件 @
cd6035f3
package
com.dianping.cat.system.tool
;
import
java.io.BufferedReader
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLEncoder
;
...
...
@@ -43,6 +47,10 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
private
Logger
m_logger
;
private
static
final
String
WEIXIN_URL
=
"http://dpoa-monitorapp-web01.beta/app/monitor/cat/push"
;
private
static
final
String
SUCCESS_TEXT
=
"{\"success\":\"1\"}"
;
private
HtmlEmail
createHtmlEmail
()
throws
EmailException
{
HtmlEmail
email
=
new
HtmlEmail
();
...
...
@@ -151,7 +159,7 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
@Override
public
boolean
sendSms
(
String
title
,
String
content
,
List
<
String
>
phones
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
phone
:
phones
)
{
InputStream
in
=
null
;
try
{
...
...
@@ -180,6 +188,63 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
}
}
@Override
public
boolean
sendWeiXin
(
String
title
,
String
content
,
String
domain
,
String
weixins
)
{
String
urlParameters
=
"domain="
+
domain
+
"&email="
+
weixins
+
"&title="
+
title
+
"&content="
+
content
;
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
WEIXIN_URL
).
openConnection
();
connection
.
setRequestMethod
(
"POST"
);
connection
.
setDoOutput
(
true
);
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
DataOutputStream
wr
=
new
DataOutputStream
(
connection
.
getOutputStream
());
wr
.
writeBytes
(
urlParameters
);
wr
.
flush
();
wr
.
close
();
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
String
inputLine
;
StringBuilder
builder
=
new
StringBuilder
();
while
((
inputLine
=
reader
.
readLine
())
!=
null
)
{
builder
.
append
(
inputLine
);
}
reader
.
close
();
String
responseText
=
builder
.
toString
();
if
(
responseText
.
equals
(
SUCCESS_TEXT
))
{
Cat
.
logEvent
(
"WeiXinSend"
,
"send_success"
,
Event
.
SUCCESS
,
"send success:"
+
domain
+
" "
+
title
+
" "
+
content
+
" "
+
weixins
+
" "
+
responseText
);
return
true
;
}
else
{
Cat
.
logEvent
(
"WeiXinSend"
,
"send_fail"
,
Event
.
SUCCESS
,
"send fail:"
+
domain
+
" "
+
title
+
" "
+
content
+
" "
+
weixins
+
" "
+
responseText
);
return
false
;
}
}
else
{
Cat
.
logEvent
(
"WeiXinSend"
,
"network_fail"
,
Event
.
SUCCESS
,
"network fail:"
+
domain
+
" "
+
title
+
" "
+
content
+
" "
+
weixins
);
return
false
;
}
}
catch
(
Exception
ex
)
{
Cat
.
logEvent
(
"WeiXinSend"
,
"error"
,
Event
.
SUCCESS
,
"error:"
+
domain
+
" "
+
title
+
" "
+
content
+
" "
+
weixins
);
Cat
.
logError
(
"send weixin error:"
+
domain
+
" "
+
title
+
" "
+
content
+
" "
+
weixins
,
ex
);
return
false
;
}
}
public
static
void
main
(
String
[]
args
)
{
boolean
result
=
new
DefaultMailImpl
().
sendWeiXin
(
"test"
,
"test"
,
"test"
,
"tianwen.zhou@dianping.com"
);
System
.
out
.
println
(
result
);
}
public
static
class
Item
{
private
String
m_title
;
...
...
@@ -252,4 +317,5 @@ public class DefaultMailImpl implements MailSMS, Initializable, LogEnabled {
}
}
}
cat-home/src/main/java/com/dianping/cat/system/tool/MailSMS.java
浏览文件 @
cd6035f3
...
...
@@ -9,5 +9,7 @@ public interface MailSMS {
public
boolean
sendEmailByGmail
(
String
title
,
String
content
,
List
<
String
>
emails
);
public
boolean
sendSms
(
String
title
,
String
content
,
List
<
String
>
phones
);
public
boolean
sendWeiXin
(
String
title
,
String
content
,
String
domain
,
String
emails
);
}
cat-home/src/main/resources/META-INF/dal/model/alertconfig-codegen.xml
浏览文件 @
cd6035f3
...
...
@@ -8,6 +8,7 @@
<attribute
name=
"enable"
value-type=
"boolean"
/>
<element
name=
"email"
value-type=
"String"
type=
"list"
names=
"emails"
/>
<element
name=
"phone"
value-type=
"String"
type=
"list"
names=
"phones"
/>
<element
name=
"weixin"
value-type=
"String"
type=
"list"
names=
"weixins"
/>
</entity>
</model>
cat-home/src/main/resources/META-INF/dal/model/alertconfig-model.xml
浏览文件 @
cd6035f3
...
...
@@ -10,6 +10,7 @@
<attribute
name=
"enable"
value-type=
"boolean"
/>
<element
name=
"email"
value-type=
"String"
type=
"list"
names=
"emails"
/>
<element
name=
"phone"
value-type=
"String"
type=
"list"
names=
"phones"
/>
<element
name=
"weixin"
value-type=
"String"
type=
"list"
names=
"weixins"
/>
</entity>
</model>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录