本次提交包含多项功能更新: 1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持 2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储 3. 新增插件分类字段支持,用于场景库分组管理 4. 优化 xq0034/0037/0048 等插件的功能及描述 5. 修复控制面响应兼容问题,支持新旧版本数据格式 6. 新增 xq0033 插件的状态存储模块,用于历史记录管理 7. 优化 CRM 登录窗口模式,支持全屏置顶
46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""测试保留期清理:回填一条 40 天前的运行日志 + 一个 40 天前的设备壳日志后执行 cleanup_expired。"""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, r"D:\work\code\37duAutomation\desktop")
|
|
import pymysql
|
|
|
|
from controlplane.core import config, logstore
|
|
|
|
c = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="123456",
|
|
database="37du_center_test")
|
|
with c.cursor() as cur:
|
|
cur.execute(
|
|
"INSERT INTO run_logs(run_id, account, device_id, plugin_id, name, version, `trigger`, "
|
|
"schedule_id, status, ok, error, summary, started, finished, duration_sec, log_count, "
|
|
"logs, uploaded_at) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,"
|
|
"DATE_SUB(NOW(), INTERVAL 40 DAY))",
|
|
("oldrun0000000000000000000000000001", "olduser", "dev-old-1", "XQ1", "老插件",
|
|
"1.0", "manual", "", "error", 0, "x", "y", 0, 0, 0, 0, "[]"))
|
|
cur.execute(
|
|
"INSERT INTO device_logs(device_id, account, hostname, client_version, size_bytes, "
|
|
"updated_at) VALUES (%s,%s,%s,%s,%s, DATE_SUB(NOW(), INTERVAL 40 DAY))",
|
|
("dev-old-1", "olduser", "OLD-PC", "1.0", 10))
|
|
c.commit()
|
|
c.close()
|
|
|
|
config.SHELL_LOGS_DIR.mkdir(parents=True, exist_ok=True)
|
|
f = os.path.join(config.SHELL_LOGS_DIR, "dev-old-1.log")
|
|
with open(f, "wb") as fh:
|
|
fh.write(b"old content\n")
|
|
|
|
r = logstore.cleanup_expired()
|
|
print("cleanup result:", r)
|
|
print("file exists after cleanup:", os.path.exists(f))
|
|
|
|
c = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="123456",
|
|
database="37du_center_test")
|
|
with c.cursor() as cur:
|
|
cur.execute("SELECT COUNT(*) FROM run_logs WHERE run_id LIKE %s", ("oldrun%",))
|
|
print("old run_logs left:", cur.fetchone()[0])
|
|
cur.execute("SELECT COUNT(*) FROM device_logs WHERE device_id = %s", ("dev-old-1",))
|
|
print("old device_logs left:", cur.fetchone()[0])
|
|
c.close()
|
|
print("CLEANUP OK")
|