Commit 0a4e5af8 by trace

添加对贷超通知的优化, 能打开对应的管理页面, 显示名字和ID

parent 7a57ea78
...@@ -39,6 +39,7 @@ let developer = ['yingchen.nong@starwin.com'] ...@@ -39,6 +39,7 @@ let developer = ['yingchen.nong@starwin.com']
let notifyEmail = developer let notifyEmail = developer
let daichaoApps = [] let daichaoApps = []
let daichaoAppInfoes = {}
let ourAppIds = [] let ourAppIds = []
let ourApps = {} let ourApps = {}
let hitDaichao = isTest() ? 1 : 0 let hitDaichao = isTest() ? 1 : 0
...@@ -159,16 +160,7 @@ async function startMonitor() { ...@@ -159,16 +160,7 @@ async function startMonitor() {
dingDing(`今天不在时间段或者已发过当日在线 app 列表\n time:${new Date().toLocaleTimeString}`) dingDing(`今天不在时间段或者已发过当日在线 app 列表\n time:${new Date().toLocaleTimeString}`)
return return
} }
let content = 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)))
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)))
sendEmail(content) sendEmail(content)
}) })
.then(() => { .then(() => {
...@@ -204,13 +196,23 @@ async function startMonitor() { ...@@ -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() { async function getDaichao() {
await getPromiss(daichao) await getPromiss(daichao)
.then(val => { .then(val => {
if (isTest()) {
daichaoApps = []
return
}
try { try {
daichaoData = JSON.parse(val && val.body && val.body || "{}").data daichaoData = JSON.parse(val && val.body && val.body || "{}").data
} catch (err) { } catch (err) {
...@@ -220,6 +222,16 @@ async function getDaichao() { ...@@ -220,6 +222,16 @@ async function getDaichao() {
} }
daichaoApps = daichaoData && daichaoData.map(app => app.packageName) || [] 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} 个`) log(`代超数据: ${daichaoApps.length} 个`)
monitorNames["daichao"] = daichaoApps monitorNames["daichao"] = daichaoApps
if (daichaoApps.length == 0) { if (daichaoApps.length == 0) {
...@@ -232,6 +244,42 @@ async function getDaichao() { ...@@ -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() { async function getConfig() {
await getPromiss(subApi).then(val => { await getPromiss(subApi).then(val => {
log('------------ get congfig from gitlab -----------') log('------------ get congfig from gitlab -----------')
...@@ -245,7 +293,7 @@ async function getConfig() { ...@@ -245,7 +293,7 @@ async function getConfig() {
} }
ourApps = dataes.ourApps || {} ourApps = dataes.ourApps || {}
ourAppIds = Object.keys(ourApps) ourAppIds = Object.keys(ourApps).slice(0, 1)
if (ourAppIds.length == 0) { if (ourAppIds.length == 0) {
ourApps = { "com.globe.gcash.android": "测试我的" } ourApps = { "com.globe.gcash.android": "测试我的" }
ourAppIds = ["com.globe.gcash.android"] ourAppIds = ["com.globe.gcash.android"]
...@@ -387,6 +435,9 @@ async function monitorIfOnline(names) { ...@@ -387,6 +435,9 @@ async function monitorIfOnline(names) {
log(`获取数量: ${names.length}`) log(`获取数量: ${names.length}`)
for (let i in names) { for (let i in names) {
let name = names[i] let name = names[i]
if (name.includes('://')) {
continue
}
log(`获取: ${name}`) log(`获取: ${name}`)
await sleep(sleepTime) await sleep(sleepTime)
await gplay.app({ appId: name, requestOptions: { timeout: requestTimeout } }) await gplay.app({ appId: name, requestOptions: { timeout: requestTimeout } })
...@@ -421,7 +472,7 @@ async function monitorIfOnline(names) { ...@@ -421,7 +472,7 @@ async function monitorIfOnline(names) {
function link(name, countOurs) { function link(name, countOurs) {
let ourName = isOurs(name, countOurs) let ourName = isOurs(name, countOurs)
return `${ourName} return `${ourName} ____
<a href="${base_gp_url}${name}"> <a href="${base_gp_url}${name}">
${getRegion(name)}[${monitorType[status[name] && status[name].category || ''] || ''}] - ${name} ${getRegion(name)}[${monitorType[status[name] && status[name].category || ''] || ''}] - ${name}
<br/> <br/>
...@@ -459,6 +510,11 @@ function genMail() { ...@@ -459,6 +510,11 @@ function genMail() {
let today = new Date() let today = new Date()
let needSendList = (theDaySendList.includes(today.getDay())) && (lastSendListDate.toLocaleDateString() != today.toLocaleDateString()) 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 if (!isFirstRun
&& !needSendList && !needSendList
&& newOffline.length == 0 && newOffline.length == 0
...@@ -588,7 +644,12 @@ function genMail() { ...@@ -588,7 +644,12 @@ function genMail() {
emailContent += `<div>监控总数量: ${total}</div>` emailContent += `<div>监控总数量: ${total}</div>`
status.sendListDate = today.toString() status.sendListDate = today.toString()
} }
emailContent += `<br/><br/><br/>${new Date().toLocaleString()}`
// 有变化也发送当前监控在线情况
emailContent += generateDailyOnlineReport()
emailContent += nowGenerate
emailContent += lastGenerate
log(`生成邮件内容: \n${emailContent}`) log(`生成邮件内容: \n${emailContent}`)
// 清空临时栈 // 清空临时栈
newOffline = [] newOffline = []
...@@ -603,7 +664,8 @@ function genMail() { ...@@ -603,7 +664,8 @@ function genMail() {
function isOurs(name, countOurs) { function isOurs(name, countOurs) {
if (daichaoApps.includes(name)) { 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)) { if (ourAppIds.includes(name)) {
return `📌(${ourApps[name] || 'No Name in Gitlab'})` return `📌(${ourApps[name] || 'No Name in Gitlab'})`
...@@ -790,10 +852,11 @@ function wrapSummary(title, list, color = 'black') { ...@@ -790,10 +852,11 @@ function wrapSummary(title, list, color = 'black') {
function isInTimeInRangeToday(start, end) { function isInTimeInRangeToday(start, end) {
let dayKey = "lastDailyOnlinesAppsDate" let dayKey = "lastDailyOnlinesAppsDate"
let now = new Date() let now = new Date()
let lastDate = new Date(status[dayKey] || 'Tue Jan 29 2019 19:32:24 GMT+0800 (CST)') today = new Date(now.toDateString())
lastDate.setHours(lastDate.getHours() + 24) 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() status[dayKey] = Date()
return true return true
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment