Authored by zhangwenxue

feature(alipay): add alipay dingding alert

const alipayRepository = require('./alipay.repository');
const { logger } = global.yoho;
const AlertAgent = require('../../utils/alert-manager');
const AlertType = {
MySQL: 0,
Knex: 1,
};
const alipayAlert = new AlertAgent('alipay', {
[AlertType.MySQL]: 'mysql error',
[AlertAgent.Knex]: 'knex insert error'
}, ['1735697170', '15210602915']);
async function create({ uid, alipayAccount, alipayName }) {
try {
... ... @@ -8,6 +18,7 @@ async function create({ uid, alipayAccount, alipayName }) {
});
if (!result) {
alipayAlert.send(AlertType.Knex);
return {
error: {
code: 500,
... ... @@ -31,7 +42,7 @@ async function create({ uid, alipayAccount, alipayName }) {
};
} else {
logger.error('mysql error =>', e);
alipayAlert.send(AlertType.MySQL, e.message);
return {
error: {
code: 500,
... ...
... ... @@ -17,11 +17,13 @@ const AlertManager = {
const now = Date.now();
let ats = [];
let text = [];
text.push(`**本次告警**: ${moment(now).format('YYYY-MM-DD HH:mm:ss')}\n`);
text.push(`**上次告警**: ${moment(this.lastSendTime).format('YYYY-MM-DD HH:mm:ss')}\n`);
text = text.concat(Object.keys(this.pendingAgents).map(agentName => {
const agent = this.pendingAgents[agentName];
ats = ats.concat(agent.ats);
return agent.getMarkdownReport();
}));
... ... @@ -46,6 +48,7 @@ class AlertAgent {
send(subjectId, text = '') {
let msg = _.get(this.msgs, subjectId, {text, count: 0});
this.msgs[subjectId] = msg;
msg.count++;
AlertManager.post(this);
... ... @@ -53,6 +56,7 @@ class AlertAgent {
getMarkdownReport() {
let report = [`## ${this.name} `];
report.push(this.ats.map(at => `@${at}`).join(' '));
const msgs = Object.keys(this.msgs).map(id => {
... ...