Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dlink
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhaowei
dlink
Commits
508a6a99
Commit
508a6a99
authored
Mar 10, 2022
by
zhu-mingye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加钉钉告警的MarkDown和Text消息类型
修复钉钉告警 @所有人 前端回显问题 优化企微告警 优化FlinkDDL
parent
0bef2d49
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
33 deletions
+104
-33
DingTalkConstants.java
...main/java/com/dlink/alert/dingtalk/DingTalkConstants.java
+5
-4
DingTalkSender.java
...rc/main/java/com/dlink/alert/dingtalk/DingTalkSender.java
+44
-13
DingTalkTest.java
.../src/test/java/com/dlink/alert/dingtalk/DingTalkTest.java
+37
-8
WeChatSender.java
...at/src/main/java/com/dlink/alert/wechat/WeChatSender.java
+2
-2
Table.java
dlink-common/src/main/java/com/dlink/model/Table.java
+2
-2
DingTalkForm.tsx
...k-web/src/pages/AlertInstance/components/DingTalkForm.tsx
+13
-3
WeChatForm.tsx
dlink-web/src/pages/AlertInstance/components/WeChatForm.tsx
+1
-1
No files found.
dlink-alert/dlink-alert-dingtalk/src/main/java/com/dlink/alert/dingtalk/DingTalkConstants.java
View file @
508a6a99
...
@@ -10,6 +10,10 @@ public final class DingTalkConstants {
...
@@ -10,6 +10,10 @@ public final class DingTalkConstants {
static
final
String
TYPE
=
"DingTalk"
;
static
final
String
TYPE
=
"DingTalk"
;
static
final
String
MARKDOWN_QUOTE
=
"- "
;
static
final
String
MARKDOWN_ENTER
=
"\n"
;
static
final
String
PROXY_ENABLE
=
"isEnableProxy"
;
static
final
String
PROXY_ENABLE
=
"isEnableProxy"
;
static
final
String
WEB_HOOK
=
"webhook"
;
static
final
String
WEB_HOOK
=
"webhook"
;
...
@@ -18,7 +22,7 @@ public final class DingTalkConstants {
...
@@ -18,7 +22,7 @@ public final class DingTalkConstants {
static
final
String
SECRET
=
"secret"
;
static
final
String
SECRET
=
"secret"
;
static
final
String
MSG_TYPE
=
"msg
T
ype"
;
static
final
String
MSG_TYPE
=
"msg
t
ype"
;
static
final
String
AT_MOBILES
=
"atMobiles"
;
static
final
String
AT_MOBILES
=
"atMobiles"
;
...
@@ -34,8 +38,5 @@ public final class DingTalkConstants {
...
@@ -34,8 +38,5 @@ public final class DingTalkConstants {
static
final
String
PASSWORD
=
"password"
;
static
final
String
PASSWORD
=
"password"
;
static
final
String
MSG_TYPE_TEXT
=
"text"
;
static
final
String
MSG_TYPE_MARKDOWN
=
"markdown"
;
}
}
dlink-alert/dlink-alert-dingtalk/src/main/java/com/dlink/alert/dingtalk/DingTalkSender.java
View file @
508a6a99
...
@@ -2,9 +2,11 @@ package com.dlink.alert.dingtalk;
...
@@ -2,9 +2,11 @@ package com.dlink.alert.dingtalk;
import
com.dlink.alert.AlertResult
;
import
com.dlink.alert.AlertResult
;
import
com.dlink.alert.AlertSendResponse
;
import
com.dlink.alert.AlertSendResponse
;
import
com.dlink.alert.ShowType
;
import
com.dlink.assertion.Asserts
;
import
com.dlink.assertion.Asserts
;
import
com.dlink.utils.JSONUtil
;
import
com.dlink.utils.JSONUtil
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.StringUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.AuthScope
;
...
@@ -26,10 +28,7 @@ import javax.crypto.spec.SecretKeySpec;
...
@@ -26,10 +28,7 @@ import javax.crypto.spec.SecretKeySpec;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
/**
/**
* DingTalkSender
* DingTalkSender
...
@@ -123,13 +122,13 @@ public class DingTalkSender {
...
@@ -123,13 +122,13 @@ public class DingTalkSender {
private
String
generateMsgJson
(
String
title
,
String
content
)
{
private
String
generateMsgJson
(
String
title
,
String
content
)
{
if
(
Asserts
.
isNullString
(
msgType
))
{
if
(
Asserts
.
isNullString
(
msgType
))
{
msgType
=
DingTalkConstants
.
MSG_TYPE_TEXT
;
msgType
=
ShowType
.
TEXT
.
getValue
()
;
}
}
Map
<
String
,
Object
>
items
=
new
HashMap
<>();
Map
<
String
,
Object
>
items
=
new
HashMap
<>();
items
.
put
(
"msgtype"
,
msgType
);
items
.
put
(
"msgtype"
,
msgType
);
Map
<
String
,
Object
>
text
=
new
HashMap
<>();
Map
<
String
,
Object
>
text
=
new
HashMap
<>();
items
.
put
(
msgType
,
text
);
items
.
put
(
msgType
,
text
);
if
(
DingTalkConstants
.
MSG_TYPE_MARKDOWN
.
equals
(
msgType
))
{
if
(
ShowType
.
TABLE
.
getValue
()
.
equals
(
msgType
))
{
generateMarkdownMsg
(
title
,
content
,
text
);
generateMarkdownMsg
(
title
,
content
,
text
);
}
else
{
}
else
{
generateTextMsg
(
title
,
content
,
text
);
generateTextMsg
(
title
,
content
,
text
);
...
@@ -139,18 +138,17 @@ public class DingTalkSender {
...
@@ -139,18 +138,17 @@ public class DingTalkSender {
}
}
private
void
generateTextMsg
(
String
title
,
String
content
,
Map
<
String
,
Object
>
text
)
{
private
void
generateTextMsg
(
String
title
,
String
content
,
Map
<
String
,
Object
>
text
)
{
StringBuilder
builder
=
new
StringBuilder
(
title
);
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
"\n"
);
builder
.
append
(
content
);
if
(
Asserts
.
isNotNullString
(
keyword
))
{
if
(
Asserts
.
isNotNullString
(
keyword
))
{
builder
.
append
(
" "
);
builder
.
append
(
keyword
);
builder
.
append
(
keyword
);
builder
.
append
(
"\n"
);
}
}
text
.
put
(
"content"
,
builder
.
toString
());
String
txt
=
genrateResultMsg
(
title
,
content
,
builder
);
text
.
put
(
"content"
,
txt
);
}
}
private
void
generateMarkdownMsg
(
String
title
,
String
content
,
Map
<
String
,
Object
>
text
)
{
private
void
generateMarkdownMsg
(
String
title
,
String
content
,
Map
<
String
,
Object
>
text
)
{
StringBuilder
builder
=
new
StringBuilder
(
content
);
StringBuilder
builder
=
new
StringBuilder
(
"# "
);
if
(
Asserts
.
isNotNullString
(
keyword
))
{
if
(
Asserts
.
isNotNullString
(
keyword
))
{
builder
.
append
(
" "
);
builder
.
append
(
" "
);
builder
.
append
(
keyword
);
builder
.
append
(
keyword
);
...
@@ -170,8 +168,41 @@ public class DingTalkSender {
...
@@ -170,8 +168,41 @@ public class DingTalkSender {
builder
.
append
(
" "
);
builder
.
append
(
" "
);
});
});
}
}
String
txt
=
genrateResultMsg
(
title
,
content
,
builder
);
text
.
put
(
"title"
,
title
);
text
.
put
(
"title"
,
title
);
text
.
put
(
"text"
,
builder
.
toString
());
text
.
put
(
"text"
,
txt
);
}
/**
* 公共生成 markdown 和 text 消息
* @param title 标题
* @param content 内容
* @param builder 拼接字符串
* @return
*/
private
String
genrateResultMsg
(
String
title
,
String
content
,
StringBuilder
builder
)
{
List
<
LinkedHashMap
>
mapSendResultItemsList
=
JSONUtil
.
toList
(
content
,
LinkedHashMap
.
class
);
if
(
null
==
mapSendResultItemsList
||
mapSendResultItemsList
.
isEmpty
())
{
logger
.
error
(
"itemsList is null"
);
throw
new
RuntimeException
(
"itemsList is null"
);
}
for
(
LinkedHashMap
mapItems
:
mapSendResultItemsList
)
{
Set
<
Map
.
Entry
<
String
,
Object
>>
entries
=
mapItems
.
entrySet
();
Iterator
<
Map
.
Entry
<
String
,
Object
>>
iterator
=
entries
.
iterator
();
StringBuilder
t
=
new
StringBuilder
(
String
.
format
(
"`%s`%s"
,
title
,
DingTalkConstants
.
MARKDOWN_ENTER
));
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
Object
>
entry
=
iterator
.
next
();
t
.
append
(
DingTalkConstants
.
MARKDOWN_QUOTE
);
t
.
append
(
entry
.
getKey
()).
append
(
":"
).
append
(
entry
.
getValue
());
t
.
append
(
DingTalkConstants
.
MARKDOWN_ENTER
);
}
builder
.
append
(
t
);
}
byte
[]
byt
=
StringUtils
.
getBytesUtf8
(
builder
.
toString
());
String
txt
=
StringUtils
.
newStringUtf8
(
byt
);
return
txt
;
}
}
private
String
generateSignedUrl
()
{
private
String
generateSignedUrl
()
{
...
...
dlink-alert/dlink-alert-dingtalk/src/test/java/com/dlink/alert/dingtalk/DingTalkTest.java
View file @
508a6a99
...
@@ -3,6 +3,7 @@ package com.dlink.alert.dingtalk;
...
@@ -3,6 +3,7 @@ package com.dlink.alert.dingtalk;
import
com.dlink.alert.Alert
;
import
com.dlink.alert.Alert
;
import
com.dlink.alert.AlertConfig
;
import
com.dlink.alert.AlertConfig
;
import
com.dlink.alert.AlertResult
;
import
com.dlink.alert.AlertResult
;
import
com.dlink.alert.ShowType
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -18,14 +19,32 @@ import java.util.Map;
...
@@ -18,14 +19,32 @@ import java.util.Map;
**/
**/
public
class
DingTalkTest
{
public
class
DingTalkTest
{
private
static
final
Map
<
String
,
String
>
config
=
new
HashMap
<>();
private
static
Map
<
String
,
String
>
config
=
new
HashMap
<>();
private
String
contentTest
=
"[{\"id\":\"70\","
+
"\"name\":\"UserBehavior-0--1193959466\","
+
"\"Job name\":\"Start workflow\","
+
"\"State\":\"SUCCESS\","
+
"\"Recovery\":\"NO\","
+
"\"Run time\":\"1\","
+
"\"Start time\": \"2018-08-06 10:31:34.0\","
+
"\"End time\": \"2018-08-06 10:31:49.0\","
+
"\"Host\": \"192.168.xx.xx\","
+
"\"Notify group\" :\"4\"}]"
;
@Before
@Before
public
void
initDingTalkConfig
()
{
public
void
initDingTalkConfig
()
{
config
.
put
(
DingTalkConstants
.
KEYWORD
,
"
keyword
"
);
config
.
put
(
DingTalkConstants
.
KEYWORD
,
"
Dlinky-Fink 钉钉告警测试
"
);
config
.
put
(
DingTalkConstants
.
WEB_HOOK
,
"url"
);
config
.
put
(
DingTalkConstants
.
WEB_HOOK
,
"url"
);
config
.
put
(
DingTalkConstants
.
MSG_TYPE
,
DingTalkConstants
.
MSG_TYPE_MARKDOWN
);
config
.
put
(
DingTalkConstants
.
MSG_TYPE
,
ShowType
.
TABLE
.
getValue
()
);
config
.
put
(
DingTalkConstants
.
PROXY_ENABLE
,
"false"
);
config
.
put
(
DingTalkConstants
.
PROXY_ENABLE
,
"false"
);
config
.
put
(
DingTalkConstants
.
PASSWORD
,
"password"
);
config
.
put
(
DingTalkConstants
.
PASSWORD
,
"password"
);
...
@@ -34,10 +53,20 @@ public class DingTalkTest {
...
@@ -34,10 +53,20 @@ public class DingTalkTest {
}
}
@Test
@Test
public
void
sendTest
(){
public
void
sendMarkDownMsgTest
(){
AlertConfig
config
=
AlertConfig
.
build
(
"test"
,
"DingTalk"
,
DingTalkTest
.
config
);
AlertConfig
config
=
AlertConfig
.
build
(
"MarkDownTest"
,
"DingTalk"
,
DingTalkTest
.
config
);
Alert
alert
=
Alert
.
build
(
config
);
AlertResult
result
=
alert
.
send
(
"Dlinky钉钉告警测试"
,
contentTest
);
Assert
.
assertEquals
(
true
,
result
.
getSuccess
());
}
@Test
public
void
sendTextMsgTest
(){
config
.
put
(
DingTalkConstants
.
MSG_TYPE
,
ShowType
.
TEXT
.
getValue
());
AlertConfig
config
=
AlertConfig
.
build
(
"TextMsgTest"
,
"DingTalk"
,
DingTalkTest
.
config
);
Alert
alert
=
Alert
.
build
(
config
);
Alert
alert
=
Alert
.
build
(
config
);
AlertResult
result
=
alert
.
send
(
"
hello word"
,
"UTF-8"
);
AlertResult
result
=
alert
.
send
(
"
Dlinky钉钉告警测试"
,
contentTest
);
Assert
.
assertEquals
(
fals
e
,
result
.
getSuccess
());
Assert
.
assertEquals
(
tru
e
,
result
.
getSuccess
());
}
}
}
}
dlink-alert/dlink-alert-wechat/src/main/java/com/dlink/alert/wechat/WeChatSender.java
View file @
508a6a99
...
@@ -155,7 +155,7 @@ public class WeChatSender {
...
@@ -155,7 +155,7 @@ public class WeChatSender {
Map
.
Entry
<
String
,
Object
>
entry
=
iterator
.
next
();
Map
.
Entry
<
String
,
Object
>
entry
=
iterator
.
next
();
t
.
append
(
WeChatConstants
.
MARKDOWN_QUOTE
);
t
.
append
(
WeChatConstants
.
MARKDOWN_QUOTE
);
t
.
append
(
entry
.
getKey
()).
append
(
"
:
"
).
append
(
entry
.
getValue
());
t
.
append
(
entry
.
getKey
()).
append
(
"
:
"
).
append
(
entry
.
getValue
());
t
.
append
(
WeChatConstants
.
MARKDOWN_ENTER
);
t
.
append
(
WeChatConstants
.
MARKDOWN_ENTER
);
}
}
contents
.
append
(
t
);
contents
.
append
(
t
);
...
@@ -179,7 +179,7 @@ public class WeChatSender {
...
@@ -179,7 +179,7 @@ public class WeChatSender {
Set
<
Map
.
Entry
<
String
,
Object
>>
entries
=
mapItems
.
entrySet
();
Set
<
Map
.
Entry
<
String
,
Object
>>
entries
=
mapItems
.
entrySet
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
entries
)
{
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
entries
)
{
contents
.
append
(
WeChatConstants
.
MARKDOWN_QUOTE
);
contents
.
append
(
WeChatConstants
.
MARKDOWN_QUOTE
);
contents
.
append
(
entry
.
getKey
()).
append
(
"
:
"
).
append
(
entry
.
getValue
());
contents
.
append
(
entry
.
getKey
()).
append
(
"
:
"
).
append
(
entry
.
getValue
());
contents
.
append
(
WeChatConstants
.
MARKDOWN_ENTER
);
contents
.
append
(
WeChatConstants
.
MARKDOWN_ENTER
);
}
}
...
...
dlink-common/src/main/java/com/dlink/model/Table.java
View file @
508a6a99
...
@@ -72,8 +72,8 @@ public class Table implements Serializable, Comparable<Table> {
...
@@ -72,8 +72,8 @@ public class Table implements Serializable, Comparable<Table> {
public
String
getFlinkTableSql
(
String
catalogName
,
String
flinkConfig
)
{
public
String
getFlinkTableSql
(
String
catalogName
,
String
flinkConfig
)
{
StringBuilder
sb
=
new
StringBuilder
(
"DROP TABLE IF EXISTS "
);
StringBuilder
sb
=
new
StringBuilder
(
"DROP TABLE IF EXISTS "
);
String
fullSchemaName
=
catalogName
+
"."
+
schema
+
"."
+
name
;
String
fullSchemaName
=
catalogName
+
"."
+
schema
+
"."
+
name
;
sb
.
append
(
fullSchemaN
ame
+
";\n"
);
sb
.
append
(
n
ame
+
";\n"
);
sb
.
append
(
"CREATE TABLE IF NOT EXISTS "
+
fullSchemaN
ame
+
" (\n"
);
sb
.
append
(
"CREATE TABLE IF NOT EXISTS "
+
n
ame
+
" (\n"
);
List
<
String
>
pks
=
new
ArrayList
<>();
List
<
String
>
pks
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
columns
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
columns
.
size
();
i
++)
{
String
type
=
columns
.
get
(
i
).
getJavaType
().
getFlinkType
();
String
type
=
columns
.
get
(
i
).
getJavaType
().
getFlinkType
();
...
...
dlink-web/src/pages/AlertInstance/components/DingTalkForm.tsx
View file @
508a6a99
import
React
,
{
use
Effect
,
use
State
}
from
'react'
;
import
React
,
{
useState
}
from
'react'
;
import
{
Form
,
Button
,
Input
,
Modal
,
Divider
,
Switch
}
from
'antd'
;
import
{
Button
,
Divider
,
Form
,
Input
,
Modal
,
Radio
,
Switch
}
from
'antd'
;
import
{
AlertInstanceTableListItem
}
from
"@/pages/AlertInstance/data"
;
import
{
AlertInstanceTableListItem
}
from
"@/pages/AlertInstance/data"
;
import
{
buildJSONData
,
getJSONData
}
from
"@/pages/AlertInstance/function"
;
import
{
buildJSONData
,
getJSONData
}
from
"@/pages/AlertInstance/function"
;
import
{
ALERT_TYPE
}
from
"@/pages/AlertInstance/conf"
;
import
{
ALERT_TYPE
}
from
"@/pages/AlertInstance/conf"
;
...
@@ -109,7 +109,7 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
...
@@ -109,7 +109,7 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
name=
"isAtAll"
name=
"isAtAll"
label=
"@所有人"
>
label=
"@所有人"
>
<
Switch
checkedChildren=
"启用"
unCheckedChildren=
"禁用"
<
Switch
checkedChildren=
"启用"
unCheckedChildren=
"禁用"
defaultChecked=
{
formVals
.
I
sAtAll
}
/>
defaultChecked=
{
formVals
.
i
sAtAll
}
/>
</
Form
.
Item
>
</
Form
.
Item
>
<
Form
.
Item
<
Form
.
Item
name=
"enabled"
name=
"enabled"
...
@@ -117,6 +117,16 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
...
@@ -117,6 +117,16 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
<
Switch
checkedChildren=
"启用"
unCheckedChildren=
"禁用"
<
Switch
checkedChildren=
"启用"
unCheckedChildren=
"禁用"
defaultChecked=
{
formVals
.
enabled
}
/>
defaultChecked=
{
formVals
.
enabled
}
/>
</
Form
.
Item
>
</
Form
.
Item
>
<
Form
.
Item
name=
"msgtype"
label=
"展示方式"
rules=
{
[{
required
:
true
,
message
:
'请选择展示方式!'
}]
}
>
<
Radio
.
Group
>
<
Radio
value=
'markdown'
>
MarkDown
</
Radio
>
<
Radio
value=
'text'
>
文本
</
Radio
>
</
Radio
.
Group
>
</
Form
.
Item
>
</>
</>
);
);
};
};
...
...
dlink-web/src/pages/AlertInstance/components/WeChatForm.tsx
View file @
508a6a99
...
@@ -102,7 +102,7 @@ const WeChatForm: React.FC<AlertInstanceFormProps> = (props) => {
...
@@ -102,7 +102,7 @@ const WeChatForm: React.FC<AlertInstanceFormProps> = (props) => {
<
Form
.
Item
<
Form
.
Item
name=
"showType"
name=
"showType"
label=
"展示方式"
label=
"展示方式"
rules=
{
[{
required
:
true
,
message
:
'请
输入
展示方式!'
}]
}
rules=
{
[{
required
:
true
,
message
:
'请
选择
展示方式!'
}]
}
>
>
<
Radio
.
Group
>
<
Radio
.
Group
>
<
Radio
value=
'markdown'
>
MarkDown
</
Radio
>
<
Radio
value=
'markdown'
>
MarkDown
</
Radio
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment