添加配置文件,邮箱和路径从配置文件中读取
This commit is contained in:
parent
8924880162
commit
8627105857
|
@ -160,3 +160,4 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
/report
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -14,6 +14,8 @@ from email.mime.multipart import MIMEMultipart
|
||||||
# 定义公共的部分
|
# 定义公共的部分
|
||||||
path = Path(__file__)
|
path = Path(__file__)
|
||||||
report_dir = path.parent.parent / "report"
|
report_dir = path.parent.parent / "report"
|
||||||
|
config_file_patch = path.parent.parent / "etc/check_config.yml"
|
||||||
|
|
||||||
# 初始化目录
|
# 初始化目录
|
||||||
if not report_dir.exists():
|
if not report_dir.exists():
|
||||||
# shutil.rmtree(data_dir)
|
# shutil.rmtree(data_dir)
|
||||||
|
@ -21,17 +23,22 @@ if not report_dir.exists():
|
||||||
#报告文件
|
#报告文件
|
||||||
week=str(datetime.now().isocalendar()[1])
|
week=str(datetime.now().isocalendar()[1])
|
||||||
file_name_week = "ComputerInfos-week-" + week + ".txt"
|
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_today_path = report_dir/file_name_today
|
||||||
file_week_path = report_dir/file_name_week
|
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():
|
def send_mail():
|
||||||
#发件人
|
#发件人
|
||||||
sender = 'mh@unamail.com'
|
sender = 'mh@unamail.com'
|
||||||
# 接收邮件,可以发给多人
|
# 接收邮件,可以发给多人
|
||||||
receivers = ['mh@unamail.com']
|
receivers = config["receivers"]
|
||||||
# 邮件主体
|
# 邮件主体
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart()
|
||||||
#正文
|
#正文
|
||||||
|
@ -168,7 +175,7 @@ def main():
|
||||||
get_disk_info()
|
get_disk_info()
|
||||||
get_cpu_info()
|
get_cpu_info()
|
||||||
get_memory_info()
|
get_memory_info()
|
||||||
path = "D:\\agent\\ubackup\\uagent\\logs"
|
path = config["agent_dir"]
|
||||||
directory_path = Path(path)
|
directory_path = Path(path)
|
||||||
save_txt(["{0}目录大小:".format(path)])
|
save_txt(["{0}目录大小:".format(path)])
|
||||||
get_dir_size(directory_path)
|
get_dir_size(directory_path)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#邮箱收件人,支持多个
|
#邮箱收件人,支持多个
|
||||||
receivers:
|
receivers:
|
||||||
- "mh@unamail.com"
|
- "mh@unamail.com"
|
||||||
|
- "ypy@unamail.com"
|
||||||
|
|
||||||
#agent安装路径
|
#agent安装路径,windows路径要用双斜线,Linux不需要
|
||||||
agent_dir : "D:\\agent\\ubackup\\uagent\\logs"
|
agent_dir : "D:\\agent\\ubackup\\uagent\\logs"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue