From 862710585731959f50da2c4206bd3a8ca7d07a7a Mon Sep 17 00:00:00 2001 From: halliday Date: Wed, 22 Nov 2023 12:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E9=82=AE=E7=AE=B1=E5=92=8C=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=BB=8E=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E8=AF=BB?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .vscode/launch.json | 17 +++++++++++++++++ bin/get_system_info.py | 13 ++++++++++--- etc/check_config.yml | 3 ++- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index 5d381cc..7811181 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +/report diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..021893f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: 当前文件", + "type": "python", + "request": "launch", + "program": "${file}", + "args": ["--send-mail=true"], + "console": "integratedTerminal", + "justMyCode": true + } + ] +} \ No newline at end of file diff --git a/bin/get_system_info.py b/bin/get_system_info.py index 31f72b2..21e98cb 100644 --- a/bin/get_system_info.py +++ b/bin/get_system_info.py @@ -14,6 +14,8 @@ from email.mime.multipart import MIMEMultipart # 定义公共的部分 path = Path(__file__) report_dir = path.parent.parent / "report" +config_file_patch = path.parent.parent / "etc/check_config.yml" + # 初始化目录 if not report_dir.exists(): # shutil.rmtree(data_dir) @@ -21,17 +23,22 @@ if not report_dir.exists(): #报告文件 week=str(datetime.now().isocalendar()[1]) file_name_week = "ComputerInfos-week-" + week + ".txt" -file_name_today="ComputerInfos-today-.txt" +file_name_today="ComputerInfos-today.txt" file_today_path = report_dir/file_name_today file_week_path = report_dir/file_name_week +#获取配置文件 +with open(config_file_patch,"r",encoding='utf-8') as fy: + config = yaml.safe_load(fy) +#print(config) + #发邮件 def send_mail(): #发件人 sender = 'mh@unamail.com' # 接收邮件,可以发给多人 - receivers = ['mh@unamail.com'] + receivers = config["receivers"] # 邮件主体 msg = MIMEMultipart() #正文 @@ -168,7 +175,7 @@ def main(): get_disk_info() get_cpu_info() get_memory_info() - path = "D:\\agent\\ubackup\\uagent\\logs" + path = config["agent_dir"] directory_path = Path(path) save_txt(["{0}目录大小:".format(path)]) get_dir_size(directory_path) diff --git a/etc/check_config.yml b/etc/check_config.yml index dd2f867..8999b19 100644 --- a/etc/check_config.yml +++ b/etc/check_config.yml @@ -1,7 +1,8 @@ #邮箱收件人,支持多个 receivers: - "mh@unamail.com" + - "ypy@unamail.com" -#agent安装路径 +#agent安装路径,windows路径要用双斜线,Linux不需要 agent_dir : "D:\\agent\\ubackup\\uagent\\logs"