fix: 修复站点监控通知通过webhook发送失败的bug

pull/361/head
xiaojunnuo 2025-03-17 18:20:15 +08:00
parent 729b19c8da
commit 9be1ecc8aa
4 changed files with 12 additions and 13 deletions

View File

@ -122,7 +122,9 @@ export abstract class BaseNotification implements INotification {
return await this.doSend({
userId: 0,
title: "【Certd】测试通知【*.foo.com】标题长度测试、测试、测试",
content: "测试通知,*.foo.com",
content: `测试通知,*.foo.com
`,
pipeline: {
id: 1,
title: "证书申请成功【测试流水线】",

View File

@ -235,9 +235,10 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
show: false
},
column: {
width: 100,
width: 110,
sorter: true,
show: false
show: true,
align: "center"
}
},
certExpiresTime: {

View File

@ -173,9 +173,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
body: {
url,
title: `站点证书检查出错<${site.name}>`,
content: `站点名称: ${site.name} \n
${site.domain} \n
${site.error}`,
content: `站点名称: ${site.name} \n站点域名 ${site.domain} \n错误信息${site.error}`,
},
},
site.userId
@ -188,11 +186,7 @@ export class SiteInfoService extends BaseService<SiteInfoEntity> {
const expires = site.certExpiresTime;
const validDays = dayjs(expires).diff(dayjs(), 'day');
const url = await this.notificationService.getBindUrl('#/monitor/site');
const content = `站点名称: ${site.name} \n
${site.domain} \n
${site.certDomains} \n
${site.certProvider} \n
${dayjs(site.certExpiresTime).format('YYYY-MM-DD')} \n`;
const content = `站点名称: ${site.name} \n站点域名 ${site.domain} \n证书域名 ${site.certDomains} \n证书颁发者 ${site.certProvider} \n过期时间 ${dayjs(site.certExpiresTime).format('YYYY-MM-DD')} \n`;
if (validDays >= 0 && validDays < tipDays) {
// 发通知
await this.notificationService.send(

View File

@ -78,7 +78,7 @@ export class WebhookNotification extends BaseNotification {
col: {
span: 24,
},
helper: `根据实际的webhook接口构建一个json对象作为参数支持变量{title}、{content}、{url},变量用{}包裹,字符串需要双引号\n如果是get方式将作为query参数拼接到url上`,
helper: `根据对应的webhook接口文档构建一个json对象作为参数默认值只是一个示例一般不是正确的参数\n支持变量{title}、{content}、{url},变量用{}包裹\n字符串需要双引号使用\\n换行\n如果是get方式将作为query参数拼接到url上`,
required: true,
})
template = '';
@ -98,8 +98,10 @@ export class WebhookNotification extends BaseNotification {
let bodyStr = target;
const keys = Object.keys(body);
for (const key of keys) {
const value = urlEncode ? encodeURIComponent(body[key]) : body[key];
let value = urlEncode ? encodeURIComponent(body[key]) : body[key];
value = value.replaceAll(`\n`, "\\n");
bodyStr = bodyStr.replaceAll(`{${key}}`, value);
}
return bodyStr;
}