diff --git a/report/report.py b/report/report.py index cfdc14d..2f139f5 100644 --- a/report/report.py +++ b/report/report.py @@ -3,10 +3,12 @@ """ # from os import write import csv +import os INVENTORY_FILE = "/tmp/inventory_report.csv" SWATCH_FILE = "/tmp/swatch_report.csv" MATCH_FILE = "/tmp/match_inv_sw.csv" +ISSUE_SUMMARY = "/tmp/issue_summary.log" def check_for_installed_products(entries): @@ -1022,3 +1024,100 @@ def csv_match_report(match_obj): writer.writerows(report_list) print("File {} created".format(MATCH_FILE)) + + +def txt_issue_report(wrong_socket_inventory, + wrong_socket_subscription, + duplicate_fqdn, + duplicate_display_name, + different_fqdn_display_name, + server_with_no_socket_key, + installed_product_with_no_package_sat, + installed_product_with_no_package_cap, + installed_product_with_no_package_ocp): + """ + Responsible to reveive the analysis and generate the issue_summary file. + """ + + with open(ISSUE_SUMMARY, "w") as file_obj: + + file_obj.write("## Wrong Sockets in Inventory\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,sockets\n") + for elements in wrong_socket_inventory: + id = elements[0]['server']['id'] + fqdn = elements[0]['server']['fqdn'] + sockets = elements[0]['system_profile']['number_of_sockets'] + pass + file_obj.write("{},{},{}\n".format(id, fqdn, sockets)) + file_obj.write("---\n") + + file_obj.write("\n") + + file_obj.write("## Wrong Sockets in Subscriptions\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,sockets\n") + for elements in wrong_socket_subscription: + id = elements[1]['inventory_id'] + fqdn = elements[1]['display_name'] + sockets = elements[1]['sockets'] + pass + file_obj.write("{},{},{}\n".format(id, fqdn, sockets)) + file_obj.write("---\n") + + file_obj.write("\n") + + file_obj.write("## Duplicate FQDN\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,display_name,created,updated\n") + for elements in duplicate_fqdn: + file_obj.write("{},{},{},{},{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + file_obj.write("---\n") + + file_obj.write("\n") + + file_obj.write("## Duplicate Display Name\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,display_name,created,updated\n") + for elements in duplicate_display_name: + file_obj.write("{},{},{},{},{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + file_obj.write("---\n") + + file_obj.write("\n") + + file_obj.write("## Different FQDN and Display Name\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,display_name,created,updated\n") + for elements in different_fqdn_display_name: + file_obj.write("{},{},{},{},{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + file_obj.write("---\n") + + + file_obj.write("\n") + + file_obj.write("## Server with no socket_key\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,display_name,created,updated\n") + for elements in server_with_no_socket_key: + file_obj.write("{},{},{},{},{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + file_obj.write("---\n") + + file_obj.write("\n") + + file_obj.write("## Installed Product with no Installed Package (Satellite, Capsule and OpenShift)\n") + file_obj.write("---\n") + file_obj.write("id,fqdn,display_name,installed_product,is_package_installed\n") + for elements in installed_product_with_no_package_sat: + file_obj.write("{},{},{},\"{}\",{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + for elements in installed_product_with_no_package_cap: + file_obj.write("{},{},{},\"{}\",{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + for elements in installed_product_with_no_package_ocp: + file_obj.write("{},{},{},\"{}\",{}\n".format(elements[0], elements[1], elements[2], elements[3], elements[4])) + + file_obj.write("---\n") + + + if os.path.isfile(ISSUE_SUMMARY): + print("File {} created".format(ISSUE_SUMMARY)) + else: + print("File {} was not created".format(ISSUE_SUMMARY)) \ No newline at end of file diff --git a/troubleshoot/ts.py b/troubleshoot/ts.py index c89a5e5..4ee7190 100644 --- a/troubleshoot/ts.py +++ b/troubleshoot/ts.py @@ -2,6 +2,7 @@ Module responsible for troublheshooting """ +import csv import json import os from execution import execution @@ -97,6 +98,7 @@ def match_hbi_sw(): stage_lst = [] report.csv_match_report(final_lst) + issue_summary_report(final_lst) def clean(): @@ -115,3 +117,163 @@ def clean(): if os.path.exists(MATCH_FILE): print("removing the file {}".format(MATCH_FILE)) os.remove(MATCH_FILE) + + +def organize_list_by_column(list_obj, col): + """ + Responsible for organize the list according to the column. + """ + return sorted(list_obj, key=lambda x: x[col]) + + +def issue_summary_report(final_lst): + """ + Function to check everything that is wrong or not expected in + Inventory and Subscriptions. + """ + + wrong_socket_inventory = [] + wrong_socket_subscription = [] + duplicate_fqdn = [] + duplicate_display_name = [] + different_fqdn_display_name = [] + server_with_no_socket_key = [] + installed_product_with_no_package_sat = [] + installed_product_with_no_package_cap = [] + installed_product_with_no_package_ocp = [] + + for obj in final_lst: + # Checking for 0 sockets in Inventory + stage_lst = [] + try: + if obj[0]['system_profile']['number_of_sockets'] == 0: + wrong_socket_inventory.append(obj) + except KeyError: + # print("Machine {} sem socket key".format(obj[0]['server']['fqdn'])) + stage_lst.append(obj[0]['server']['id']) + stage_lst.append(obj[0]['server']['fqdn']) + stage_lst.append(obj[0]['server']['display_name']) + stage_lst.append(obj[0]['server']['created']) + stage_lst.append(obj[0]['server']['updated']) + + server_with_no_socket_key.append(stage_lst) + # Checking for 0 sockets in Subscription + try: + if obj[1]['sockets'] == 0: + wrong_socket_subscription.append(obj) + except TypeError as e: + # print(e) + ... + + # Checking for duplicate FQDN + fqdn = obj[0]['server']['fqdn'] + count = 0 + stage_lst = [] + for item in final_lst: + if item[0]['server']['fqdn'] == fqdn: + stage_lst.append(obj[0]['server']['id']) + if obj[0]['server']['fqdn'] is None: + stage_lst.append("None") + else: + stage_lst.append(obj[0]['server']['fqdn']) + stage_lst.append(obj[0]['server']['display_name']) + stage_lst.append(obj[0]['server']['created']) + stage_lst.append(obj[0]['server']['updated']) + count = count + 1 + + if count > 1: + duplicate_fqdn.append(stage_lst) + + + # Checking for duplicate display_name + display_name = obj[0]['server']['display_name'] + count = 0 + stage_lst = [] + for item in final_lst: + if item[0]['server']['display_name'] == display_name: + stage_lst.append(obj[0]['server']['id']) + stage_lst.append(obj[0]['server']['fqdn']) + if obj[0]['server']['display_name'] is None: + stage_lst.append("None") + else: + stage_lst.append(obj[0]['server']['display_name']) + stage_lst.append(obj[0]['server']['created']) + stage_lst.append(obj[0]['server']['updated']) + count = count + 1 + + if count > 1: + duplicate_display_name.append(stage_lst) + + + + # Checking for same server with different display_name and FQDN + stage_lst = [] + + fqdn = obj[0]['server']['fqdn'] + display_name = obj[0]['server']['display_name'] + if fqdn != display_name: + stage_lst.append(obj[0]['server']['id']) + stage_lst.append(fqdn) + stage_lst.append(display_name) + stage_lst.append(obj[0]['server']['created']) + stage_lst.append(obj[0]['server']['updated']) + + + different_fqdn_display_name.append(stage_lst) + + + # Checking if the 250, 269 or 209 pem file is present + stage_lst = [] + + # Checking for the installed_products + installed_products_response = report.check_for_installed_products(obj[0]) + + # Checking for satellite packages + installed_package_satellite_response = report.check_for_satellite_package(obj[0]) + + # Checking for openshift packages + installed_package_openshift_response = report.check_for_openshift_package(obj[0]) + + if "250" in installed_products_response and installed_package_satellite_response != "TRUE": + stage_lst.append(obj[0]['server']['id']) + stage_lst.append(obj[0]['server']['fqdn']) + stage_lst.append(obj[0]['server']['display_name']) + stage_lst.append(installed_products_response) + stage_lst.append(installed_package_satellite_response) + + installed_product_with_no_package_sat.append(stage_lst) + + if "269" in installed_products_response and installed_package_satellite_response != "TRUE": + stage_lst.append(obj[0]['server']['id']) + stage_lst.append(obj[0]['server']['fqdn']) + stage_lst.append(obj[0]['server']['display_name']) + stage_lst.append(installed_products_response) + stage_lst.append(installed_package_satellite_response) + + installed_product_with_no_package_cap.append(stage_lst) + + if ("290" in installed_products_response) and (installed_package_openshift_response != "TRUE"): + stage_lst.append(obj[0]['server']['id']) + stage_lst.append(obj[0]['server']['fqdn']) + stage_lst.append(obj[0]['server']['display_name']) + stage_lst.append(installed_products_response) + stage_lst.append(installed_package_openshift_response) + + installed_product_with_no_package_ocp.append(stage_lst) + + + # Passing the list and also the column that will be used to order (column #1 is the FQDN one) + organized_duplicate_fqdn = organize_list_by_column(duplicate_fqdn, 1) + + # Passing the list and also the column that will be used to order (column #2 is the Display Name one) + organized_duplicate_display_name = organize_list_by_column(duplicate_display_name, 2) + + report.txt_issue_report(wrong_socket_inventory, + wrong_socket_subscription, + organized_duplicate_fqdn, + organized_duplicate_display_name, + different_fqdn_display_name, + server_with_no_socket_key, + installed_product_with_no_package_sat, + installed_product_with_no_package_cap, + installed_product_with_no_package_ocp)