Commit 87407989 authored by mqf_0707's avatar mqf_0707

钉钉告警优化

parent 4447fbac
{ {
"cloud": { "cloud": {
"type": "CLOUDAPP" "type": "CLOUDAPP"
} },
"exclude": [
"server/**"
]
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"description": "11", "description": "11",
"main": "index.js", "main": "index.js",
"title": "测试活动",
"author": "duiba", "author": "duiba",
"license": "ISC", "license": "ISC",
"sdkVersion": "*", "sdkVersion": "*",
......
...@@ -119,8 +119,3 @@ export const sellerId = '1234' ...@@ -119,8 +119,3 @@ export const sellerId = '1234'
// C端的APP NAME // C端的APP NAME
export const C_APP_NAME: string = `promotioncenter-${appId}` export const C_APP_NAME: string = `promotioncenter-${appId}`
// 钉钉告警 活动名称
export const activityName = ''
// 开发者手机号
export const phone = ''
...@@ -42,7 +42,7 @@ export default function preUpdate(checks: IFunction[]) { ...@@ -42,7 +42,7 @@ export default function preUpdate(checks: IFunction[]) {
console.log(error, 'preUpdateUser-error') console.log(error, 'preUpdateUser-error')
recordErrorLog(context, baseInfos, error.toString(), error.stack) recordErrorLog(context, baseInfos, error.toString(), error.stack)
// 云告警 // 云告警
cloundAlarm(context, error.toString()) cloundAlarm(context, error.toString(), error.stack)
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
return method.apply(target, [context, { ...baseInfos }, services, preCheckData]) return method.apply(target, [context, { ...baseInfos }, services, preCheckData])
......
...@@ -58,7 +58,7 @@ export default function requestCountLimit(limitCount: number, limitTime: number) ...@@ -58,7 +58,7 @@ export default function requestCountLimit(limitCount: number, limitTime: number)
console.log('error', error) console.log('error', error)
recordErrorLog(context, baseInfos, error.toString(), error.stack) recordErrorLog(context, baseInfos, error.toString(), error.stack)
// 云告警 // 云告警
cloundAlarm(context, error.toString()) cloundAlarm(context, error.toString(), error.stack)
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
......
...@@ -47,7 +47,7 @@ export default function requestRateLimit(rate = 500) { ...@@ -47,7 +47,7 @@ export default function requestRateLimit(rate = 500) {
console.log('error', error) console.log('error', error)
recordErrorLog(context, baseInfos, error.toString(), error.stack) recordErrorLog(context, baseInfos, error.toString(), error.stack)
// 云告警 // 云告警
cloundAlarm(context, error.toString()) cloundAlarm(context, error.toString(), error.stack)
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
......
import { phone, activityName } from '../../constants' const configPackage = require('../../../package.json')
/** /**
* 告警信息 * 告警信息
* @param message * @param message
*/ */
export const cloundAlarm = async (context: IContext<IParams>, message: string) => { export const cloundAlarm = async (context: IContext<IParams>, message: string, stack: string) => {
// https://oapi.dingtalk.com/robot/send?access_token=f6d0d8ecdab3ad77dc51b5173f630f1c0e0fcbe90e994d0a642fb0b516dfd24c console.warn(configPackage)
const { title, author } = configPackage
const envTxt = {
'test': '测试环境',
'pre': '预发环境',
'online': '线上环境'
}
// https://oapi.dingtalk.com/robot/send?access_token= f6d0d8ecdab3ad77dc51b5173f630f1c0e0fcbe90e994d0a642fb0b516dfd24c
// 测试 d452c99b12d3fe67472c681e76b13ed5b2355c3e2c3b856a1c3a9897a103986b
const text = { const text = {
"msgtype": "markdown", "msgtype": "markdown",
"markdown": { "markdown": {
"title":"云告警", "title":"云告警",
"text": `### 活动名称:${activityName} \n ### 告警内容 \n ####${message}\n @${phone}` "text": `### 活动名称:${title} \n > #### 环境: ${envTxt[context.env]}\n > #### 告警内容: ${message}\n > #### 详细信息: \n > ${stack}\n\n @${author}`
}, },
"at": { "isAtAll": false, "atMobiles": [phone], "atUserIds": [] } "at": { "isAtAll": false, "atMobiles": [], "atUserIds": [] }
} }
const result = await context.cloud.httpApi.invoke( const result = await context.cloud.httpApi.invoke(
{ {
......
...@@ -14,7 +14,7 @@ export async function doHandler(target: Object, method: IFunction, args: any[]) ...@@ -14,7 +14,7 @@ export async function doHandler(target: Object, method: IFunction, args: any[])
console.log('error', error) console.log('error', error)
recordErrorLog(args[0], args[1], error.toString(), error.stack) recordErrorLog(args[0], args[1], error.toString(), error.stack)
// 云告警 // 云告警
cloundAlarm(args[0], error.toString()) cloundAlarm(args[0], error.toString(), error.stack)
ret = resultsModel.error(CODE_TYPES.SYSTEM_ERROR) ret = resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
......
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