Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 2.5.x_dev2
Browse files Browse the repository at this point in the history
  • Loading branch information
Teingi committed Oct 14, 2024
2 parents 779c6b7 + 7244a18 commit f502baf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
13 changes: 9 additions & 4 deletions handler/checker/check_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def export_report_html(self):
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>obdiag Check Report</title>
<title>{{ report_title }}</title>
<style>
body {
padding-top: 60px;
Expand Down Expand Up @@ -290,7 +290,7 @@ def export_report_html(self):
html_template_report_info_table = """
<section>
<table>
<div style="font-weight: bold;font-size: 24px;">obdiag Check Report</div>
<div style="font-weight: bold;font-size: 24px;">{{ report_title }}</div>
<p class="line"></p>
<tr>
<th>Report Time</th>
Expand Down Expand Up @@ -344,16 +344,21 @@ def export_report_html(self):
if len(task.all_fail()) == 0 and len(task.all_critical()) == 0 and len(task.all_warning()) == 0:
report_all_html.append({"task": task.name, "task_report": "all pass"})

report_title_str = "obdiag Check Report"
if self.report_target == "observer":
report_title_str = "obdiag observer Check Report"
elif self.report_target == "obproxy":
report_title_str = "obdiag obproxy Check Report"
fp = open(self.report_path + ".html", 'a+', encoding='utf-8')
template_head = Template(html_template_head)
template_table = Template(html_template_data_table)
fp.write(template_head.render() + "\n")
fp.write(template_head.render(report_title=report_title_str) + "\n")
template_report_info_table = Template(html_template_report_info_table)
cluster_ips = ""
for server in self.context.cluster_config["servers"]:
cluster_ips += server["ip"]
cluster_ips += ";"
fp.write(template_report_info_table.render(report_time=self.report_time, obdiag_version=OBDIAG_VERSION, ob_cluster_ip=cluster_ips, ob_version=self.context.cluster_config["version"]) + "\n")
fp.write(template_report_info_table.render(report_title=report_title_str, report_time=self.report_time, obdiag_version=OBDIAG_VERSION, ob_cluster_ip=cluster_ips, ob_version=self.context.cluster_config["version"]) + "\n")

if len(fail_map_html) != 0:
rendered_fail_map_html = template_table.render(task_name="Fail Tasks Report", tasks=fail_map_html)
Expand Down
4 changes: 3 additions & 1 deletion handler/gather/gather_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, context, gather_pack_dir='./', is_scene=False):
self.zip_encrypt = False
self.is_scene = is_scene
self.config_path = const.DEFAULT_CONFIG_PATH
self.zip_password = None
if self.context.get_variable("gather_timestamp", None):
self.gather_timestamp = self.context.get_variable("gather_timestamp")
else:
Expand Down Expand Up @@ -190,7 +191,7 @@ def handle_from_node(node):
self.stdio.verbose("redact_option is {0}".format(self.redact))
redact_dir = "{0}_redact".format(pack_dir_this_command)
self.redact_dir = redact_dir
redact = Redact(self.context, self.pack_dir_this_command, redact_dir)
redact = Redact(self.context, self.pack_dir_this_command, redact_dir, zip_password=self.zip_password)
redact.redact_files(self.redact)
self.stdio.print("redact success the log save on {0}".format(self.redact_dir))
return ObdiagResult(ObdiagResult.SUCCESS_CODE, data={"store_dir": redact_dir})
Expand Down Expand Up @@ -357,6 +358,7 @@ def __handle_zip_file(self, ssh_client, resp, gather_dir_name, pack_dir_this_com
self.stdio.start_loading('[ip: {0}] zip observer log start'.format(ssh_client.get_name()))
if self.zip_encrypt:
zip_password = Util.gen_password(16)
self.zip_password = zip_password
zip_encrypt_dir(ssh_client, zip_password, self.gather_ob_log_temporary_dir, gather_dir_name, self.stdio)
else:
zip_dir(ssh_client, self.gather_ob_log_temporary_dir, gather_dir_name, self.stdio)
Expand Down
19 changes: 17 additions & 2 deletions handler/gather/plugins/redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@


class Redact:
def __init__(self, context, input_file_dir, output_file_dir):
def __init__(self, context, input_file_dir, output_file_dir, zip_password=None):
self.context = context
self.stdio = context.stdio
self.redacts = {}
self.input_file_dir = input_file_dir
self.output_file_dir = output_file_dir
self.zip_password = zip_password
self.module_dir = os.path.expanduser('~/.obdiag/gather/redact')
self.inner_config = self.context.inner_config

Expand Down Expand Up @@ -55,14 +56,20 @@ def redact_files(self, input_redacts):
self.stdio.verbose("open zip file: {0}".format(os.path.join(self.input_file_dir, zip_file)))
with zipfile.ZipFile(os.path.join(self.input_file_dir, zip_file), 'r') as zip_ref:
# Extract all files to the current directory
zip_ref.extractall(self.input_file_dir)
if self.zip_password is not None:
zip_ref.extractall(self.input_file_dir, pwd=self.zip_password.encode('utf-8'))
else:
zip_ref.extractall(self.input_file_dir)
gather_log_files = []
for file_name in os.listdir(self.input_file_dir):
if "zip" not in file_name and "result_summary.txt" not in file_name:
log_dir = os.path.join(self.input_file_dir, file_name)
for log_file in os.listdir(log_dir):
gather_log_files.append(os.path.join(log_dir, log_file))
self.stdio.verbose("result_log_files add {0}".format(os.path.join(log_dir, log_file)))
if len(gather_log_files) == 0:
self.stdio.warn("No log file found. The redact process will be skipped.")
return False
file_queue = []
max_processes = int(self.inner_config.get('gather').get('redact_processing_num')) or 3
self.stdio.verbose("max_processes: {0}".format(max_processes))
Expand All @@ -78,16 +85,24 @@ def redact_files(self, input_redacts):
file_queue.append(file_thread)
for file_thread in file_queue:
file_thread.join()
# delete gather_log_files
self.stdio.verbose("redact end. delete all gather_log_files")
for file_name in gather_log_files:
self.stdio.verbose("delete file: {0}".format(file_name))
os.remove(file_name)
# zip the dir by node
subfolders = [f for f in os.listdir(self.output_file_dir) if os.path.isdir(os.path.join(self.output_file_dir, f))]
for subfolder in subfolders:
subfolder_path = os.path.join(self.output_file_dir, subfolder)
zip_filename = os.path.join(self.output_file_dir, f"{subfolder}.zip")
if self.zip_password is not None:
self.stdio.warn("the redacted log without passwd")
with zipfile.ZipFile(zip_filename, 'w') as zipf:
for root, dirs, files in os.walk(subfolder_path):
for file in files:
file_path = os.path.join(root, file)
zipf.write(file_path, os.path.relpath(file_path, subfolder_path))
self.stdio.verbose("zip the redact log with passwd: {0}".format(self.zip_password.encode('utf-8')))
self.stdio.verbose("delete the dir: {0}".format(subfolder_path))
shutil.rmtree(subfolder_path)
self.stdio.print(f"{subfolder} is zipped on {zip_filename}")
Expand Down

0 comments on commit f502baf

Please sign in to comment.