添加配置文件,邮箱和路径从配置文件中读取

This commit is contained in:
halliday 2023-11-22 12:06:56 +08:00
parent 8924880162
commit 8627105857
4 changed files with 30 additions and 4 deletions

1
.gitignore vendored
View File

@ -160,3 +160,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
/report

17
.vscode/launch.json vendored Normal file
View File

@ -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
}
]
}

View File

@ -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)

View File

@ -1,7 +1,8 @@
#邮箱收件人,支持多个
receivers:
- "mh@unamail.com"
- "ypy@unamail.com"
#agent安装路径
#agent安装路径,windows路径要用双斜线Linux不需要
agent_dir : "D:\\agent\\ubackup\\uagent\\logs"