Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AppMonitorSubscriber
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nongyingchen
AppMonitorSubscriber
Commits
0a4e5af8
Commit
0a4e5af8
authored
May 21, 2019
by
trace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加对贷超通知的优化, 能打开对应的管理页面, 显示名字和ID
parent
7a57ea78
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
21 deletions
+84
-21
play.js
+84
-21
No files found.
play.js
View file @
0a4e5af8
...
...
@@ -39,6 +39,7 @@ let developer = ['yingchen.nong@starwin.com']
let
notifyEmail
=
developer
let
daichaoApps
=
[]
let
daichaoAppInfoes
=
{}
let
ourAppIds
=
[]
let
ourApps
=
{}
let
hitDaichao
=
isTest
()
?
1
:
0
...
...
@@ -159,16 +160,7 @@ async function startMonitor() {
dingDing
(
`今天不在时间段或者已发过当日在线 app 列表\n time:
${
new
Date
().
toLocaleTimeString
}
`
)
return
}
let
onlineApps
=
ourAppIds
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
offlineApps
=
ourAppIds
.
filter
(
val
=>
!
onlineApps
.
includes
(
val
))
let
daichaoOnlines
=
daichaoApps
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
daichaoOfflines
=
daichaoApps
.
filter
(
val
=>
!
daichaoOnlines
.
includes
(
val
))
let
content
=
''
content
+=
wrapSummary
(
`Gitlab 在线 app (
${
onlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
onlineApps
.
map
(
val
=>
link
(
val
)))
content
+=
wrapSummary
(
`Gitlab 下线 app (
${
offlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
offlineApps
.
map
(
val
=>
link
(
val
)))
content
+=
wrapSummary
(
`贷超在线 App (
${
daichaoOnlines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOnlines
.
map
(
val
=>
link
(
val
)))
content
+=
wrapSummary
(
`贷超下线 App (
${
daichaoOfflines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOfflines
.
map
(
val
=>
link
(
val
)))
let
content
=
generateDailyOnlineReport
()
sendEmail
(
content
)
})
.
then
(()
=>
{
...
...
@@ -204,13 +196,23 @@ async function startMonitor() {
}
}
function
generateDailyOnlineReport
()
{
let
onlineApps
=
ourAppIds
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
offlineApps
=
ourAppIds
.
filter
(
val
=>
!
onlineApps
.
includes
(
val
))
let
daichaoOnlines
=
daichaoApps
.
filter
(
val
=>
status
[
val
]
&&
status
[
val
].
status
||
false
)
let
daichaoOfflines
=
daichaoApps
.
filter
(
val
=>
!
daichaoOnlines
.
includes
(
val
))
let
content
=
''
content
+=
wrapSummary
(
`Gitlab 在线 app (
${
onlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
onlineApps
.
map
(
val
=>
link
(
val
)),
'green'
)
content
+=
wrapSummary
(
`Gitlab 下线 app (
${
offlineApps
.
length
}
/
${
ourAppIds
.
length
}
)`
,
offlineApps
.
map
(
val
=>
link
(
val
)),
'red'
)
content
+=
wrapSummary
(
`贷超在线 App (
${
daichaoOnlines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOnlines
.
map
(
val
=>
link
(
val
)),
'green'
)
content
+=
wrapSummary
(
`贷超下线 App (
${
daichaoOfflines
.
length
}
/
${
daichaoApps
.
length
}
)`
,
daichaoOfflines
.
map
(
val
=>
link
(
val
)),
'red'
)
return
content
}
async
function
getDaichao
()
{
await
getPromiss
(
daichao
)
.
then
(
val
=>
{
if
(
isTest
())
{
daichaoApps
=
[]
return
}
try
{
daichaoData
=
JSON
.
parse
(
val
&&
val
.
body
&&
val
.
body
||
"{}"
).
data
}
catch
(
err
)
{
...
...
@@ -220,6 +222,16 @@ async function getDaichao() {
}
daichaoApps
=
daichaoData
&&
daichaoData
.
map
(
app
=>
app
.
packageName
)
||
[]
for
(
index
in
(
daichaoData
&&
daichaoData
||
[]))
{
let
app
=
daichaoData
[
index
]
daichaoAppInfoes
[
app
.
packageName
]
=
{
name
:
app
.
name
,
daichaoId
:
app
.
id
}
}
if
(
isTest
())
{
daichaoApps
=
daichaoApps
.
slice
(
0
,
1
)
}
log
(
`代超数据:
${
daichaoApps
.
length
}
个`
)
monitorNames
[
"daichao"
]
=
daichaoApps
if
(
daichaoApps
.
length
==
0
)
{
...
...
@@ -232,6 +244,42 @@ async function getDaichao() {
})
}
// async function getDaichao(url) {
// await getPromiss(url)
// .then(val => {
// if (isTest()) {
// daichaoApps = []
// return
// }
// try {
// daichaoData = JSON.parse(val && val.body && val.body || "{}").data
// } catch (err) {
// errMsg = `贷超数据解析出错: ${err}`
// errorLog.push(errMsg)
// return
// }
// daichaoApps = daichaoData && daichaoData.map(app => app.packageName) || []
// daichaoAppInfoes = daichaoData && daichaoData.map(app => {
// let dcApp = {}
// dcApp[app.packageName] = {
// name: app.name,
// appId: app.id
// }
// return dcApp
// })
// log(`代超数据: ${daichaoApps.length} 个`)
// monitorNames["daichao"] = daichaoApps
// if (daichaoApps.length == 0) {
// log('代超数据为空')
// }
// })
// .catch(err => {
// errorLog.push(`贷超获取失败:${err.toString()}`)
// return
// })
// }
async
function
getConfig
()
{
await
getPromiss
(
subApi
).
then
(
val
=>
{
log
(
'------------ get congfig from gitlab -----------'
)
...
...
@@ -245,7 +293,7 @@ async function getConfig() {
}
ourApps
=
dataes
.
ourApps
||
{}
ourAppIds
=
Object
.
keys
(
ourApps
)
ourAppIds
=
Object
.
keys
(
ourApps
)
.
slice
(
0
,
1
)
if
(
ourAppIds
.
length
==
0
)
{
ourApps
=
{
"com.globe.gcash.android"
:
"测试我的"
}
ourAppIds
=
[
"com.globe.gcash.android"
]
...
...
@@ -387,6 +435,9 @@ async function monitorIfOnline(names) {
log
(
`获取数量:
${
names
.
length
}
`
)
for
(
let
i
in
names
)
{
let
name
=
names
[
i
]
if
(
name
.
includes
(
'://'
))
{
continue
}
log
(
`获取:
${
name
}
`
)
await
sleep
(
sleepTime
)
await
gplay
.
app
({
appId
:
name
,
requestOptions
:
{
timeout
:
requestTimeout
}
})
...
...
@@ -421,7 +472,7 @@ async function monitorIfOnline(names) {
function
link
(
name
,
countOurs
)
{
let
ourName
=
isOurs
(
name
,
countOurs
)
return
`
${
ourName
}
return
`
${
ourName
}
____
<a href="
${
base_gp_url
}${
name
}
">
${
getRegion
(
name
)}
[
${
monitorType
[
status
[
name
]
&&
status
[
name
].
category
||
''
]
||
''
}
] -
${
name
}
<br/>
...
...
@@ -459,6 +510,11 @@ function genMail() {
let
today
=
new
Date
()
let
needSendList
=
(
theDaySendList
.
includes
(
today
.
getDay
()))
&&
(
lastSendListDate
.
toLocaleDateString
()
!=
today
.
toLocaleDateString
())
let
nowGenerate
=
`<br/><br/>邮件生成时间: <br/>
${
new
Date
().
toLocaleString
()}
`
let
lastLoopDate
=
status
[
'lastLoopDate'
]
&&
new
Date
(
status
[
'lastLoopDate'
])
||
new
Date
()
let
loopInterval
=
(
new
Date
()).
getHours
()
-
lastLoopDate
.
getHours
()
let
lastGenerate
=
`<br/><br/><br/>上次循环时间
${
lastLoopDate
.
toLocaleString
()}
, 间隔:
${
loopInterval
}
小时`
if
(
!
isFirstRun
&&
!
needSendList
&&
newOffline
.
length
==
0
...
...
@@ -588,7 +644,12 @@ function genMail() {
emailContent
+=
`<div>监控总数量:
${
total
}
</div>`
status
.
sendListDate
=
today
.
toString
()
}
emailContent
+=
`<br/><br/><br/>
${
new
Date
().
toLocaleString
()}
`
// 有变化也发送当前监控在线情况
emailContent
+=
generateDailyOnlineReport
()
emailContent
+=
nowGenerate
emailContent
+=
lastGenerate
log
(
`生成邮件内容: \n
${
emailContent
}
`
)
// 清空临时栈
newOffline
=
[]
...
...
@@ -603,7 +664,8 @@ function genMail() {
function
isOurs
(
name
,
countOurs
)
{
if
(
daichaoApps
.
includes
(
name
))
{
return
"🏦(贷超)"
return
`<a href="http://admin.uuang.co.id/#/loan/
${
daichaoAppInfoes
[
name
]
&&
daichaoAppInfoes
[
name
].
daichaoId
||
''
}
">🏦(贷超 [
${
daichaoAppInfoes
[
name
].
daichaoId
}
] _ <
${
daichaoAppInfoes
[
name
].
name
}
>(->MGT)) | </a>`
}
if
(
ourAppIds
.
includes
(
name
))
{
return
`📌(
${
ourApps
[
name
]
||
'No Name in Gitlab'
}
)`
...
...
@@ -790,10 +852,11 @@ function wrapSummary(title, list, color = 'black') {
function
isInTimeInRangeToday
(
start
,
end
)
{
let
dayKey
=
"lastDailyOnlinesAppsDate"
let
now
=
new
Date
()
let
lastDate
=
new
Date
(
status
[
dayKey
]
||
'Tue Jan 29 2019 19:32:24 GMT+0800 (CST)'
)
lastDate
.
setHours
(
lastDate
.
getHours
()
+
24
)
today
=
new
Date
(
now
.
toDateString
())
let
lastDate
=
(
new
Date
(
status
[
dayKey
]
||
'Tue May 20 2019 19:32:24 GMT+0800 (CST)'
)).
toDateString
()
lastDate
=
new
Date
(
lastDate
)
// 去掉范围的验证, 只要大于某一时间就发, 且只发一次
if
(
start
<
now
.
getHours
()
&&
now
>
lastDate
)
{
if
(
start
<
now
.
getHours
()
&&
today
>
lastDate
)
{
status
[
dayKey
]
=
Date
()
return
true
}
...
...
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