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
403f1bd3
Unverified
Commit
403f1bd3
authored
Apr 05, 2022
by
aiwenmo
Committed by
GitHub
Apr 05, 2022
Browse files
Options
Browse Files
Download
Plain Diff
[Feature-339][admin,web] Add alarmMsg sending test
[Feature-339][admin,web] Add alarmMsg sending test
parents
1f8d2985
3c3dd668
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
118 additions
and
9 deletions
+118
-9
AlertInstanceController.java
...in/java/com/dlink/controller/AlertInstanceController.java
+18
-7
AlertInstanceService.java
...src/main/java/com/dlink/service/AlertInstanceService.java
+3
-0
AlertInstanceServiceImpl.java
...java/com/dlink/service/impl/AlertInstanceServiceImpl.java
+30
-0
AlertInstanceChooseForm.tsx
...ages/AlertInstance/components/AlertInstanceChooseForm.tsx
+18
-1
DingTalkForm.tsx
...k-web/src/pages/AlertInstance/components/DingTalkForm.tsx
+9
-0
EmailForm.tsx
dlink-web/src/pages/AlertInstance/components/EmailForm.tsx
+9
-0
FeiShuForm.tsx
dlink-web/src/pages/AlertInstance/components/FeiShuForm.tsx
+9
-0
WeChatForm.tsx
dlink-web/src/pages/AlertInstance/components/WeChatForm.tsx
+8
-0
service.ts
dlink-web/src/pages/AlertInstance/service.ts
+14
-1
No files found.
dlink-admin/src/main/java/com/dlink/controller/AlertInstanceController.java
View file @
403f1bd3
package
com
.
dlink
.
controller
;
import
com.dlink.alert.AlertPool
;
import
com.dlink.alert.AlertResult
;
import
com.dlink.common.result.ProTableResult
;
import
com.dlink.common.result.Result
;
import
com.dlink.model.AlertInstance
;
...
...
@@ -8,13 +9,7 @@ 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.DeleteMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -92,4 +87,20 @@ public class AlertInstanceController {
public
Result
listEnabledAll
()
{
return
Result
.
succeed
(
alertInstanceService
.
listEnabledAll
(),
"获取成功"
);
}
/**
* 发送告警实例的测试信息
*/
@PostMapping
(
"/sendTest"
)
public
Result
sendTest
(
@RequestBody
AlertInstance
alertInstance
)
throws
Exception
{
AlertResult
alertResult
=
alertInstanceService
.
getAlerTesttResult
(
alertInstance
);
if
(
alertResult
.
getSuccess
())
{
return
Result
.
succeed
(
"发送成功"
);
}
else
{
return
Result
.
failed
(
"发送失败"
);
}
}
}
dlink-admin/src/main/java/com/dlink/service/AlertInstanceService.java
View file @
403f1bd3
package
com
.
dlink
.
service
;
import
com.dlink.alert.AlertResult
;
import
com.dlink.db.service.ISuperService
;
import
com.dlink.model.AlertInstance
;
...
...
@@ -14,4 +15,6 @@ import java.util.List;
public
interface
AlertInstanceService
extends
ISuperService
<
AlertInstance
>
{
List
<
AlertInstance
>
listEnabledAll
();
AlertResult
getAlerTesttResult
(
AlertInstance
alertInstance
);
}
dlink-admin/src/main/java/com/dlink/service/impl/AlertInstanceServiceImpl.java
View file @
403f1bd3
package
com
.
dlink
.
service
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.dlink.alert.*
;
import
com.dlink.db.service.impl.SuperServiceImpl
;
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
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.UUID
;
/**
* AlertInstanceServiceImpl
...
...
@@ -21,4 +26,29 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
public
List
<
AlertInstance
>
listEnabledAll
()
{
return
list
(
new
QueryWrapper
<
AlertInstance
>().
eq
(
"enabled"
,
1
));
}
@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
());
}
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
()
+
"\"}]"
;
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
;
}
}
dlink-web/src/pages/AlertInstance/components/AlertInstanceChooseForm.tsx
View file @
403f1bd3
...
...
@@ -7,7 +7,7 @@ import {ALERT_CONFIG_LIST, ALERT_TYPE, AlertConfig} from "@/pages/AlertInstance/
import
{
getAlertIcon
}
from
"@/pages/AlertInstance/icon"
;
import
{
AlertStateType
}
from
"@/pages/AlertInstance/model"
;
import
DingTalkForm
from
"@/pages/AlertInstance/components/DingTalkForm"
;
import
{
createOrModifyAlertInstance
}
from
"@/pages/AlertInstance/service"
;
import
{
createOrModifyAlertInstance
,
sendTest
}
from
"@/pages/AlertInstance/service"
;
import
WeChatForm
from
"@/pages/AlertInstance/components/WeChatForm"
;
import
FeiShuForm
from
"@/pages/AlertInstance/components/FeiShuForm"
;
import
EmailForm
from
"@/pages/AlertInstance/components/EmailForm"
;
...
...
@@ -43,6 +43,11 @@ const AlertInstanceChooseForm: React.FC<UpdateFormProps> = (props) => {
}
};
const
onTest
=
async
(
value
:
any
)
=>
{
await
sendTest
(
value
);
};
return
(
<
Modal
width=
{
800
}
...
...
@@ -88,6 +93,9 @@ const AlertInstanceChooseForm: React.FC<UpdateFormProps> = (props) => {
onSubmit=
{
(
value
)
=>
{
onSubmit
(
value
);
}
}
onTest=
{
(
value
)
=>
{
onTest
(
value
);
}
}
/>:
undefined
}
{
(
values
?.
type
==
ALERT_TYPE
.
WECHAT
||
alertType
==
ALERT_TYPE
.
WECHAT
)?
...
...
@@ -101,6 +109,9 @@ const AlertInstanceChooseForm: React.FC<UpdateFormProps> = (props) => {
onSubmit=
{
(
value
)
=>
{
onSubmit
(
value
);
}
}
onTest=
{
(
value
)
=>
{
onTest
(
value
);
}
}
/>:
undefined
}
{
(
values
?.
type
==
ALERT_TYPE
.
FEISHU
||
alertType
==
ALERT_TYPE
.
FEISHU
)?
...
...
@@ -114,6 +125,9 @@ const AlertInstanceChooseForm: React.FC<UpdateFormProps> = (props) => {
onSubmit=
{
(
value
)
=>
{
onSubmit
(
value
);
}
}
onTest=
{
(
value
)
=>
{
onTest
(
value
);
}
}
/>:
undefined
}
{
(
values
?.
type
==
ALERT_TYPE
.
EMAIL
||
alertType
==
ALERT_TYPE
.
EMAIL
)?
...
...
@@ -127,6 +141,9 @@ const AlertInstanceChooseForm: React.FC<UpdateFormProps> = (props) => {
onSubmit=
{
(
value
)
=>
{
onSubmit
(
value
);
}
}
onTest=
{
(
value
)
=>
{
onTest
(
value
);
}
}
/>:
undefined
}
</
Modal
>
...
...
dlink-web/src/pages/AlertInstance/components/DingTalkForm.tsx
View file @
403f1bd3
...
...
@@ -7,6 +7,7 @@ import {ALERT_TYPE} from "@/pages/AlertInstance/conf";
export
type
AlertInstanceFormProps
=
{
onCancel
:
(
flag
?:
boolean
)
=>
void
;
onSubmit
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
onTest
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
modalVisible
:
boolean
;
values
:
Partial
<
AlertInstanceTableListItem
>
;
};
...
...
@@ -30,6 +31,7 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
const
{
onSubmit
:
handleSubmit
,
onCancel
:
handleModalVisible
,
onTest
:
handleTest
,
modalVisible
,
}
=
props
;
...
...
@@ -37,6 +39,12 @@ const DingTalkForm: React.FC<AlertInstanceFormProps> = (props) => {
setFormVals
({...
formVals
,...
change
});
};
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
));
handleTest
({...
formVals
,
...
fieldsValue
});
};
const
submitForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
));
...
...
@@ -135,6 +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=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/components/EmailForm.tsx
View file @
403f1bd3
...
...
@@ -7,6 +7,7 @@ import {ALERT_TYPE} from "@/pages/AlertInstance/conf";
export
type
AlertInstanceFormProps
=
{
onCancel
:
(
flag
?:
boolean
)
=>
void
;
onSubmit
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
onTest
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
modalVisible
:
boolean
;
values
:
Partial
<
AlertInstanceTableListItem
>
;
};
...
...
@@ -30,6 +31,7 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
const
{
onSubmit
:
handleSubmit
,
onCancel
:
handleModalVisible
,
onTest
:
handleTest
,
modalVisible
,
}
=
props
;
...
...
@@ -37,6 +39,12 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
setFormVals
({...
formVals
,...
change
});
};
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
({...
formVals
,
...
fieldsValue
});
handleTest
({...
formVals
,
...
fieldsValue
});
};
const
submitForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
(
buildJSONData
(
formVals
,
fieldsValue
));
...
...
@@ -173,6 +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=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/components/FeiShuForm.tsx
View file @
403f1bd3
...
...
@@ -7,6 +7,7 @@ import {ALERT_TYPE} from "@/pages/AlertInstance/conf";
export
type
AlertInstanceFormProps
=
{
onCancel
:
(
flag
?:
boolean
)
=>
void
;
onSubmit
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
onTest
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
modalVisible
:
boolean
;
values
:
Partial
<
AlertInstanceTableListItem
>
;
};
...
...
@@ -29,6 +30,7 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
const
{
onSubmit
:
handleSubmit
,
onTest
:
handleTest
,
onCancel
:
handleModalVisible
,
modalVisible
,
}
=
props
;
...
...
@@ -43,6 +45,12 @@ const FeiShuForm: React.FC<AlertInstanceFormProps> = (props) => {
handleSubmit
(
buildJSONData
(
formVals
,
fieldsValue
));
};
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
getFieldsValue
();
setFormVals
({...
formVals
,
...
fieldsValue
});
handleTest
({...
formVals
,
...
fieldsValue
});
};
const
renderContent
=
(
vals
)
=>
{
return
(
<>
...
...
@@ -144,6 +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=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/components/WeChatForm.tsx
View file @
403f1bd3
...
...
@@ -7,6 +7,7 @@ import {ALERT_TYPE} from "@/pages/AlertInstance/conf";
export
type
AlertInstanceFormProps
=
{
onCancel
:
(
flag
?:
boolean
)
=>
void
;
onSubmit
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
onTest
:
(
values
:
Partial
<
AlertInstanceTableListItem
>
)
=>
void
;
modalVisible
:
boolean
;
values
:
Partial
<
AlertInstanceTableListItem
>
;
};
...
...
@@ -30,12 +31,18 @@ const WeChatForm: React.FC<AlertInstanceFormProps> = (props) => {
const
{
onSubmit
:
handleSubmit
,
onCancel
:
handleModalVisible
,
onTest
:
handleTest
,
modalVisible
,
}
=
props
;
const
onValuesChange
=
(
change
:
any
,
all
:
any
)
=>
{
setFormVals
({...
formVals
,...
change
});
};
const
sendTestForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
({...
formVals
,
...
fieldsValue
});
handleTest
({...
formVals
,
...
fieldsValue
});
};
const
submitForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
...
...
@@ -178,6 +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=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
...
...
dlink-web/src/pages/AlertInstance/service.ts
View file @
403f1bd3
import
{
handleAddOrUpdate
}
from
"@/components/Common/crud"
;
import
{
handleAddOrUpdate
,
postAll
}
from
"@/components/Common/crud"
;
import
{
AlertInstanceTableListItem
}
from
"@/pages/AlertInstance/data"
;
import
{
message
}
from
"antd"
;
export
async
function
createOrModifyAlertInstance
(
alertInstance
:
AlertInstanceTableListItem
)
{
return
handleAddOrUpdate
(
'/api/alertInstance'
,
alertInstance
);
}
export
async
function
sendTest
(
alertInstance
:
AlertInstanceTableListItem
)
{
const
hide
=
message
.
loading
(
'正在发送测试告警信息'
);
try
{
const
{
code
,
msg
}
=
await
postAll
(
'/api/alertInstance/sendTest'
,
alertInstance
);
hide
();
code
==
0
?
message
.
success
(
msg
):
message
.
error
(
msg
);
}
catch
(
error
)
{
hide
();
message
.
error
(
'请求失败,请重试'
);
}
}
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