guanghulab/scripts/gdrive/push-token-alerts.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

65 lines
1.9 KiB
JavaScript

/**
* push-token-alerts.js
*
* 天眼系统调用此脚本读取 token-alert.json
* 并将告警信息写入主控台 + 公告板
*
* 输出:
* - grid-db/notifications/token-alert-{timestamp}.md → 主控台通知
* - grid-db/bulletin/token-alert-{timestamp}.md → 公告板通知
*
* 守护: PER-ZY001 铸渊
* 系统: SYS-GLW-0001
* 主控: TCS-0002∞ 冰朔
*/
const fs = require('fs');
const path = require('path');
function pushAlerts() {
const alertPath = path.join(__dirname, '../../grid-db/logs/token-alert.json');
if (!fs.existsSync(alertPath)) {
console.log('✅ 无告警。');
return;
}
const alert = JSON.parse(fs.readFileSync(alertPath, 'utf8'));
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
// 生成主控台通知
const dashboardContent = [
`# ⚠️ Token 续期告警`,
``,
`**时间:** ${alert.time}`,
`**严重级:** ${alert.severity || 'ALERT'}`,
`**影响用户:** ${alert.failed_users.join(', ')}`,
``,
`## 描述`,
alert.message,
``,
`## 需要人类操作`,
...(alert.instructions || []).map((s) => s),
``,
`---`,
`*此告警由 Token 续期引擎自动生成*`
].join('\n');
// 写入主控台
const notifDir = path.join(__dirname, '../../grid-db/notifications');
if (!fs.existsSync(notifDir)) fs.mkdirSync(notifDir, { recursive: true });
fs.writeFileSync(path.join(notifDir, `token-alert-${timestamp}.md`), dashboardContent);
// 写入公告板
const bulletinDir = path.join(__dirname, '../../grid-db/bulletin');
if (!fs.existsSync(bulletinDir)) fs.mkdirSync(bulletinDir, { recursive: true });
fs.writeFileSync(path.join(bulletinDir, `token-alert-${timestamp}.md`), dashboardContent);
// 清除已处理的告警文件
fs.unlinkSync(alertPath);
console.log(`⚠️ 告警已推送到主控台 + 公告板: token-alert-${timestamp}.md`);
}
pushAlerts();