Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
ufo-app-web
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
zhangwenxue
6 years ago
Commit
00a8edc95c9299307cc96403bda8e4e72d960e81
1 parent
5e97a6e9
feature(alipay): add alipay dingding alert
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
doraemon/middleware/alipay.service.js
utils/alert-manager.js
doraemon/middleware/alipay.service.js
View file @
00a8edc
const
alipayRepository
=
require
(
'./alipay.repository'
);
const
{
logger
}
=
global
.
yoho
;
const
AlertAgent
=
require
(
'../../utils/alert-manager'
);
const
AlertType
=
{
MySQL
:
0
,
Knex
:
1
,
};
const
alipayAlert
=
new
AlertAgent
(
'alipay'
,
{
[
AlertType
.
MySQL
]:
'mysql error'
,
[
AlertAgent
.
Knex
]:
'knex insert error'
},
[
'1735697170'
,
'15210602915'
]);
async
function
create
({
uid
,
alipayAccount
,
alipayName
})
{
try
{
...
...
@@ -8,6 +18,7 @@ async function create({ uid, alipayAccount, alipayName }) {
});
if
(
!
result
)
{
alipayAlert
.
send
(
AlertType
.
Knex
);
return
{
error
:
{
code
:
500
,
...
...
@@ -31,7 +42,7 @@ async function create({ uid, alipayAccount, alipayName }) {
};
}
else
{
logger
.
error
(
'mysql error =>'
,
e
);
alipayAlert
.
send
(
AlertType
.
MySQL
,
e
.
message
);
return
{
error
:
{
code
:
500
,
...
...
utils/alert-manager.js
View file @
00a8edc
...
...
@@ -17,11 +17,13 @@ const AlertManager = {
const
now
=
Date
.
now
();
let
ats
=
[];
let
text
=
[];
text
.
push
(
`
**
本次告警
**
:
$
{
moment
(
now
).
format
(
'YYYY-MM-DD HH:mm:ss'
)}
\
n
`
);
text
.
push
(
`
**
上次告警
**
:
$
{
moment
(
this
.
lastSendTime
).
format
(
'YYYY-MM-DD HH:mm:ss'
)}
\
n
`
);
text
=
text
.
concat
(
Object
.
keys
(
this
.
pendingAgents
).
map
(
agentName
=>
{
const
agent
=
this
.
pendingAgents
[
agentName
];
ats
=
ats
.
concat
(
agent
.
ats
);
return
agent
.
getMarkdownReport
();
}));
...
...
@@ -46,6 +48,7 @@ class AlertAgent {
send
(
subjectId
,
text
=
''
)
{
let
msg
=
_
.
get
(
this
.
msgs
,
subjectId
,
{
text
,
count
:
0
});
this
.
msgs
[
subjectId
]
=
msg
;
msg
.
count
++
;
AlertManager
.
post
(
this
);
...
...
@@ -53,6 +56,7 @@ class AlertAgent {
getMarkdownReport
()
{
let
report
=
[
`##
$
{
this
.
name
}
`
];
report
.
push
(
this
.
ats
.
map
(
at
=>
`@
$
{
at
}
`
).
join
(
' '
));
const
msgs
=
Object
.
keys
(
this
.
msgs
).
map
(
id
=>
{
...
...
Please
register
or
login
to post a comment