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
a3e6b3aa
Commit
a3e6b3aa
authored
May 24, 2019
by
huangchao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://47.100.14.92:8929/nongyingchen/AppMonitorSubscriber
parents
6ec3aab0
c209fe6f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
28 deletions
+57
-28
play.js
+56
-27
subscriber.json
+1
-1
No files found.
play.js
View file @
a3e6b3aa
let
version
=
'1.0'
let
release
=
`<div><br/>
<br/>1. <br/>
加入对贷超 MGT 的支持. 支持点击"<贷超名MGT>"打开贷超对应管理系统, 点击包名 ID 打开 GooglePlay<br/>
<br/>2. <br/>
在线列表上下线颜色区分. 上线: 绿色, 下线: 红色.<br/>
<br/>other:<br/>
当监控中有上下线变化才会发送邮件, 并且会带上当前在线下线列表<br/>
上下线通知邮件中第一行, "《》" 中的是 VTPM 本次监控情况涉及 APP 数量, "【】" 中是本次监控通知中贷超 APP 涉及数量<br/>
<div/>
<br/>
<br/>
<br/>
`
// 依赖
var
gplay
=
require
(
'google-play-scraper'
)
var
nodemailer
=
require
(
'nodemailer'
)
// 工具
var
fs
=
require
(
'fs'
)
var
username
=
require
(
'os'
).
userInfo
().
username
var
request
=
require
(
'request'
)
var
util
=
require
(
'util'
)
var
getPromiss
=
util
.
promisify
(
request
.
get
)
// 地址
let
subApi
=
"https://git.starwin.tech/nongyingchen/AppMonitorSubscriber/raw/master/subscriber.json"
log
(
`当前奔跑在:
${
username
}
`
)
let
ding
=
'https://oapi.dingtalk.com/robot/send?access_token='
let
debugDingding
=
`
${
ding
}
bf03c69128b771107b8715911b8a76db61a55cbd8b00e1a2c955578c2a3da719`
let
notifyDingding
=
`
${
ding
}
61403ec65efd7a9e40cb6d490e1bfab8aff28800696918a23ec4dffdf5aa1315`
let
daichao
=
`admin/loan/listactive?current=0&size=10000&descs%5B0%5D=priority&packageId=10002`
let
daichaoRegion
=
[
'http://admin.uuang.co.id/'
,
'http://admin.ph.g-cashing.com/'
,
'http://admin.a.vaylaco.com/'
]
let
daichaoRegion
=
{
'http://admin.uuang.co.id/'
:
'印尼贷超'
,
'http://admin.ph.g-cashing.com/'
:
'菲律宾贷超'
,
'http://admin.a.vaylaco.com/'
:
'越南贷超'
}
// Config ------------------------------------------------------------
let
sec
=
1000
;
...
...
@@ -87,8 +107,8 @@ let allNames = names => {
return
Array
.
from
(
new
Set
(
an
))
}
function
log
(
content
)
{
if
(
isTest
())
{
function
log
(
content
,
useRelease
=
false
)
{
if
(
isTest
()
||
useRelease
)
{
console
.
log
(
`[
${
new
Date
().
toLocaleString
()}
]:
${
content
}
`
)
}
}
...
...
@@ -108,7 +128,7 @@ try {
isFirstRun
=
false
}
catch
(
err
)
{
isFirstRun
=
true
console
.
log
(
`状态文件不存在, 直接使用空的{}\n
${
err
.
toString
()}
`
)
log
(
`状态文件不存在, 直接使用空的{}\n
${
err
.
toString
()}
`
,
true
)
}
// 获取记录上次更新监控名得文件
...
...
@@ -116,13 +136,13 @@ try {
let
fileNames
=
JSON
.
parse
(
fs
.
readFileSync
(
monitorApps
,
'utf-8'
))
if
(
Array
.
isArray
(
fileNames
))
{
monitorNames
[
'vn'
]
=
fileNames
console
.
log
(
'原来只记录数组形式, 现在变更为对象形式, 原数组放到vn数组中'
)
log
(
'原来只记录数组形式, 现在变更为对象形式, 原数组放到vn数组中'
,
true
)
}
else
{
monitorNames
=
fileNames
}
isFirstRun
=
false
}
catch
(
err
)
{
console
.
log
(
`监控列表文件不存在, 直接使用空的{}\n
${
err
.
toString
()}
`
)
log
(
`监控列表文件不存在, 直接使用空的{}\n
${
err
.
toString
()}
`
,
true
)
}
let
newOnline
=
[]
// 新上架
let
newOffline
=
[]
// 新下架
...
...
@@ -130,6 +150,7 @@ let permissionChange = {} // 权限变化
let
failedApps
=
[]
// 获取失败的
let
newTopMonitorNames
=
{}
let
errorLog
=
[]
// 错误记录
let
newDeploy
=
true
log
(
'log 打开'
)
...
...
@@ -141,12 +162,16 @@ if (isTest()) {
startMonitor
()
}
sendEmail
(
`开始监控-----------------------`
)
async
function
startMonitor
()
{
log
(
'开始监控'
)
while
(
start
)
{
log
(
`抓取一圈`
)
await
getConfig
()
.
then
(()
=>
{
// 部署通知, 更新说明
sendEmail
(
`<div>爬虫部署版本:
${
version
}
</div>更新说明:
${
release
}
`
)
})
.
then
(
getDaichao
)
.
then
(
getTop100
)
.
then
(()
=>
fs
.
writeFileSync
(
monitorApps
,
JSON
.
stringify
(
monitorNames
)))
// 保存到本地
...
...
@@ -179,7 +204,7 @@ async function startMonitor() {
lastIntervalTime
=
lastIntervalTime
*
2
let
content
=
`监控出错
${
err
}
\n间隔时间调整为
${(
lastIntervalTime
)
/
minute
}
分钟`
content
+=
markError
()
console
.
log
(
content
)
log
(
content
,
true
)
sendEmail
(
content
,
developer
)
dingDing
(
content
)
if
(
err
.
toString
().
includes
(
'ENOSPC'
))
{
...
...
@@ -217,8 +242,9 @@ function generateDailyOnlineReport() {
async
function
getDaichao
()
{
let
allRegionDaichaoApps
=
[]
for
(
index
in
daichaoRegion
)
{
let
region
=
daichaoRegion
[
index
]
for
(
region
in
daichaoRegion
)
{
// for (index in Object.keys(daichaoRegion)) {
// let region = daichaoRegion[index]
daichaoApiUrl
=
region
+
daichao
log
(
` 贷超 url:
${
daichaoApiUrl
}
`
)
await
getPromiss
(
daichaoApiUrl
)
...
...
@@ -237,7 +263,8 @@ async function getDaichao() {
daichaoAppInfoes
[
app
.
packageName
]
=
{
name
:
app
.
name
,
daichaoId
:
app
.
id
,
mgt
:
`
${
region
}
#/loan/`
mgt
:
`
${
region
}
#/loan/`
,
region
:
daichaoRegion
[
region
]
}
}
if
(
isTest
())
{
...
...
@@ -409,7 +436,7 @@ async function getTop100() {
requestOptions
:
{
timeout
:
requestTimeout
}
})
.
then
(
res
=>
{
console
.
log
(
`获取到 <
${
monitorRegion
[
region
]}
>[
${
monitorType
[
type
]}
]排名:
${
i
*
120
}
~
${
i
*
120
+
getNum
}
`
)
log
(
`获取到 <
${
monitorRegion
[
region
]}
>[
${
monitorType
[
type
]}
]排名:
${
i
*
120
}
~
${
i
*
120
+
getNum
}
`
,
true
)
if
(
res
&&
res
.
length
&&
res
.
length
>
0
)
{
res
.
forEach
(
app
=>
{
...
...
@@ -428,7 +455,7 @@ async function getTop100() {
}
})
.
catch
(
err
=>
{
console
.
log
(
`获取排名<
${
monitorRegion
[
region
]}
> 错误:
${
err
.
message
}
`
)
log
(
`获取排名<
${
monitorRegion
[
region
]}
> 错误:
${
err
.
message
}
`
,
true
)
throw
err
})
}
...
...
@@ -469,17 +496,17 @@ async function monitorIfOnline(names) {
})
.
catch
((
err
)
=>
{
if
(
err
.
toString
().
includes
(
'404'
))
{
console
.
log
(
`获取不到:
${
name
}
, error:
${
err
}
`
)
log
(
`获取不到:
${
name
}
, error:
${
err
}
`
,
true
)
failedApps
.
push
(
name
)
judgeNewOffline
(
name
)
let
a
=
status
[
name
]
||
{}
status
[
name
]
=
{
...
a
,
status
:
false
,
date
:
Date
().
toString
()
}
}
else
if
(
err
.
toString
().
includes
(
'ETIMEDOUT'
))
{
console
.
log
(
`连接超时:
${
err
.
toString
()}
`
)
log
(
`连接超时:
${
err
.
toString
()}
`
,
true
)
throw
err
}
else
{
errorLog
.
push
(
`Motitor Online Error:
${
link
(
name
,
true
)}
-
${
err
.
message
}
`
)
console
.
log
(
`获取在线错误:
${
name
}
,
${
err
.
message
}
`
)
log
(
`获取在线错误:
${
name
}
,
${
err
.
message
}
`
,
true
)
}
})
}
...
...
@@ -661,6 +688,8 @@ function genMail() {
}
// 有变化也发送当前监控在线情况
emailContent
+=
'<br/><br/><br/>'
emailContent
+=
'在线/下线 情况:'
emailContent
+=
generateDailyOnlineReport
()
emailContent
+=
nowGenerate
...
...
@@ -674,14 +703,14 @@ function genMail() {
errorLog
=
[]
newTopMonitorNames
=
{}
return
`<div>
${
firstLine
}
</div><br/>
${
emailContent
}
`
return
`<div>
${
firstLine
}
</div><br/>
${
emailContent
}
<br/>version:
${
version
}
`
}
function
isOurs
(
name
,
countOurs
)
{
let
prefix
=
''
if
(
daichaoApps
.
includes
(
name
))
{
prefix
=
`<a href="
${
daichaoAppInfoes
[
name
].
mgt
}${
daichaoAppInfoes
[
name
]
&&
daichaoAppInfoes
[
name
].
daichaoId
||
''
}
">
🏦(贷超 [
${
daichaoAppInfoes
[
name
].
daichaoId
}
] _
<
${
daichaoAppInfoes
[
name
].
name
}
>(->MGT)) | </a>`
prefix
=
`
🏦(贷超.
${
daichaoAppInfoes
[
name
].
region
}
[
${
daichaoAppInfoes
[
name
].
daichaoId
}
]__
<a href="
${
daichaoAppInfoes
[
name
].
mgt
}${
daichaoAppInfoes
[
name
]
&&
daichaoAppInfoes
[
name
].
daichaoId
||
''
}
"> <
${
daichaoAppInfoes
[
name
].
name
}
>(->MGT)) | </a>`
}
if
(
ourAppIds
.
includes
(
name
))
{
if
(
prefix
!=
''
)
{
...
...
@@ -719,7 +748,7 @@ function aliveContent(date, lastSend) {
function
sendEmail
(
content
,
to
=
notifyEmail
)
{
if
(
content
==
null
||
content
==
undefined
||
content
==
''
)
{
console
.
log
(
'没有生成内容, 检查心跳'
)
log
(
'没有生成内容, 检查心跳'
,
true
)
let
date
=
new
Date
()
let
lastDing
=
new
Date
(
status
.
lastDingDate
||
'Tue Jan 29 2019 19:32:24 GMT+0800 (CST)'
)
let
lastSend
=
new
Date
(
status
.
lastSendDate
||
'Tue Jan 29 2019 19:32:24 GMT+0800 (CST)'
)
...
...
@@ -743,7 +772,7 @@ function sendEmail(content, to = notifyEmail) {
}
return
}
console
.
log
(
`发送email:
${
content
.
length
}
`
)
log
(
`发送email:
${
content
.
length
}
`
,
true
)
// if (content.indexOf('Error') != -1) {
// to = developer
// } else {
...
...
@@ -758,7 +787,7 @@ function sendEmail(content, to = notifyEmail) {
secure
:
false
,
auth
:
{
user
:
myEmail
,
pass
:
'
rwGxHWrxYKJJ2xnu
'
pass
:
'
3Yth5apYLqNiAjMq
'
}
})
...
...
@@ -775,9 +804,9 @@ function sendEmail(content, to = notifyEmail) {
trans
.
sendMail
(
mailOption
,
(
error
,
info
)
=>
{
if
(
error
)
{
return
console
.
log
(
`发生错误:
${
error
}
`
);
return
log
(
`发生错误:
${
error
}
`
,
true
);
}
console
.
log
(
`message
${
info
.
messageId
}
send:
${
info
.
response
}
`
)
log
(
`message
${
info
.
messageId
}
send:
${
info
.
response
}
`
,
true
)
})
dingDing
(
content
,
notifyDingding
)
...
...
subscriber.json
View file @
a3e6b3aa
...
...
@@ -60,7 +60,7 @@
"ky.com.haimaloan"
:
"2017 youdong"
,
"com.qcash.meiko"
:
"2018 Qcash"
,
"com.tdong.tco"
:
"2019 Tdong"
,
"com.
vndoa.usehaloow
"
:
"2020 VNDloan"
,
"com.
zccd.afsrv
"
:
"2020 VNDloan"
,
"com.yuioqwe.cash"
:
"No.2021 Wdong/Wcash"
,
"com.bsnwjqwe.vgn"
:
"2022 Fast Dong"
,
"com.oweiq.saldh"
:
"2023 Lucky Wallet"
,
...
...
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