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
3ff5d3f3
Commit
3ff5d3f3
authored
Apr 05, 2022
by
wenmo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix-347] [alert] Fix to the latest configuration take effect during the alert test
parent
eb71b91d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
34 deletions
+35
-34
AlertInstanceController.java
...in/java/com/dlink/controller/AlertInstanceController.java
+4
-5
AlertInstanceService.java
...src/main/java/com/dlink/service/AlertInstanceService.java
+1
-1
AlertInstanceServiceImpl.java
...java/com/dlink/service/impl/AlertInstanceServiceImpl.java
+10
-17
Alert.java
...dlink-alert-base/src/main/java/com/dlink/alert/Alert.java
+9
-0
DingTalkForm.tsx
...k-web/src/pages/AlertInstance/components/DingTalkForm.tsx
+2
-2
EmailForm.tsx
dlink-web/src/pages/AlertInstance/components/EmailForm.tsx
+3
-3
FeiShuForm.tsx
dlink-web/src/pages/AlertInstance/components/FeiShuForm.tsx
+3
-3
WeChatForm.tsx
dlink-web/src/pages/AlertInstance/components/WeChatForm.tsx
+3
-3
No files found.
dlink-admin/src/main/java/com/dlink/controller/AlertInstanceController.java
View file @
3ff5d3f3
...
...
@@ -7,7 +7,9 @@ import com.dlink.common.result.Result;
import
com.dlink.model.AlertInstance
;
import
com.dlink.service.AlertInstanceService
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -93,14 +95,11 @@ public class AlertInstanceController {
*/
@PostMapping
(
"/sendTest"
)
public
Result
sendTest
(
@RequestBody
AlertInstance
alertInstance
)
throws
Exception
{
AlertResult
alertResult
=
alertInstanceService
.
getAlerTesttResul
t
(
alertInstance
);
AlertResult
alertResult
=
alertInstanceService
.
testAler
t
(
alertInstance
);
if
(
alertResult
.
getSuccess
())
{
return
Result
.
succeed
(
"发送成功"
);
}
else
{
}
else
{
return
Result
.
failed
(
"发送失败"
);
}
}
}
dlink-admin/src/main/java/com/dlink/service/AlertInstanceService.java
View file @
3ff5d3f3
...
...
@@ -16,5 +16,5 @@ public interface AlertInstanceService extends ISuperService<AlertInstance> {
List
<
AlertInstance
>
listEnabledAll
();
AlertResult
getAlerTesttResul
t
(
AlertInstance
alertInstance
);
AlertResult
testAler
t
(
AlertInstance
alertInstance
);
}
dlink-admin/src/main/java/com/dlink/service/impl/AlertInstanceServiceImpl.java
View file @
3ff5d3f3
...
...
@@ -7,6 +7,7 @@ import com.dlink.mapper.AlertInstanceMapper;
import
com.dlink.model.AlertInstance
;
import
com.dlink.service.AlertInstanceService
;
import
com.dlink.utils.JSONUtil
;
import
org.springframework.stereotype.Service
;
import
java.text.SimpleDateFormat
;
...
...
@@ -28,27 +29,19 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
}
@Override
public
AlertResult
getAlerTesttResult
(
AlertInstance
alertInstance
)
{
AlertConfig
alertConfig
=
null
;
Alert
alert
=
null
;
if
(!
AlertPool
.
exist
(
alertInstance
.
getName
()))
{
alertConfig
=
AlertConfig
.
build
(
alertInstance
.
getName
(),
alertInstance
.
getType
(),
JSONUtil
.
toMap
(
alertInstance
.
getParams
()));
alert
=
Alert
.
build
(
alertConfig
);
AlertPool
.
push
(
alertInstance
.
getName
(),
alert
);
}
else
{
alert
=
AlertPool
.
get
(
alertInstance
.
getName
());
}
public
AlertResult
testAlert
(
AlertInstance
alertInstance
)
{
AlertConfig
alertConfig
=
AlertConfig
.
build
(
alertInstance
.
getName
(),
alertInstance
.
getType
(),
JSONUtil
.
toMap
(
alertInstance
.
getParams
()));
Alert
alert
=
Alert
.
buildTest
(
alertConfig
);
String
currentDateTime
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
Calendar
.
getInstance
().
getTime
());
String
testSendMsg
=
"[{\"type\":\"Flink 实时监控\","
+
"\"time\":\""
+
currentDateTime
+
"\","
+
"\"id\":\""
+
UUID
.
randomUUID
()
+
"\","
+
"\"name\":\"此信息仅用于测试告警信息是否发送正常 ! 请忽略此信息!\","
+
"\"status\":\"Test\","
+
"\"content\" :\""
+
UUID
.
randomUUID
()
+
"\"}]"
;
"\"time\":\""
+
currentDateTime
+
"\","
+
"\"id\":\""
+
UUID
.
randomUUID
()
+
"\","
+
"\"name\":\"此信息仅用于测试告警信息是否发送正常 ! 请忽略此信息!\","
+
"\"status\":\"Test\","
+
"\"content\" :\""
+
UUID
.
randomUUID
()
+
"\"}]"
;
List
<
AlertMsg
>
lists
=
JSONUtil
.
toList
(
testSendMsg
,
AlertMsg
.
class
);
String
title
=
"任务【测试任务】:"
+
alertInstance
.
getType
()
+
" 报警 !"
;
String
content
=
JSONUtil
.
toJsonString
(
lists
);
AlertResult
alertResult
=
alert
.
send
(
title
,
content
);
return
alertResult
;
return
alert
.
send
(
title
,
content
);
}
}
dlink-alert/dlink-alert-base/src/main/java/com/dlink/alert/Alert.java
View file @
3ff5d3f3
package
com
.
dlink
.
alert
;
import
com.dlink.assertion.Asserts
;
import
sun.misc.Service
;
import
java.util.Iterator
;
...
...
@@ -40,6 +41,14 @@ public interface Alert {
return
driver
;
}
static
Alert
buildTest
(
AlertConfig
config
)
{
Optional
<
Alert
>
optionalDriver
=
Alert
.
get
(
config
);
if
(!
optionalDriver
.
isPresent
())
{
throw
new
AlertException
(
"不支持报警组件类型【"
+
config
.
getType
()
+
"】,请在 lib 下添加扩展依赖"
);
}
return
optionalDriver
.
get
();
}
Alert
setConfig
(
AlertConfig
config
);
default
boolean
canHandle
(
String
type
)
{
...
...
dlink-web/src/pages/AlertInstance/components/DingTalkForm.tsx
View file @
3ff5d3f3
...
...
@@ -42,7 +42,7 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
));
handleTest
(
{...
formVals
,
...
fieldsValue
}
);
handleTest
(
buildJSONData
(
formVals
,
fieldsValue
)
);
};
const
submitForm
=
async
()
=>
{
...
...
@@ -143,7 +143,7 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
return
(
<>
<
Button
onClick=
{
()
=>
handleModalVisible
(
false
)
}
>
取消
</
Button
>
<
Button
type=
"primary"
danger
htmlType=
"button"
onClick=
{
sendTestForm
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
sendTestForm
()
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/components/EmailForm.tsx
View file @
3ff5d3f3
...
...
@@ -41,8 +41,8 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
(
{...
formVals
,
...
fieldsValue
}
);
handleTest
(
{...
formVals
,
...
fieldsValue
}
);
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
)
);
handleTest
(
buildJSONData
(
formVals
,
fieldsValue
)
);
};
const
submitForm
=
async
()
=>
{
...
...
@@ -181,7 +181,7 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
return
(
<>
<
Button
onClick=
{
()
=>
handleModalVisible
(
false
)
}
>
取消
</
Button
>
<
Button
type=
"primary"
danger
htmlType=
"button"
onClick=
{
sendTestForm
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
sendTestForm
()
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/components/FeiShuForm.tsx
View file @
3ff5d3f3
...
...
@@ -47,8 +47,8 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
getFieldsValue
();
setFormVals
(
{...
formVals
,
...
fieldsValue
}
);
handleTest
(
{...
formVals
,
...
fieldsValue
}
);
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
)
);
handleTest
(
buildJSONData
(
formVals
,
fieldsValue
)
);
};
const
renderContent
=
(
vals
)
=>
{
...
...
@@ -152,7 +152,7 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
return
(
<>
<
Button
onClick=
{
()
=>
handleModalVisible
(
false
)
}
>
取消
</
Button
>
<
Button
type=
"primary"
danger
htmlType=
"button"
onClick=
{
sendTestForm
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
sendTestForm
()
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/components/WeChatForm.tsx
View file @
3ff5d3f3
...
...
@@ -40,8 +40,8 @@ const WeChatForm: React.FC<AlertInstanceFormProps> = (props) => {
};
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
(
{...
formVals
,
...
fieldsValue
}
);
handleTest
(
{...
formVals
,
...
fieldsValue
}
);
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
)
);
handleTest
(
buildJSONData
(
formVals
,
fieldsValue
)
);
};
const
submitForm
=
async
()
=>
{
...
...
@@ -185,7 +185,7 @@ const WeChatForm: React.FC<AlertInstanceFormProps> = (props) => {
return
(
<>
<
Button
onClick=
{
()
=>
handleModalVisible
(
false
)
}
>
取消
</
Button
>
<
Button
type=
"primary"
danger
htmlType=
"button"
onClick=
{
sendTestForm
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
sendTestForm
()
}
>
测试
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
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