Browse Source

告警推送

dev
巴林闲侠 2 years ago
parent
commit
995b3aa57e
  1. 1
      api/.vscode/launch.json
  2. 17
      api/app/lib/controllers/alarm/video.js
  3. 26
      api/app/lib/schedule/alarms_push.js
  4. 7
      api/config.js

1
api/.vscode/launch.json

@ -61,6 +61,7 @@
"--clickHouseProjectManage peppm8",
"--clickHouseVcmp video_access_dev",
"--clickHouseDataAlarm default",
"--clickHouseIot iot",
"--confirmAlarmAnxinUserId 1",
"--vcmpAppId 5048b08d-c449-4d7f-b1ec-f741012aefe8",

17
api/app/lib/controllers/alarm/video.js

@ -284,6 +284,22 @@ async function confirm (ctx) {
}
}
async function alarmAdded (ctx) {
try {
const { models } = ctx.fs.dc;
ctx.status = 200;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function vcmpAppAuthToken (ctx) {
try {
const { models } = ctx.fs.dc;
@ -306,5 +322,6 @@ module.exports = {
deviceType,
alarmList,
confirm,
alarmAdded,
vcmpAppAuthToken
};

26
api/app/lib/schedule/alarms_push.js

@ -4,7 +4,7 @@ module.exports = function (app, opts) {
const alarmsPush = app.fs.scheduleInit(
{
interval: '12 */1 * * * *',
immediate: true, // dev
// immediate: true, // dev
proRun: true,
},
async () => {
@ -112,7 +112,13 @@ module.exports = function (app, opts) {
`
).toPromise() :
[]
let searchStrucIds = strucListRes.map(s => s.id)
let strucThingId = []
let searchStrucIds = strucListRes.map(s => {
if (s.iotaThingId) {
strucThingId.push(s.iotaThingId)
}
return s.id
})
searchStrucIds = searchStrucIds.concat([991, 1052, 700])
@ -177,11 +183,13 @@ module.exports = function (app, opts) {
} else {
if (c.alarmType.includes('data_outages') || c.alarmType.includes('data_exception')) {
// 查了设备异常率 去安心云查当前项目下的设备数量
// TODO 等同步以太数据再查
deviceCount = 9999
// await clickHouse.anxinyun.query(`
// SELECT count(*) FROM
// `).toPromise()
let deviceCountRes =
strucThingId.length ?
await clickHouse.iot.query(`
SELECT count(DeviceId) AS count FROM device WHERE ThingId IN (${strucThingId.map(t => `'${t}'`).join(',')}, '-1')
`).toPromise()
: []
deviceCount = deviceCountRes.length ? deviceCountRes[0].count : 0
}
if (c.alarmType.includes('video_exception')) {
// 查了视频异常 去安心云查 接入的 萤石 设备数量
@ -675,9 +683,9 @@ module.exports = function (app, opts) {
}
return arr
}, [])
if (emails.length || 1) {
if (emails.length) {
await pushByEmail({
email: ['1650192445@qq.com', '777y'],
email: emails,
title: emailTitle,
text: '',
html: html

7
api/config.js

@ -43,6 +43,7 @@ args.option('clickHousePepEmis', 'clickHouse 项企数据库名称');
args.option('clickHouseProjectManage', 'clickHouse 项目管理数据库名称');
args.option('clickHouseVcmp', 'clickHouse 视频平台数据库名称');
args.option('clickHouseDataAlarm', 'clickHouse 视频平台数据告警库名称');
args.option('clickHouseIot', 'clickHouse IOT平台设备信息库名称');
args.option('confirmAlarmAnxinUserId', '确认告警时保存到 ES 的安心云的用户的 id');
@ -98,6 +99,7 @@ const CLICKHOUST_PEP_EMIS = process.env.CLICKHOUST_PEP_EMIS || flags.clickHouseP
const CLICKHOUST_PROJECT_MANAGE = process.env.CLICKHOUST_PROJECT_MANAGE || flags.clickHouseProjectManage
const CLICKHOUST_VCMP = process.env.CLICKHOUST_VCMP || flags.clickHouseVcmp
const CLICKHOUST_DATA_ALARM = process.env.CLICKHOUST_DATA_ALARM || flags.clickHouseDataAlarm
const CLICKHOUST_IOT = process.env.CLICKHOUST_IOT || flags.clickHouseIot
const CONFIRM_ALARM_ANXIN_USER_ID = process.env.CONFIRM_ALARM_ANXIN_USER_ID || flags.confirmAlarmAnxinUserId
@ -118,7 +120,7 @@ if (
|| !API_IOT_AUTH
|| !QINIU_DOMAIN_QNDMN_RESOURCE || !QINIU_BUCKET_RESOURCE || !QINIU_AK || !QINIU_SK
|| !CLICKHOUST_URL || !CLICKHOUST_PORT
|| !CLICKHOUST_ANXINCLOUD || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_PROJECT_MANAGE || !CLICKHOUST_VCMP || !CLICKHOUST_DATA_ALARM
|| !CLICKHOUST_ANXINCLOUD || !CLICKHOUST_PEP_EMIS || !CLICKHOUST_PROJECT_MANAGE || !CLICKHOUST_VCMP || !CLICKHOUST_DATA_ALARM || !CLICKHOUST_IOT
|| !CONFIRM_ALARM_ANXIN_USER_ID
|| !VCMP_APP_ID || !VCMP_APP_SECRET
) {
@ -233,6 +235,9 @@ const product = {
}, {
name: 'dataAlarm',
db: CLICKHOUST_DATA_ALARM
}, {
name: 'iot',
db: CLICKHOUST_IOT
}
]
}

Loading…
Cancel
Save