Commit 64c2ad1e by 李嘉林

feat: 加钉钉监控

parent 74f5d78a
......@@ -6,7 +6,7 @@ import spokesman from "@/api/spokesman";
import { themeColor, checkShowConditionIds, getStoreInfo, setStoreInfo } from "@/utils/mayi";
import { query_isEntry } from "@/utils/mayi_fenxiao";
import { sendMsg } from "@/utils/dingdingLogMonitoring";
export default {
data() {
return {
......@@ -351,6 +351,29 @@ export default {
},
onError(data) {
console.log(data, "js异常捕获");
// 钉钉监控
let userId = wx.getStorageSync("loginUserInfo") ? wx.getStorageSync("loginUserInfo").userId : '-';
let sendMsgQuery = {
type: 'bug',
mixid: this.$store.state.mixid,
errorType: 'MINI',
errorText: data,
monitorParams: {
userId,
uid: wx.getStorageSync("_ma_uid"),
},
}
try {
const res = wx.getSystemInfoSync();
sendMsgQuery.monitorParams.brand = res.brand;
sendMsgQuery.monitorParams.SDKVersion = res.SDKVersion;
sendMsgQuery.monitorParams.platform = res.platform;
sendMsgQuery.monitorParams.system = res.system;
sendMsgQuery.monitorParams.version = res.version;
} catch (e) {
console.error('获取系统信息失败', e);
}
sendMsg(sendMsgQuery);
this.$mpAnalytics.recordError({
data,
keyword: data,
......
/*
* 钉钉群消息推送机器人
* 文档
* https://open.dingtalk.com/document/orgapp/robot-message-type-staff-information-in-an-enterprise?spm=a2c6h.13066369.question.8.30c543fblTKVaW
*/
// 基础参数
const AT_USER = {
"l": "15838347133"
};
// 获取辅助参数
function getMonitorParams(obj) {
console.log('getMonitorParams-obj->', obj);
let t = "";
if (obj && Object.keys(obj).length > 0) {
Object.keys(obj).forEach(item => {
t += `- **${item}**: \`${obj[item]}\`\n`
})
}
return t || `- **暂无**`;
}
/**
* 获取模板
* @param {*} param0
* @returns
*/
function md_template({ type = 'bug', mixid = '', errorText = '', errorType = '', monitorParams = {} }) {
let bugT = ['### ⚠️ **异常报警通知** ⚠️',
'#### **系统概览**',
`- **MIX_ID**: \`${mixid}\``,
`- **环境**: \`${process.env.NODE_ENV}\``,
`- **错误类型**: \`${errorType}\``,
`- **抛出时间**: \`${new Date().toLocaleString()}\``,
'#### **错误描述**',
'\n',
`>${errorText ? errorText : '-'}\n`,
'#### **辅助参数**',
`${getMonitorParams(monitorParams)}`,
'\n',
'#### **查看日志**',
`>[kibana](https://kibana.mayi888.com/app/kibana#/discover/9134c350-f707-11ee-8573-31e83e1bb75d?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now%2Fd,to:now%2Fd))&_a=(columns:!(log_message,log_host),filters:!(),index:'9c11dbd0-f704-11ee-8573-31e83e1bb75d',interval:auto,query:(language:lucene,query:''),sort:!()))\n`,
`>[报表](https://bi.mayi888.com/)\n`,
'\n',
`@${[AT_USER["l"]]}`
]
let temp = {
bug: bugT.join("\n"),
warning: `### warning`,
}
return temp[type]
}
/**
* 初始化
* @param {*} data
* @returns
*/
function initParams(data) {
// 钉钉请求参数
let SEND_MSG_QUERY = {
at: {
atMobiles: [AT_USER["l"]],
// atUserId: [],
// isAtAll: false,
},
msgtype: "markdown", // text、markdown、actionCard
markdown: {
title: "异常报警",
text: md_template({ ...data }),
},
}
return SEND_MSG_QUERY
}
/**
* 发送消息
* @param {*} data
* type = 'bug', mixid = '', errorText = '', errorType = '', monitorParams = {}
*/
export function sendMsg(data) {
console.log('initParams->', initParams(data));
wx.request({
url: "https://oapi.dingtalk.com/robot/send?access_token=1a29dd59d14953a831989e9ba19ad16dd5f06fcbed3256b3832752aee69b4d00",
method: "POST",
data: initParams(data),
header: {
"Content-Type": "application/json"
},
success: function(res) {
console.log("发送成功", res);
},
fail: function(res) {
console.log("发送失败", res);
}
})
}
\ No newline at end of file
......@@ -8,7 +8,6 @@ module.exports = {
log.debug.apply(log, arguments)
},
info() {
console.log('日志log级别');
if (!log) return
log.info.apply(log, arguments)
},
......
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