Browse Source

查询数据告警详情

dev
巴林闲侠 2 years ago
parent
commit
537f9d1e77
  1. 8
      api/app/lib/controllers/alarm/app.js
  2. 31
      api/app/lib/controllers/alarm/data.js
  3. 3
      api/app/lib/routes/alarm/index.js
  4. 5
      api/app/lib/utils/dataRange.js

8
api/app/lib/controllers/alarm/app.js

@ -235,10 +235,12 @@ async function apiErrorList (ctx) {
} }
if (errType) { if (errType) {
if (errType = 'element') { if (errType == 'element') {
findOption.where.screenshot = { $ne: null }
} else if (errType == 'timeout') {
} else if (errType == 'apiError') {
findOption.where.screenshot = null findOption.where.screenshot = null
} else {
findOption.where.statusCode = errType
} }
} }
if (confirmState) { if (confirmState) {

31
api/app/lib/controllers/alarm/data.js

@ -6,15 +6,16 @@ async function list (ctx) {
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config const { database: anxinyun } = clickHouse.anxinyun.opts.config
const { pepProjectId } = ctx.query
const isSuper = judgeSuper(ctx) const isSuper = judgeSuper(ctx)
let anxinStrucIds = null let anxinStrucIds = null
if (!isSuper) { if (!isSuper || pepProjectId) {
anxinStrucIds = await anxinStrucIdRange(ctx) anxinStrucIds = await anxinStrucIdRange({ ctx, pepProjectId })
} }
const alarmRes = await clickHouse.dataAlarm.query(` const alarmRes = await clickHouse.dataAlarm.query(`
SELECT SELECT
AlarmId, SourceName, name AlarmId, SourceName, name AS StructureName, StructureId
FROM FROM
alarms alarms
LEFT JOIN ${anxinyun}.t_structure LEFT JOIN ${anxinyun}.t_structure
@ -33,6 +34,28 @@ async function list (ctx) {
} }
} }
async function detail (ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { alarmId } = ctx.query
const detailRes = await clickHouse.dataAlarm.query(`
SELECT * FROM alarm_details WHERE AlarmId = '${alarmId}' ORDER BY Time ASC
`).toPromise()
ctx.status = 200;
ctx.body = detailRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = { module.exports = {
list list,
detail
}; };

3
api/app/lib/routes/alarm/index.js

@ -28,4 +28,7 @@ module.exports = function (app, router, opts) {
// 数据告警 // 数据告警
app.fs.api.logAttr['GET/alarm/data/list'] = { content: '查询数据告警列表', visible: true }; app.fs.api.logAttr['GET/alarm/data/list'] = { content: '查询数据告警列表', visible: true };
router.get('/alarm/data/list', dataAlarm.list); router.get('/alarm/data/list', dataAlarm.list);
app.fs.api.logAttr['GET/alarm/data/detail'] = { content: '查询数据告警详情', visible: true };
router.get('/alarm/data/detail', dataAlarm.detail);
}; };

5
api/app/lib/utils/dataRange.js

@ -14,15 +14,16 @@ module.exports = function (app, opts) {
} }
} }
async function anxinStrucIdRange (ctx) { async function anxinStrucIdRange ({ ctx, pepProjectId }) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { userInfo = {} } = ctx.fs.api || {}; const { userInfo = {} } = ctx.fs.api || {};
const { correlationProject = [] } = userInfo const { correlationProject = [] } = userInfo
// TODO 这儿也许需要判断传进来的 pepProjectId 在不在当前用户的关注范围内
const bindRes = await models.ProjectCorrelation.findAll({ const bindRes = await models.ProjectCorrelation.findAll({
where: { where: {
id: { $in: correlationProject }, id: { $in: pepProjectId ? [pepProjectId] : correlationProject },
del: false del: false
} }
}) })

Loading…
Cancel
Save