登录失效告警升级: 自动刷新页面抓登录二维码发群(文字+二维码图片+'今日不需要可忽略'说明), 失败降级纯文字

This commit is contained in:
hermes
2026-08-27 03:06:51 +00:00
parent 1580e9dbc8
commit 70ec657b4e
2 changed files with 97 additions and 2 deletions
+29 -2
View File
@@ -47,6 +47,33 @@ function send(target, text) {
} catch (e) { log(`发送失败: ${String(e.message).slice(0, 100)}`); }
}
// 发送图片+文字到群(MEDIA: 语法)
function sendGroupImage(text, imgPath) {
try {
fs.writeFileSync(`/tmp/runner-imgmsg-${ACCT}.txt`, `${text}\nMEDIA:${imgPath}`);
execSync(`${HERMES} send -t "feishu:${GROUP}" -f /tmp/runner-imgmsg-${ACCT}.txt`,
{ stdio: ['pipe', 'pipe', 'pipe'], timeout: 90000 });
log(`已发送图片消息 → 群(数字HR)(附二维码)`);
} catch (e) { log(`图片消息发送失败: ${String(e.message).slice(0, 100)}`); }
}
// 登录失效时:刷新页面抓登录二维码,发群(文字+二维码+补充说明)
function notifyLoginExpired() {
const label = `${ACCT}(${ACCT === 'hr1' ? 'Chrome·合塑账号' : 'Edge·派卡账号'})`;
const text = `🚨 当前${label}账号登录已失效,今日筛选中止。扫码可重新登录:\n如今天不需要协助筛选简历,可忽略该二维码`;
const qrPath = `/tmp/zhaopin-login-qr-${ACCT}.png`;
try {
execSync(`node ${SCRIPTS}/login-qrcode.js ${PORT} ${qrPath}`,
{ cwd: SCRIPTS, timeout: 90000, stdio: ['pipe', 'pipe', 'pipe'] });
if (fs.existsSync(qrPath) && fs.statSync(qrPath).size > 1000) {
sendGroupImage(text, qrPath);
return;
}
log('二维码截图异常(文件过小或不存在),降级为纯文字');
} catch (e) { log(`二维码获取失败: ${String(e.message).slice(0, 100)},降级为纯文字`); }
send(GROUP, `🚨 当前${label}账号登录已失效,今日筛选中止,请在任务机重新登录智联`);
}
function writeState(status, chatLeft) {
fs.writeFileSync(path.join(STATE_DIR, `state-${ACCT}.json`),
JSON.stringify({ date: today(), status, chatLeft: chatLeft ?? null, endedAt: new Date().toISOString() }));
@@ -159,9 +186,9 @@ function statusText(s) {
maybeSendReport('kicked_out', lastChatLeft);
break;
}
// 登录失效 → 群告警,结束
// 登录失效 → 群告警(带登录二维码),结束
if (/登录已失效|passport\.zhaopin\.com/.test(out)) {
send(GROUP, `🚨 ${ACCT}(${ACCT === 'hr1' ? 'Chrome·合塑账号' : 'Edge·派卡账号'})智联登录态已失效,今日筛选中止,请在任务机重新登录智联`);
notifyLoginExpired();
maybeSendReport('login_expired', lastChatLeft);
break;
}