Browse Source

应用告警 type

dev
巴林闲侠 2 years ago
parent
commit
69b016796b
  1. 2
      api/.vscode/launch.json
  2. 10
      api/app/lib/controllers/alarm/app.js
  3. 23
      api/app/lib/controllers/alarm/data.js
  4. 11
      api/app/lib/models/app_alarm.js
  5. 2
      api/sequelize-automate.config.js
  6. 2
      script/0.0.4/schema/1.alert_table.sql

2
api/.vscode/launch.json

@ -50,7 +50,7 @@
// "--clickHouseDataAlarm default",
//
"--clickHouseAnxincloud Anxinyun8",
"--clickHouseAnxincloud Anxinyun11",
"--clickHousePepEmis pepca8",
"--clickHouseProjectManage peppm8",
"--clickHouseVcmp video_accrss1",

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

@ -132,16 +132,20 @@ async function notedInspection (ctx) {
async function apiError (ctx) {
try {
const models = ctx.fs.dc.models;
const { projectAppId, alarmContent, router, statusCode, screenshot = '' } = ctx.request.body
const { projectAppId, alarmContent, router, statusCode, screenshot = '', type } = ctx.request.body
const now = moment().format()
if (!type) {
throw '请标明告警类型 type'
}
let storageData = {
projectAppId, alarmContent, router, statusCode
projectAppId, alarmContent, router, statusCode, type
}
const existRes = await models.AppAlarm.findOne({
where: {
projectAppId, alarmContent, router, statusCode,
confirm: null
confirm: null, type
}
})
if (existRes) {

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

@ -6,21 +6,38 @@ async function list (ctx) {
const { clickHouse } = ctx.app.fs
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config
const { pepProjectId } = ctx.query
const { pepProjectId, groupId, sustainTimeStart, sustainTimeEnd } = ctx.query
const isSuper = judgeSuper(ctx)
let anxinStrucIds = null
if (!isSuper || pepProjectId) {
anxinStrucIds = await anxinStrucIdRange({ ctx, pepProjectId })
}
let whereOption = []
if (anxinStrucIds) {
whereOption.push(`${anxinyun}.t_structure.id IN (${anxinStrucIds.join(",")})`)
}
if (groupId) {
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`)
}
if (groupUnitId) {
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`)
}
if (sustainTimeStart && sustainTimeEnd) {
whereOption.push(``)
}
const alarmRes = await clickHouse.dataAlarm.query(`
SELECT
AlarmId, SourceName, name AS StructureName, StructureId
AlarmId, SourceName,
${anxinyun}.t_structure.name AS StructureName, StructureId,
${anxinyun}.t_alarm_code.name AS AlarmCodeDescribe
FROM
alarms
LEFT JOIN ${anxinyun}.t_structure
ON ${anxinyun}.t_structure.id = alarms.StructureId
${anxinStrucIds ? 'WHERE ' + anxinyun + '.t_structure.id IN (' + anxinStrucIds.join(",") + ')' : ''}
LEFT JOIN ${anxinyun}.t_alarm_code
ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode
${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''}
`).toPromise();
ctx.status = 200;

11
api/app/lib/models/app_alarm.js

@ -34,7 +34,7 @@ module.exports = dc => {
autoIncrement: false,
references: {
key: "id",
model: "projectApp"
model: "app"
}
},
appDomain: {
@ -126,6 +126,15 @@ module.exports = dc => {
primaryKey: false,
field: "confirm_auto",
autoIncrement: false
},
type: {
type: DataTypes.INTEGER,
allowNull: true,
defaultValue: null,
comment: null,
primaryKey: false,
field: "type",
autoIncrement: false
}
}, {
tableName: "app_alarm",

2
api/sequelize-automate.config.js

@ -26,7 +26,7 @@ module.exports = {
dir: './app/lib/models', // 指定输出 models 文件的目录
typesDir: 'models', // 指定输出 TypeScript 类型定义的文件目录,只有 TypeScript / Midway 等会有类型定义
emptyDir: false, // !!! 谨慎操作 生成 models 之前是否清空 `dir` 以及 `typesDir`
tables: ['project_app'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
tables: ['app_alarm'], // 指定生成哪些表的 models,如 ['user', 'user_post'];如果为 null,则忽略改属性
skipTables: [], // 指定跳过哪些表的 models,如 ['user'];如果为 null,则忽略改属性
tsNoCheck: false, // 是否添加 `@ts-nocheck` 注释到 models 文件中
ignorePrefix: [], // 生成的模型名称忽略的前缀,因为 项目中有以下表名是以 t_ 开头的,在实际模型中不需要, 可以添加多个 [ 't_data_', 't_',] ,长度较长的 前缀放前面

2
script/0.0.4/schema/1.alert_table.sql

@ -0,0 +1,2 @@
alter table app_alarm
add type int;
Loading…
Cancel
Save