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
7bcfde99
Commit
7bcfde99
authored
Feb 24, 2022
by
wenmo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alert module
parent
1a74cf25
Changes
25
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
1265 additions
and
37 deletions
+1265
-37
README.md
README.md
+3
-1
pom.xml
dlink-alert/dlink-alert-base/pom.xml
+25
-0
AbstractAlert.java
...ert-base/src/main/java/com/dlink/alert/AbstractAlert.java
+20
-0
Alert.java
...dlink-alert-base/src/main/java/com/dlink/alert/Alert.java
+54
-0
AlertConfig.java
...alert-base/src/main/java/com/dlink/alert/AlertConfig.java
+52
-0
AlertException.java
...rt-base/src/main/java/com/dlink/alert/AlertException.java
+18
-0
AlertPool.java
...k-alert-base/src/main/java/com/dlink/alert/AlertPool.java
+36
-0
AlertResult.java
...alert-base/src/main/java/com/dlink/alert/AlertResult.java
+36
-0
AlertSendResponse.java
...base/src/main/java/com/dlink/alert/AlertSendResponse.java
+31
-0
ShowType.java
...nk-alert-base/src/main/java/com/dlink/alert/ShowType.java
+29
-0
pom.xml
dlink-alert/dlink-alert-dingtalk/pom.xml
+33
-0
DingTalkAlert.java
...src/main/java/com/dlink/alert/dingtalk/DingTalkAlert.java
+24
-0
DingTalkConstants.java
...main/java/com/dlink/alert/dingtalk/DingTalkConstants.java
+41
-0
DingTalkSender.java
...rc/main/java/com/dlink/alert/dingtalk/DingTalkSender.java
+227
-0
com.dlink.alert.Alert
...rc/main/resources/META-INF/services/com.dlink.alert.Alert
+1
-0
DingTalkTest.java
.../src/test/java/com/dlink/alert/dingtalk/DingTalkTest.java
+43
-0
pom.xml
dlink-alert/dlink-alert-wechat/pom.xml
+34
-0
WeChatAlert.java
...hat/src/main/java/com/dlink/alert/wechat/WeChatAlert.java
+22
-0
WeChatConstants.java
...src/main/java/com/dlink/alert/wechat/WeChatConstants.java
+41
-0
WeChatSender.java
...at/src/main/java/com/dlink/alert/wechat/WeChatSender.java
+251
-0
WeChatType.java
...chat/src/main/java/com/dlink/alert/wechat/WeChatType.java
+29
-0
com.dlink.alert.Alert
...rc/main/resources/META-INF/services/com.dlink.alert.Alert
+1
-0
pom.xml
dlink-alert/pom.xml
+24
-0
JSONUtil.java
dlink-common/src/main/java/com/dlink/utils/JSONUtil.java
+178
-0
pom.xml
pom.xml
+12
-36
No files found.
README.md
View file @
7bcfde99
...
@@ -287,7 +287,7 @@ Flink 的版本取决于 lib 下的 dlink-client-1.13.jar。当前版本默认
...
@@ -287,7 +287,7 @@ Flink 的版本取决于 lib 下的 dlink-client-1.13.jar。当前版本默认
8.[
Dlink 在 Flink-mysql-cdc 到 Doris 的实践
](
https://github.com/DataLinkDC/dlink/blob/main/dlink-doc/doc/Dlink%E5%9C%A8Flink-mysql-cdc%E5%88%B0Doris%E7%9A%84%E5%AE%9E%E8%B7%B5.md
)
8.[
Dlink 在 Flink-mysql-cdc 到 Doris 的实践
](
https://github.com/DataLinkDC/dlink/blob/main/dlink-doc/doc/Dlink%E5%9C%A8Flink-mysql-cdc%E5%88%B0Doris%E7%9A%84%E5%AE%9E%E8%B7%B5.md
)
## 技术栈
## 技术栈
与鸣谢
[
Apache Flink
](
https://github.com/apache/flink
)
[
Apache Flink
](
https://github.com/apache/flink
)
...
@@ -295,6 +295,8 @@ Flink 的版本取决于 lib 下的 dlink-client-1.13.jar。当前版本默认
...
@@ -295,6 +295,8 @@ Flink 的版本取决于 lib 下的 dlink-client-1.13.jar。当前版本默认
[
ant-design-pro
](
https://github.com/ant-design/ant-design-pro
)
[
ant-design-pro
](
https://github.com/ant-design/ant-design-pro
)
[
dolphinscheduler
](
https://github.com/apache/dolphinscheduler
)
[
Monaco Editor
](
https://github.com/Microsoft/monaco-editor
)
[
Monaco Editor
](
https://github.com/Microsoft/monaco-editor
)
[
SpringBoot
](
)
[
SpringBoot
](
)
...
...
dlink-alert/dlink-alert-base/pom.xml
0 → 100644
View file @
7bcfde99
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
dlink-alert
</artifactId>
<groupId>
com.dlink
</groupId>
<version>
0.6.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
dlink-alert-base
</artifactId>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-common
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/AbstractAlert.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
/**
* AbstractAlert
*
* @author wenmo
* @since 2022/2/23 19:22
**/
public
abstract
class
AbstractAlert
implements
Alert
{
private
AlertConfig
config
;
public
AlertConfig
getConfig
()
{
return
config
;
}
public
Alert
setConfig
(
AlertConfig
config
)
{
this
.
config
=
config
;
return
this
;
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/Alert.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
import
com.dlink.assertion.Asserts
;
import
com.dlink.exception.MetaDataException
;
import
sun.misc.Service
;
import
java.util.Iterator
;
import
java.util.Optional
;
import
java.util.ServiceLoader
;
/**
* Alert
*
* @author wenmo
* @since 2022/2/23 19:05
**/
public
interface
Alert
{
static
Optional
<
Alert
>
get
(
AlertConfig
config
)
{
Asserts
.
checkNotNull
(
config
,
"报警组件配置不能为空"
);
Iterator
<
Alert
>
providers
=
Service
.
providers
(
Alert
.
class
);
while
(
providers
.
hasNext
())
{
Alert
alert
=
providers
.
next
();
if
(
alert
.
canHandle
(
config
.
getType
()))
{
return
Optional
.
of
(
alert
.
setConfig
(
config
));
}
}
return
Optional
.
empty
();
}
static
Alert
build
(
AlertConfig
config
)
{
String
key
=
config
.
getName
();
if
(
AlertPool
.
exist
(
key
))
{
return
AlertPool
.
get
(
key
);
}
Optional
<
Alert
>
optionalDriver
=
Alert
.
get
(
config
);
if
(!
optionalDriver
.
isPresent
())
{
throw
new
AlertException
(
"不支持报警组件类型【"
+
config
.
getType
()
+
"】,请在 lib 下添加扩展依赖"
);
}
Alert
driver
=
optionalDriver
.
get
();
AlertPool
.
push
(
key
,
driver
);
return
driver
;
}
Alert
setConfig
(
AlertConfig
config
);
default
boolean
canHandle
(
String
type
){
return
Asserts
.
isEqualsIgnoreCase
(
getType
(),
type
);
}
String
getType
();
AlertResult
send
(
String
title
,
String
content
);
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/AlertConfig.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
import
java.util.Map
;
/**
* AlertConfig
*
* @author wenmo
* @since 2022/2/23 19:09
**/
public
class
AlertConfig
{
private
String
name
;
private
String
type
;
private
Map
<
String
,
String
>
param
;
public
AlertConfig
()
{
}
public
AlertConfig
(
String
name
,
String
type
,
Map
<
String
,
String
>
param
)
{
this
.
name
=
name
;
this
.
type
=
type
;
this
.
param
=
param
;
}
public
static
AlertConfig
build
(
String
name
,
String
type
,
Map
<
String
,
String
>
param
)
{
return
new
AlertConfig
(
name
,
type
,
param
);
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
Map
<
String
,
String
>
getParam
()
{
return
param
;
}
public
void
setParam
(
Map
<
String
,
String
>
param
)
{
this
.
param
=
param
;
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/AlertException.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
/**
* AlertException
*
* @author wenmo
* @since 2022/2/23 19:19
**/
public
class
AlertException
extends
RuntimeException
{
public
AlertException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
AlertException
(
String
message
)
{
super
(
message
);
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/AlertPool.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* AlertPool
*
* @author wenmo
* @since 2022/2/23 19:16
**/
public
class
AlertPool
{
private
static
volatile
Map
<
String
,
Alert
>
alertMap
=
new
ConcurrentHashMap
<>();
public
static
boolean
exist
(
String
key
)
{
if
(
alertMap
.
containsKey
(
key
))
{
return
true
;
}
return
false
;
}
public
static
Integer
push
(
String
key
,
Alert
alert
)
{
alertMap
.
put
(
key
,
alert
);
return
alertMap
.
size
();
}
public
static
Integer
remove
(
String
key
)
{
alertMap
.
remove
(
key
);
return
alertMap
.
size
();
}
public
static
Alert
get
(
String
key
)
{
return
alertMap
.
get
(
key
);
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/AlertResult.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
/**
* AlertResult
*
* @author wenmo
* @since 2022/2/23 20:20
**/
public
class
AlertResult
{
private
String
status
;
private
String
message
;
public
AlertResult
()
{
}
public
AlertResult
(
String
status
,
String
message
)
{
this
.
status
=
status
;
this
.
message
=
message
;
}
public
String
getStatus
()
{
return
status
;
}
public
void
setStatus
(
String
status
)
{
this
.
status
=
status
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/AlertSendResponse.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
/**
* AlertSendResponse
*
* @author wenmo
* @since 2022/2/23 20:23
**/
public
class
AlertSendResponse
{
private
Integer
errcode
;
private
String
errmsg
;
public
AlertSendResponse
()
{
}
public
Integer
getErrcode
()
{
return
errcode
;
}
public
void
setErrcode
(
Integer
errcode
)
{
this
.
errcode
=
errcode
;
}
public
String
getErrmsg
()
{
return
errmsg
;
}
public
void
setErrmsg
(
String
errmsg
)
{
this
.
errmsg
=
errmsg
;
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/ShowType.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
;
/**
* ShowType
*
* @author wenmo
* @since 2022/2/23 21:32
**/
public
enum
ShowType
{
TABLE
(
0
,
"table"
),
TEXT
(
1
,
"text"
);
private
int
code
;
private
String
value
;
ShowType
(
int
code
,
String
value
)
{
this
.
code
=
code
;
this
.
value
=
value
;
}
public
int
getCode
()
{
return
code
;
}
public
String
getValue
()
{
return
value
;
}
}
dlink-alert/dlink-alert-dingtalk/pom.xml
0 → 100644
View file @
7bcfde99
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
dlink-alert
</artifactId>
<groupId>
com.dlink
</groupId>
<version>
0.6.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
dlink-alert-dingtalk
</artifactId>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-alert-base
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
dlink-alert/dlink-alert-dingtalk/src/main/java/com/dlink/alert/dingtalk/DingTalkAlert.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
dingtalk
;
import
com.dlink.alert.AbstractAlert
;
import
com.dlink.alert.AlertResult
;
/**
* DingTalkAlert
*
* @author wenmo
* @since 2022/2/23 19:28
**/
public
class
DingTalkAlert
extends
AbstractAlert
{
@Override
public
String
getType
()
{
return
DingTalkConstants
.
TYPE
;
}
@Override
public
AlertResult
send
(
String
title
,
String
content
)
{
DingTalkSender
sender
=
new
DingTalkSender
(
getConfig
().
getParam
());
return
sender
.
send
(
title
,
content
);
}
}
dlink-alert/dlink-alert-dingtalk/src/main/java/com/dlink/alert/dingtalk/DingTalkConstants.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
dingtalk
;
/**
* DingTalkConstants
*
* @author wenmo
* @since 2022/2/23 19:37
**/
public
final
class
DingTalkConstants
{
static
final
String
TYPE
=
"DingTalk"
;
static
final
String
PROXY_ENABLE
=
"IsEnableProxy"
;
static
final
String
WEB_HOOK
=
"WebHook"
;
static
final
String
KEYWORD
=
"Keyword"
;
static
final
String
SECRET
=
"Secret"
;
static
final
String
MSG_TYPE
=
"MsgType"
;
static
final
String
AT_MOBILES
=
"AtMobiles"
;
static
final
String
AT_USERIDS
=
"AtUserIds"
;
static
final
String
AT_ALL
=
"IsAtAll"
;
static
final
String
PROXY
=
"Proxy"
;
static
final
String
PORT
=
"Port"
;
static
final
String
USER
=
"User"
;
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
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
dingtalk
;
import
com.dlink.alert.AlertResult
;
import
com.dlink.alert.AlertSendResponse
;
import
com.dlink.assertion.Asserts
;
import
com.dlink.utils.JSONUtil
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.client.CredentialsProvider
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.crypto.Mac
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
/**
* DingTalkSender
*
* @author wenmo
* @since 2022/2/23 19:34
**/
public
class
DingTalkSender
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
DingTalkSender
.
class
);
private
final
String
url
;
private
final
String
keyword
;
private
final
String
secret
;
private
String
msgType
;
private
final
String
atMobiles
;
private
final
String
atUserIds
;
private
final
Boolean
atAll
;
private
final
Boolean
enableProxy
;
private
String
proxy
;
private
Integer
port
;
private
String
user
;
private
String
password
;
DingTalkSender
(
Map
<
String
,
String
>
config
)
{
url
=
config
.
get
(
DingTalkConstants
.
WEB_HOOK
);
keyword
=
config
.
get
(
DingTalkConstants
.
KEYWORD
);
secret
=
config
.
get
(
DingTalkConstants
.
SECRET
);
msgType
=
config
.
get
(
DingTalkConstants
.
MSG_TYPE
);
atMobiles
=
config
.
get
(
DingTalkConstants
.
AT_MOBILES
);
atUserIds
=
config
.
get
(
DingTalkConstants
.
AT_USERIDS
);
atAll
=
Boolean
.
valueOf
(
config
.
get
(
DingTalkConstants
.
AT_ALL
));
enableProxy
=
Boolean
.
valueOf
(
config
.
get
(
DingTalkConstants
.
PROXY_ENABLE
));
if
(
Boolean
.
TRUE
.
equals
(
enableProxy
))
{
port
=
Integer
.
parseInt
(
config
.
get
(
DingTalkConstants
.
PORT
));
proxy
=
config
.
get
(
DingTalkConstants
.
PROXY
);
user
=
config
.
get
(
DingTalkConstants
.
USER
);
password
=
config
.
get
(
DingTalkConstants
.
PASSWORD
);
}
}
public
AlertResult
send
(
String
title
,
String
content
)
{
AlertResult
alertResult
;
try
{
String
resp
=
sendMsg
(
title
,
content
);
return
checkMsgResult
(
resp
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"send ding talk alert msg exception : {}"
,
e
.
getMessage
());
alertResult
=
new
AlertResult
();
alertResult
.
setStatus
(
"false"
);
alertResult
.
setMessage
(
"send ding talk alert fail."
);
}
return
alertResult
;
}
private
String
sendMsg
(
String
title
,
String
content
)
throws
IOException
{
String
msg
=
generateMsgJson
(
title
,
content
);
String
httpUrl
=
url
;
if
(
Asserts
.
isNotNullString
(
secret
)){
httpUrl
=
generateSignedUrl
();
}
HttpPost
httpPost
=
new
HttpPost
(
httpUrl
);
StringEntity
stringEntity
=
new
StringEntity
(
msg
,
StandardCharsets
.
UTF_8
);
httpPost
.
setEntity
(
stringEntity
);
httpPost
.
addHeader
(
"Content-Type"
,
"application/json; charset=utf-8"
);
CloseableHttpClient
httpClient
;
if
(
Boolean
.
TRUE
.
equals
(
enableProxy
))
{
HttpHost
httpProxy
=
new
HttpHost
(
proxy
,
port
);
CredentialsProvider
provider
=
new
BasicCredentialsProvider
();
provider
.
setCredentials
(
new
AuthScope
(
httpProxy
),
new
UsernamePasswordCredentials
(
user
,
password
));
httpClient
=
HttpClients
.
custom
().
setDefaultCredentialsProvider
(
provider
).
build
();
RequestConfig
rcf
=
RequestConfig
.
custom
().
setProxy
(
httpProxy
).
build
();
httpPost
.
setConfig
(
rcf
);
}
else
{
httpClient
=
HttpClients
.
createDefault
();
}
try
{
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpPost
);
String
resp
;
try
{
HttpEntity
httpEntity
=
response
.
getEntity
();
resp
=
EntityUtils
.
toString
(
httpEntity
,
"UTF-8"
);
EntityUtils
.
consume
(
httpEntity
);
}
finally
{
response
.
close
();
}
return
resp
;
}
finally
{
httpClient
.
close
();
}
}
private
String
generateMsgJson
(
String
title
,
String
content
)
{
if
(
Asserts
.
isNullString
(
msgType
))
{
msgType
=
DingTalkConstants
.
MSG_TYPE_TEXT
;
}
Map
<
String
,
Object
>
items
=
new
HashMap
<>();
items
.
put
(
"msgtype"
,
msgType
);
Map
<
String
,
Object
>
text
=
new
HashMap
<>();
items
.
put
(
msgType
,
text
);
if
(
DingTalkConstants
.
MSG_TYPE_MARKDOWN
.
equals
(
msgType
))
{
generateMarkdownMsg
(
title
,
content
,
text
);
}
else
{
generateTextMsg
(
title
,
content
,
text
);
}
setMsgAt
(
items
);
return
JSONUtil
.
toJsonString
(
items
);
}
private
void
generateTextMsg
(
String
title
,
String
content
,
Map
<
String
,
Object
>
text
)
{
StringBuilder
builder
=
new
StringBuilder
(
title
);
builder
.
append
(
"\n"
);
builder
.
append
(
content
);
if
(
Asserts
.
isNotNullString
(
keyword
))
{
builder
.
append
(
" "
);
builder
.
append
(
keyword
);
}
text
.
put
(
"content"
,
builder
.
toString
());
}
private
void
generateMarkdownMsg
(
String
title
,
String
content
,
Map
<
String
,
Object
>
text
)
{
StringBuilder
builder
=
new
StringBuilder
(
content
);
if
(
Asserts
.
isNotNullString
(
keyword
))
{
builder
.
append
(
" "
);
builder
.
append
(
keyword
);
}
builder
.
append
(
"\n\n"
);
if
(
Asserts
.
isNotNullString
(
atMobiles
))
{
Arrays
.
stream
(
atMobiles
.
split
(
","
)).
forEach
(
value
->
{
builder
.
append
(
"@"
);
builder
.
append
(
value
);
builder
.
append
(
" "
);
});
}
if
(
Asserts
.
isNotNullString
(
atUserIds
))
{
Arrays
.
stream
(
atUserIds
.
split
(
","
)).
forEach
(
value
->
{
builder
.
append
(
"@"
);
builder
.
append
(
value
);
builder
.
append
(
" "
);
});
}
text
.
put
(
"title"
,
title
);
text
.
put
(
"text"
,
builder
.
toString
());
}
private
String
generateSignedUrl
()
{
Long
timestamp
=
System
.
currentTimeMillis
();
String
stringToSign
=
timestamp
+
"\n"
+
secret
;
String
sign
=
""
;
try
{
Mac
mac
=
Mac
.
getInstance
(
"HmacSHA256"
);
mac
.
init
(
new
SecretKeySpec
(
secret
.
getBytes
(
"UTF-8"
),
"HmacSHA256"
));
byte
[]
signData
=
mac
.
doFinal
(
stringToSign
.
getBytes
(
"UTF-8"
));
sign
=
URLEncoder
.
encode
(
new
String
(
Base64
.
encodeBase64
(
signData
)),
"UTF-8"
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"generate sign error, message:{}"
,
e
);
}
return
url
+
"×tamp="
+
timestamp
+
"&sign="
+
sign
;
}
private
void
setMsgAt
(
Map
<
String
,
Object
>
items
)
{
Map
<
String
,
Object
>
at
=
new
HashMap
<>();
String
[]
atMobileArray
=
Asserts
.
isNotNullString
(
atMobiles
)
?
atMobiles
.
split
(
","
)
:
new
String
[
0
];
String
[]
atUserArray
=
Asserts
.
isNotNullString
(
atUserIds
)
?
atUserIds
.
split
(
","
)
:
new
String
[
0
];
boolean
isAtAll
=
Objects
.
isNull
(
atAll
)
?
false
:
atAll
;
at
.
put
(
"atMobiles"
,
atMobileArray
);
at
.
put
(
"atUserIds"
,
atUserArray
);
at
.
put
(
"isAtAll"
,
isAtAll
);
items
.
put
(
"at"
,
at
);
}
private
AlertResult
checkMsgResult
(
String
result
)
{
AlertResult
alertResult
=
new
AlertResult
();
alertResult
.
setStatus
(
"false"
);
if
(
null
==
result
)
{
alertResult
.
setMessage
(
"send ding talk msg error"
);
logger
.
info
(
"send ding talk msg error,ding talk server resp is null"
);
return
alertResult
;
}
AlertSendResponse
response
=
JSONUtil
.
parseObject
(
result
,
AlertSendResponse
.
class
);
if
(
null
==
response
)
{
alertResult
.
setMessage
(
"send ding talk msg fail"
);
logger
.
info
(
"send ding talk msg error,resp error"
);
return
alertResult
;
}
if
(
response
.
getErrcode
()
==
0
)
{
alertResult
.
setStatus
(
"true"
);
alertResult
.
setMessage
(
"send ding talk msg success"
);
return
alertResult
;
}
alertResult
.
setMessage
(
String
.
format
(
"alert send ding talk msg error : %s"
,
response
.
getErrmsg
()));
logger
.
info
(
"alert send ding talk msg error : {}"
,
response
.
getErrmsg
());
return
alertResult
;
}
}
dlink-alert/dlink-alert-dingtalk/src/main/resources/META-INF/services/com.dlink.alert.Alert
0 → 100644
View file @
7bcfde99
com.dlink.alert.dingtalk.DingTalkAlert
\ No newline at end of file
dlink-alert/dlink-alert-dingtalk/src/test/java/com/dlink/alert/dingtalk/DingTalkTest.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
dingtalk
;
import
com.dlink.alert.Alert
;
import
com.dlink.alert.AlertConfig
;
import
com.dlink.alert.AlertResult
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* DingTalkTest
*
* @author wenmo
* @since 2022/2/23 20:18
**/
public
class
DingTalkTest
{
private
static
final
Map
<
String
,
String
>
config
=
new
HashMap
<>();
@Before
public
void
initDingTalkConfig
()
{
config
.
put
(
DingTalkConstants
.
KEYWORD
,
"keyword"
);
config
.
put
(
DingTalkConstants
.
WEB_HOOK
,
"url"
);
config
.
put
(
DingTalkConstants
.
MSG_TYPE
,
DingTalkConstants
.
MSG_TYPE_MARKDOWN
);
config
.
put
(
DingTalkConstants
.
PROXY_ENABLE
,
"false"
);
config
.
put
(
DingTalkConstants
.
PASSWORD
,
"password"
);
config
.
put
(
DingTalkConstants
.
PORT
,
"9988"
);
config
.
put
(
DingTalkConstants
.
USER
,
"user1,user2"
);
}
@Test
public
void
sendTest
(){
AlertConfig
config
=
AlertConfig
.
build
(
"test"
,
"DingTalk"
,
DingTalkTest
.
config
);
Alert
alert
=
Alert
.
build
(
config
);
AlertResult
result
=
alert
.
send
(
"hello word"
,
"UTF-8"
);
Assert
.
assertEquals
(
"false"
,
result
.
getStatus
());
}
}
dlink-alert/dlink-alert-wechat/pom.xml
0 → 100644
View file @
7bcfde99
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
dlink-alert
</artifactId>
<groupId>
com.dlink
</groupId>
<version>
0.6.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
dlink-alert-wechat
</artifactId>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-alert-base
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
dlink-alert/dlink-alert-wechat/src/main/java/com/dlink/alert/wechat/WeChatAlert.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
wechat
;
import
com.dlink.alert.AbstractAlert
;
import
com.dlink.alert.AlertResult
;
/**
* WeChatAlert
*
* @author wenmo
* @since 2022/2/23 21:09
**/
public
class
WeChatAlert
extends
AbstractAlert
{
@Override
public
String
getType
()
{
return
WeChatConstants
.
TYPE
;
}
@Override
public
AlertResult
send
(
String
title
,
String
content
)
{
return
null
;
}
}
dlink-alert/dlink-alert-wechat/src/main/java/com/dlink/alert/wechat/WeChatConstants.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
wechat
;
/**
* WeChatConstants
*
* @author wenmo
* @since 2022/2/23 21:10
**/
public
class
WeChatConstants
{
static
final
String
TYPE
=
"WeChat"
;
static
final
String
MARKDOWN_QUOTE
=
">"
;
static
final
String
MARKDOWN_ENTER
=
"\n"
;
static
final
String
CHARSET
=
"UTF-8"
;
static
final
String
PUSH_URL
=
"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}"
;
static
final
String
APP_CHAT_PUSH_URL
=
"https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token={token}"
;
static
final
String
TOKEN_URL
=
"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpId}&corpsecret={secret}"
;
static
final
String
CORP_ID
=
"corpId"
;
static
final
String
SECRET
=
"secret"
;
static
final
String
TEAM_SEND_MSG
=
"teamSendMsg"
;
static
final
String
USER_SEND_MSG
=
"userSendMsg"
;
static
final
String
AGENT_ID
=
"agentId"
;
static
final
String
USERS
=
"users"
;
static
final
String
SEND_TYPE
=
"sendType"
;
static
final
String
SHOW_TYPE
=
"showType"
;
}
dlink-alert/dlink-alert-wechat/src/main/java/com/dlink/alert/wechat/WeChatSender.java
0 → 100644
View file @
7bcfde99
This diff is collapsed.
Click to expand it.
dlink-alert/dlink-alert-wechat/src/main/java/com/dlink/alert/wechat/WeChatType.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
alert
.
wechat
;
/**
* WeChatType
*
* @author wenmo
* @since 2022/2/23 21:36
**/
public
enum
WeChatType
{
APP
(
1
,
"应用"
),
APPCHAT
(
2
,
"群聊"
);
private
final
int
code
;
private
final
String
value
;
WeChatType
(
int
code
,
String
value
)
{
this
.
code
=
code
;
this
.
value
=
value
;
}
public
int
getCode
()
{
return
code
;
}
public
String
getValue
()
{
return
value
;
}
}
dlink-alert/dlink-alert-wechat/src/main/resources/META-INF/services/com.dlink.alert.Alert
0 → 100644
View file @
7bcfde99
com.dlink.alert.wechat.WeChatAlert
\ No newline at end of file
dlink-alert/pom.xml
0 → 100644
View file @
7bcfde99
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
dlink
</artifactId>
<groupId>
com.dlink
</groupId>
<version>
0.6.0-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
dlink-alert
</artifactId>
<packaging>
pom
</packaging>
<modules>
<module>
dlink-alert-base
</module>
<module>
dlink-alert-dingtalk
</module>
<module>
dlink-alert-wechat
</module>
</modules>
<properties>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
dlink-common/src/main/java/com/dlink/utils/JSONUtil.java
0 → 100644
View file @
7bcfde99
package
com
.
dlink
.
utils
;
import
com.dlink.assertion.Asserts
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.JsonDeserializer
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.TextNode
;
import
com.fasterxml.jackson.databind.type.CollectionType
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TimeZone
;
import
static
com
.
fasterxml
.
jackson
.
databind
.
DeserializationFeature
.
ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT
;
import
static
com
.
fasterxml
.
jackson
.
databind
.
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
;
import
static
com
.
fasterxml
.
jackson
.
databind
.
DeserializationFeature
.
READ_UNKNOWN_ENUM_VALUES_AS_NULL
;
import
static
com
.
fasterxml
.
jackson
.
databind
.
MapperFeature
.
REQUIRE_SETTERS_FOR_GETTERS
;
import
static
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
;
/**
* JSONUtil
*
* @author wenmo
* @since 2022/2/23 19:57
**/
public
class
JSONUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
JSONUtil
.
class
);
private
static
final
ObjectMapper
objectMapper
=
new
ObjectMapper
()
.
configure
(
FAIL_ON_UNKNOWN_PROPERTIES
,
false
)
.
configure
(
ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT
,
true
)
.
configure
(
READ_UNKNOWN_ENUM_VALUES_AS_NULL
,
true
)
.
configure
(
REQUIRE_SETTERS_FOR_GETTERS
,
true
)
.
setTimeZone
(
TimeZone
.
getDefault
());
public
static
ArrayNode
createArrayNode
()
{
return
objectMapper
.
createArrayNode
();
}
public
static
ObjectNode
createObjectNode
()
{
return
objectMapper
.
createObjectNode
();
}
public
static
JsonNode
toJsonNode
(
Object
obj
)
{
return
objectMapper
.
valueToTree
(
obj
);
}
public
static
String
toJsonString
(
Object
object
,
SerializationFeature
feature
)
{
try
{
ObjectWriter
writer
=
objectMapper
.
writer
(
feature
);
return
writer
.
writeValueAsString
(
object
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"object to json exception!"
,
e
);
}
return
null
;
}
public
static
<
T
>
T
parseObject
(
String
json
,
Class
<
T
>
clazz
)
{
if
(
Asserts
.
isNullString
(
json
))
{
return
null
;
}
try
{
return
objectMapper
.
readValue
(
json
,
clazz
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse object exception!"
,
e
);
}
return
null
;
}
public
static
<
T
>
T
parseObject
(
byte
[]
src
,
Class
<
T
>
clazz
)
{
if
(
src
==
null
)
{
return
null
;
}
String
json
=
new
String
(
src
,
UTF_8
);
return
parseObject
(
json
,
clazz
);
}
public
static
<
T
>
List
<
T
>
toList
(
String
json
,
Class
<
T
>
clazz
)
{
if
(
Asserts
.
isNullString
(
json
))
{
return
Collections
.
emptyList
();
}
try
{
CollectionType
listType
=
objectMapper
.
getTypeFactory
().
constructCollectionType
(
ArrayList
.
class
,
clazz
);
return
objectMapper
.
readValue
(
json
,
listType
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse list exception!"
,
e
);
}
return
Collections
.
emptyList
();
}
public
static
Map
<
String
,
String
>
toMap
(
String
json
)
{
return
parseObject
(
json
,
new
TypeReference
<
Map
<
String
,
String
>>()
{
});
}
public
static
<
K
,
V
>
Map
<
K
,
V
>
toMap
(
String
json
,
Class
<
K
>
classK
,
Class
<
V
>
classV
)
{
return
parseObject
(
json
,
new
TypeReference
<
Map
<
K
,
V
>>()
{
});
}
public
static
<
T
>
T
parseObject
(
String
json
,
TypeReference
<
T
>
type
)
{
if
(
Asserts
.
isNullString
(
json
))
{
return
null
;
}
try
{
return
objectMapper
.
readValue
(
json
,
type
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"json to map exception!"
,
e
);
}
return
null
;
}
public
static
String
toJsonString
(
Object
object
)
{
try
{
return
objectMapper
.
writeValueAsString
(
object
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Object json deserialization exception."
,
e
);
}
}
public
static
<
T
>
byte
[]
toJsonByteArray
(
T
obj
)
{
if
(
obj
==
null
)
{
return
null
;
}
String
json
=
""
;
try
{
json
=
toJsonString
(
obj
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"json serialize exception."
,
e
);
}
return
json
.
getBytes
(
UTF_8
);
}
public
static
ObjectNode
parseObject
(
String
text
)
{
try
{
if
(
text
.
isEmpty
())
{
return
parseObject
(
text
,
ObjectNode
.
class
);
}
else
{
return
(
ObjectNode
)
objectMapper
.
readTree
(
text
);
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"String json deserialization exception."
,
e
);
}
}
public
static
ArrayNode
parseArray
(
String
text
)
{
try
{
return
(
ArrayNode
)
objectMapper
.
readTree
(
text
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Json deserialization exception."
,
e
);
}
}
public
static
class
JsonDataDeserializer
extends
JsonDeserializer
<
String
>
{
@Override
public
String
deserialize
(
JsonParser
p
,
DeserializationContext
ctxt
)
throws
IOException
{
JsonNode
node
=
p
.
getCodec
().
readTree
(
p
);
if
(
node
instanceof
TextNode
)
{
return
node
.
asText
();
}
else
{
return
node
.
toString
();
}
}
}
}
pom.xml
View file @
7bcfde99
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
<module>
dlink-web
</module>
<module>
dlink-web
</module>
<module>
dlink-admin
</module>
<module>
dlink-admin
</module>
<module>
dlink-assembly
</module>
<module>
dlink-assembly
</module>
<module>
dlink-alert
</module>
</modules>
</modules>
...
@@ -38,7 +39,6 @@
...
@@ -38,7 +39,6 @@
<lombok.version>
1.18.16
</lombok.version>
<lombok.version>
1.18.16
</lombok.version>
<jackjson.version>
2.11.4
</jackjson.version>
<jackjson.version>
2.11.4
</jackjson.version>
<guava.version>
21.0
</guava.version>
<guava.version>
21.0
</guava.version>
<!-- <log4j.version>2.17.1</log4j.version>-->
<mysql-connector-java.version>
8.0.22
</mysql-connector-java.version>
<mysql-connector-java.version>
8.0.22
</mysql-connector-java.version>
<ojdbc8.version>
12.2.0.1
</ojdbc8.version>
<ojdbc8.version>
12.2.0.1
</ojdbc8.version>
<clickhouse.version>
0.2.6
</clickhouse.version>
<clickhouse.version>
0.2.6
</clickhouse.version>
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
<!--<flyway.version>6.4.4</flyway.version>-->
<!--<flyway.version>6.4.4</flyway.version>-->
<sa-token.version>
1.28.0
</sa-token.version>
<sa-token.version>
1.28.0
</sa-token.version>
<commons-lang3.version>
3.3.2
</commons-lang3.version>
<commons-lang3.version>
3.3.2
</commons-lang3.version>
<httpclient.version>
4.4.1
</httpclient.version>
<maven-jar-plugin.version>
3.2.0
</maven-jar-plugin.version>
<maven-jar-plugin.version>
3.2.0
</maven-jar-plugin.version>
<maven-assembly-plugin.version>
3.2.0
</maven-assembly-plugin.version>
<maven-assembly-plugin.version>
3.2.0
</maven-assembly-plugin.version>
<maven.resource.version>
3.2.0
</maven.resource.version>
<maven.resource.version>
3.2.0
</maven.resource.version>
...
@@ -108,21 +109,6 @@
...
@@ -108,21 +109,6 @@
<artifactId>
commons-lang3
</artifactId>
<artifactId>
commons-lang3
</artifactId>
<version>
${commons-lang3.version}
</version>
<version>
${commons-lang3.version}
</version>
</dependency>
</dependency>
<!--<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>-->
<!--<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>-->
<dependency>
<dependency>
<groupId>
mysql
</groupId>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
...
@@ -275,6 +261,16 @@
...
@@ -275,6 +261,16 @@
<artifactId>
dlink-client-hadoop
</artifactId>
<artifactId>
dlink-client-hadoop
</artifactId>
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.dlink
</groupId>
<artifactId>
dlink-alert-base
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
${httpclient.version}
</version>
</dependency>
</dependencies>
</dependencies>
</dependencyManagement>
</dependencyManagement>
<build>
<build>
...
@@ -283,26 +279,6 @@
...
@@ -283,26 +279,6 @@
<groupId>
org.apache.maven.plugins
</groupId>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-jar-plugin
</artifactId>
<artifactId>
maven-jar-plugin
</artifactId>
</plugin>
</plugin>
<!-- 将依赖的jar包拷贝到target目录下 -->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-dependency-plugin</artifactId>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>copy-dependencies</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>copy-dependencies</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>${basedir}/target</outputDirectory>-->
<!-- <excludeTransitive>false</excludeTransitive>-->
<!-- <stripVersion>false</stripVersion>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</plugins>
</build>
</build>
</project>
</project>
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