fix: address code review — improve alert matching logic, fix email indentation
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
parent
19e35fac73
commit
ebbca679e4
|
|
@ -5,7 +5,7 @@ name: "🔍 Server Patrol · 服务器每日巡检"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0,12 * * *' # UTC 00:00+12:00 = 北京 08:00+20:00
|
- cron: '0 0,12 * * *' # UTC 00:00 and 12:00 = 北京 08:00 and 20:00
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
workflow_run:
|
workflow_run:
|
||||||
workflows: ["🏠 Sandbox Deploy"]
|
workflows: ["🏠 Sandbox Deploy"]
|
||||||
|
|
@ -92,19 +92,17 @@ jobs:
|
||||||
alerts = '\n'.join(f' ❌ {a}' for a in report['alerts'])
|
alerts = '\n'.join(f' ❌ {a}' for a in report['alerts'])
|
||||||
fixed = '\n'.join(f' ✅ {f}' for f in report['auto_fixed'])
|
fixed = '\n'.join(f' ✅ {f}' for f in report['auto_fixed'])
|
||||||
|
|
||||||
body = f"""🔍 铸渊服务器巡检报告
|
body = (
|
||||||
时间: {report['timestamp']}
|
f"🔍 铸渊服务器巡检报告\n"
|
||||||
|
f"时间: {report['timestamp']}\n\n"
|
||||||
⚠️ 发现 {report['alert_count']} 个异常:
|
f"⚠️ 发现 {report['alert_count']} 个异常:\n"
|
||||||
{alerts}
|
f"{alerts}\n\n"
|
||||||
|
f"🔧 自动修复 {report['fixed_count']} 个:\n"
|
||||||
🔧 自动修复 {report['fixed_count']} 个:
|
f"{fixed if fixed else ' (无)'}\n\n"
|
||||||
{fixed if fixed else ' (无)'}
|
f"磁盘使用率: {report['disk_usage_percent']}%\n"
|
||||||
|
f"Nginx状态: {report['nginx_status']}\n\n"
|
||||||
磁盘使用率: {report['disk_usage_percent']}%
|
f"—— 铸渊 · 光湖代码守护人格体"
|
||||||
Nginx状态: {report['nginx_status']}
|
)
|
||||||
|
|
||||||
—— 铸渊 · 光湖代码守护人格体"""
|
|
||||||
|
|
||||||
smtp_user = os.environ['SMTP_USER']
|
smtp_user = os.environ['SMTP_USER']
|
||||||
smtp_pass = os.environ['SMTP_PASS']
|
smtp_pass = os.environ['SMTP_PASS']
|
||||||
|
|
|
||||||
|
|
@ -120,10 +120,13 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 找出未能自动修复的异常 → 开工单
|
// 找出未能自动修复的异常 → 开工单
|
||||||
const autoFixedSet = new Set(report.auto_fixed || []);
|
const autoFixed = report.auto_fixed || [];
|
||||||
const unresolvedAlerts = (report.alerts || []).filter(alert => {
|
const unresolvedAlerts = (report.alerts || []).filter(alert => {
|
||||||
// 如果 alert 对应有一条 auto_fixed,说明已修复,不开工单
|
// 检查是否有对应的自动修复记录(修复消息中包含完整的异常描述关键词)
|
||||||
return !report.auto_fixed.some(fix => fix.includes(alert.split(' ')[0]));
|
return !autoFixed.some(fix => {
|
||||||
|
const alertKey = alert.replace(/[::].*/g, '').trim();
|
||||||
|
return fix.includes(alertKey);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (unresolvedAlerts.length === 0) {
|
if (unresolvedAlerts.length === 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue