Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
前端
/
sentry-robot
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3ca33305
authored
Nov 21, 2022
by
zhangquan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
日志提醒
1 parent
aeff93d1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
24 deletions
app/controller/robot.js
app/schedule/tip.js
app/utils/utils.js
app/controller/robot.js
View file @
3ca3330
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
const
Controller
=
require
(
"egg"
).
Controller
;
const
Controller
=
require
(
"egg"
).
Controller
;
const
{
SENTRY_HOOKS
}
=
require
(
"../utils/const"
);
const
{
SENTRY_HOOKS
}
=
require
(
"../utils/const"
);
const
{
fmtDateTime
,
genProjectOwners
}
=
require
(
"../utils/utils"
);
const
{
dateFormat
,
genProjectOwners
}
=
require
(
"../utils/utils"
);
class
SentryController
extends
Controller
{
class
SentryController
extends
Controller
{
/**
/**
...
@@ -13,10 +13,7 @@ class SentryController extends Controller {
...
@@ -13,10 +13,7 @@ class SentryController extends Controller {
params
,
params
,
request
:
{
body
},
request
:
{
body
},
}
=
this
.
ctx
;
}
=
this
.
ctx
;
console
.
log
(
params
);
console
.
log
(
body
);
let
bodyJson
=
JSON
.
stringify
(
body
);
let
bodyJson
=
JSON
.
stringify
(
body
);
let
paramsJson
=
JSON
.
stringify
(
params
);
let
data
=
body
&&
body
.
data
&&
body
.
data
.
issue
?
body
.
data
.
issue
:
{};
let
data
=
body
&&
body
.
data
&&
body
.
data
.
issue
?
body
.
data
.
issue
:
{};
const
ROBOT_DATA
=
{
const
ROBOT_DATA
=
{
msgtype
:
"markdown"
,
msgtype
:
"markdown"
,
...
@@ -26,18 +23,14 @@ class SentryController extends Controller {
...
@@ -26,18 +23,14 @@ class SentryController extends Controller {
}
<
/font>发生错误
:
}
<
/font>发生错误
:
>
错误原因
:
<
font
color
=
\
"info\">${data.title}</font>
>
错误原因
:
<
font
color
=
\
"info\">${data.title}</font>
> 错误目录: <font color=\"info\">${data.culprit}</font>
> 错误目录: <font color=\"info\">${data.culprit}</font>
> 错误时间: <font color=\"info\">${fmtDateTime()}</font>
> 错误时间: <font color=\"info\">${dateFormat(new Date(), 'YYYY-MM-DD mm:ss')}</font>
> 错误级别: <font color=\"info\">${data.level}</font>
> 查看详情: [http://sentry.glsx.com.cn/auth/login/sentry/](http://sentry.glsx.com.cn/auth/login/sentry/)
> 错误链接: [查看日志](${data.url || data.permalink})
> 错误body: <font color=\"info\">${bodyJson}</font>`,
> 错误body: <font color=\"info\">${bodyJson}</font>
\n
请以下同事注意:${genProjectOwners(SENTRY_HOOKS.SCRM.owners)}`,
},
},
};
};
const result = await this.ctx.curl(
const result = await this.ctx.curl(
"
https
:
//qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f2ba84b-1b7f-4556-8508-e6c605e2671c",
"
https
:
//qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f2ba84b-1b7f-4556-8508-e6c605e2671c",
{
{
// url: SENTRY_HOOKS[params.name].sentry_hook,
method
:
"POST"
,
method
:
"POST"
,
headers
:
{
headers
:
{
"content-type"
:
"application/json"
,
"content-type"
:
"application/json"
,
...
@@ -52,6 +45,14 @@ class SentryController extends Controller {
...
@@ -52,6 +45,14 @@ class SentryController extends Controller {
msg: "提醒成功",
msg: "提醒成功",
};
};
}
}
async test(){
const result = await this.ctx.curl(
"https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=file-uploader"
);
console.log(result)
}
}
}
module.exports = SentryController;
module.exports = SentryController;
app/schedule/tip.js
0 → 100644
View file @
3ca3330
const
Subscription
=
require
(
'egg'
).
Subscription
;
const
{
dateFormat
}
=
require
(
"../utils/utils"
);
module
.
exports
=
{
schedule
:
{
cron
:
'0 0 9 * * *'
,
type
:
'all'
,
// 指定所有的 worker 都需要执行
},
async
task
(
ctx
)
{
let
plist
=
[
'胡悦'
,
'陈婉清'
,
'匡雅琴'
,
'李伟康'
,
'陆宇天'
,
'王琦琳'
,
'王志慧'
,
'吴文祥'
,
'徐忆琳'
,
'杨北旺'
,
'杨明'
,
'张杰'
,
'张立顺'
,
'张权'
,
'张晓玮'
]
let
idx
=
parseInt
((
new
Date
().
getTime
()
-
new
Date
(
'2022-10-24'
).
getTime
())
/
(
86400000
*
7
))
let
includeList
=
[
'2022-12-31'
,
'2023-01-01'
,
'2023-01-02'
,
'2023-01-21'
,
'2023-01-22'
,
'2023-01-23'
,
'2023-01-24'
,
'2023-01-25'
,
'2023-01-26'
,
'2023-01-27'
,
'2023-04-05'
,
'2023-05-01'
,
'2023-05-02'
,
'2023-05-03'
,
'2023-05-04'
,
'2023-05-05'
,
'2023-06-23'
,
'2023-06-24'
,
'2023-06-25'
,
'2023-06-23'
,
'2023-06-24'
,
'2023-06-25'
,
'2023-09-29'
,
'2023-09-30'
,
'2023-10-01'
,
'2023-10-02'
,
'2023-10-03'
,
'2023-10-04'
,
'2023-10-05'
,
'2023-10-06'
]
let
excludeList
=
[
'2023-01-28'
,
'2023-01-29'
,
'2023-04-29'
,
'2023-04-30'
,
'2023-06-25'
,
'2023-10-07'
,
'2023-10-08'
]
let
curDay
=
dateFormat
(
new
Date
())
let
isWeekend
=
new
Date
().
getDay
()
==
0
||
new
Date
().
getDay
()
==
6
if
(
includeList
.
includes
(
curDay
)
||
(
!
excludeList
.
includes
(
curDay
)
&&
isWeekend
))
return
;
const
ROBOT_DATA
=
{
msgtype
:
"markdown"
,
markdown
:
{
content
:
`请各位填写日报,[https://www.kdocs.cn/l/crp55HhT7R9b](https://www.kdocs.cn/l/crp55HhT7R9b), 麻烦
${
plist
[
idx
]}
同学提交日报
${
new
Date
().
getDay
()
==
1
?
',并创建日报菜单'
:
''
}
`
,
},
};
const
result
=
await
ctx
.
curl
(
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5d90c43a-87e0-454c-8cc6-39db43cf9e2c"
,
{
method
:
"POST"
,
headers
:
{
"content-type"
:
"application/json"
,
},
data
:
JSON
.
stringify
(
ROBOT_DATA
),
}
);
ctx
.
app
.
cache
=
{
code
:
"0"
,
data
:
result
,
msg
:
"提醒成功"
,
};
},
};
\ No newline at end of file
\ No newline at end of file
app/utils/utils.js
View file @
3ca3330
/**
/**
* 对当前时间进行格式化
* 对当前时间进行格式化
*/
*/
const
fmtDateTime
=
()
=>
{
const
dateFormat
=
function
(
dateTime
,
format
=
'YYYY-MM-DD'
)
{
let
date
=
new
Date
();
const
date
=
new
Date
(
dateTime
)
const
config
=
{
YYYY
:
date
.
getFullYear
(),
MM
:
appendZero
(
date
.
getMonth
()
+
1
),
//getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11)
DD
:
appendZero
(
date
.
getDate
()),
HH
:
appendZero
(
date
.
getHours
()),
mm
:
appendZero
(
date
.
getMinutes
()),
ss
:
appendZero
(
date
.
getSeconds
())
}
for
(
const
key
in
config
)
{
format
=
format
.
replace
(
key
,
config
[
key
])
}
return
format
}
let
year
=
date
.
getFullYear
();
let
month
=
date
.
getMonth
()
+
1
;
let
hour
=
date
.
getHours
();
let
min
=
date
.
getMinutes
();
month
=
month
<
10
?
`0
${
month
}
`
:
month
;
function
appendZero
(
int
)
{
hour
=
hour
<
10
?
`0
${
hour
}
`
:
hour
;
if
(
int
<
10
)
{
min
=
min
<
10
?
`0
${
min
}
`
:
min
;
return
'0'
+
`
${
int
}
`
}
else
{
return
`
${
year
}
-
${
month
}
-
${
date
.
getDate
()}
${
hour
}
:
${
min
}
`
;
return
int
};
}
}
/**
/**
* 生成项目负责人
* 生成项目负责人
...
@@ -24,6 +34,6 @@ const genProjectOwners = (owners) => {
...
@@ -24,6 +34,6 @@ const genProjectOwners = (owners) => {
};
};
module
.
exports
=
{
module
.
exports
=
{
fmtDateTime
,
dateFormat
,
genProjectOwners
,
genProjectOwners
,
};
};
Write
Preview
Markdown
is supported
Attach a file
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 post a comment