提交修改
This commit is contained in:
parent
99f080a45b
commit
505ea6f365
|
@ -54,6 +54,11 @@ def send_mail():
|
|||
except smtplib.SMTPException:
|
||||
print("Error: 无法发送邮件")
|
||||
|
||||
def run_sql(commdline):
|
||||
result=subprocess.run(commdline,capture_output=True,text=True)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def get_need_tables():
|
||||
# 先查询出所有的tbl_jobhistory表
|
||||
SQL_TABLES="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='unary' AND TABLE_NAME regexp 'tbl_jobhistory(_2)|^tbl_jobhistory$'"
|
||||
|
@ -61,8 +66,8 @@ def get_need_tables():
|
|||
#RESULT_TABLES=`mysql -u$MYSQLUSER -p$MYSQLPWD -e "$SQL_TABLES" 2>/dev/null|awk 'NR>1'`
|
||||
RESULT_TABLES=None
|
||||
commdline = ["mysql", "-uunadba", "-p1223Bc@2008", "-e", SQL_TABLES]
|
||||
result=subprocess.run(commdline,capture_output=True,text=True)
|
||||
tables_list = result.stdout.split('\n')[1:-1]
|
||||
result = run_sql(commdline)
|
||||
tables_list = result.split('\n')[1:-1]
|
||||
return tables_list
|
||||
|
||||
|
||||
|
@ -81,9 +86,28 @@ def get_policy_tasks(id,name):
|
|||
ALLJOBHISTORY_SQL = " UNION ALL ".join(ALLJOBHISTORY)
|
||||
#最终查询的语句
|
||||
check_sql = "select operdesc,sum(n2) as num from ("+ ALLJOBHISTORY_SQL + ") b group by b.operdesc"
|
||||
print(check_sql)
|
||||
commdline = ["mysql", "-uunadba", "unary","-p1223Bc@2008", "-e", check_sql]
|
||||
result=subprocess.run(commdline,capture_output=True,text=True)
|
||||
all_num = "select sum(num) as num1 from (" + check_sql +") t1"
|
||||
# 总个数
|
||||
commdline = ["mysql", "-uunadba", "unary","-p1223Bc@2008", "-e", all_num]
|
||||
result = run_sql(commdline)
|
||||
# 处理异常
|
||||
if result.stdout is None:
|
||||
assert False,'select error'
|
||||
# 失败的
|
||||
failed_num_sql = "select sum(num) as num1 from (" + check_sql +") t1 where t1.operdesc like '%失败%' "
|
||||
failed_commdline = ["mysql", "-uunadba", "unary","-p1223Bc@2008", "-e", failed_num_sql]
|
||||
result_failed = run_sql(failed_commdline)
|
||||
if result_failed.stdout is None:
|
||||
failed_num = 0
|
||||
|
||||
# 成功的
|
||||
success_num_sql = "select sum(num) as num1 from (" + check_sql +") t1 where t1.operdesc like '%成功%' "
|
||||
success_commdline = ["mysql", "-uunadba", "unary","-p1223Bc@2008", "-e", success_num_sql]
|
||||
result_success = run_sql(success_commdline)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return result
|
||||
|
||||
|
@ -119,7 +143,7 @@ def main():
|
|||
# "VMwareCDM":{"agentID":"3D661E09C4F0456B97FBFBA5386C70D8","policyName":["长期"]},
|
||||
# }
|
||||
data={
|
||||
"vmware":{"agentID":"22CDE0BCDE104B0C8596009D236383AA","policyName":["复现2"]},
|
||||
"vmware":{"agentID":"22CDE0BCDE104B0C8596009D236383AA","policyName":["复现"]},
|
||||
"vmware2":{"agentID":"22CDE0BCDE104B0C8596009D236383AA","policyName":["复现2"]},
|
||||
}
|
||||
# 获取所需要查询的表
|
||||
|
|
Loading…
Reference in New Issue