From 4a0c17e1c0f16d69045a1d7b420d3712a94a601f Mon Sep 17 00:00:00 2001 From: Brian Read Date: Tue, 4 Jun 2024 10:12:01 +0100 Subject: [PATCH] Move html and template files to /opt/mailstats --- .../opt/mailstats/html/mailstats.css | 0 root/opt/mailstats/logs/.gitignore | 0 .../templates/mailstats-sub-table.html.pt | 0 .../opt/mailstats/templates/mailstats.html.pt | 0 root/usr/bin/mailstats.py | 16 ++++++++++------ 5 files changed, 10 insertions(+), 6 deletions(-) rename mailstats.css => root/opt/mailstats/html/mailstats.css (100%) create mode 100644 root/opt/mailstats/logs/.gitignore rename mailstats-sub-table.html.pt => root/opt/mailstats/templates/mailstats-sub-table.html.pt (100%) rename mailstats.html.pt => root/opt/mailstats/templates/mailstats.html.pt (100%) diff --git a/mailstats.css b/root/opt/mailstats/html/mailstats.css similarity index 100% rename from mailstats.css rename to root/opt/mailstats/html/mailstats.css diff --git a/root/opt/mailstats/logs/.gitignore b/root/opt/mailstats/logs/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/mailstats-sub-table.html.pt b/root/opt/mailstats/templates/mailstats-sub-table.html.pt similarity index 100% rename from mailstats-sub-table.html.pt rename to root/opt/mailstats/templates/mailstats-sub-table.html.pt diff --git a/mailstats.html.pt b/root/opt/mailstats/templates/mailstats.html.pt similarity index 100% rename from mailstats.html.pt rename to root/opt/mailstats/templates/mailstats.html.pt diff --git a/root/usr/bin/mailstats.py b/root/usr/bin/mailstats.py index e6b5902..88ca01a 100644 --- a/root/usr/bin/mailstats.py +++ b/root/usr/bin/mailstats.py @@ -28,10 +28,14 @@ from collections import defaultdict Mailstats_version = '1.2' script_dir = os.path.dirname(os.path.abspath(__file__)) -data_file_path = script_dir+'/../../../' +data_file_path = script_dir+'/../..' #back to the top now = datetime.now() yesterday = now - timedelta(days=1) formatted_yesterday = yesterday.strftime("%Y-%m-%d") +#html_page_path = data_file_path+"/home/e-smith/files/ibays/mesdb/html/mailstats/" +html_page_dir = data_file_path+"/opt/mailstats/html/" +template_dir = data_file_path+"/opt/mailstats/templates/" +logs_dir = data_file_path+"/opt/mailstats/logs/" # Column numbering Hour = 0 @@ -360,7 +364,7 @@ def split_timestamp_and_data(log_entry: str) -> list: def render_sub_table(table_title,table_headers,found_values): # NeedNOTE: also need to compute the percentages here. - template_path = data_file_path+'mailstats-sub-table.html.pt' + template_path = template_dir+'mailstats-sub-table.html.pt' # Load the template with open(template_path, 'r') as template_file: template_content = template_file.read() @@ -409,8 +413,8 @@ if __name__ == "__main__": num_hours = 25 # Represents hours from 0 to 23 - adds extra one for column totals and another for percentages - data_file = data_file_path+'current.log' - log_entries,skip_count = read_in_yesterday_log_file(data_file) + log_file = logs_dir+'current.log' + log_entries,skip_count = read_in_yesterday_log_file(log_file) if len(log_entries) == 0: print(f"No records found in {data_file}") quit() @@ -613,7 +617,7 @@ if __name__ == "__main__": print(f"J:{j} I:{i}") #Now apply the results to the chameleon template - main table # Path to the template file - template_path = data_file_path+'mailstats.html.pt' + template_path = template_dir+'mailstats.html.pt' # Load the template with open(template_path, 'r') as template_file: template_content = template_file.read() @@ -660,7 +664,7 @@ if __name__ == "__main__": total_html = insert_string_after(total_html,Nav_str, "") # Write the rendered HTML to a file - output_path = data_file_path+'mailstats_for_'+formatted_yesterday + output_path = html_page_dir+'mailstats_for_'+formatted_yesterday output_path = output_path.replace(' ','_') with open(output_path+'.html', 'w') as output_file: output_file.write(total_html)