From 580d1de9158607431741cca90301396ea654027e Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 18 Sep 2018 21:48:15 -0600 Subject: [PATCH] Finished Prime95 osTicket reply section * NOTE: A reply is not posted for Aborted tests or Unknown results --- .bin/Scripts/functions/hw_diags.py | 76 ++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index e9e8109a..627ffa6d 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -141,6 +141,9 @@ def get_graph_step(rate, scale=16): def get_osticket_number(): """Get ticket number and confirm with name from osTicket DB.""" ticket_number = None + if not ost_db['Cursor']: + # No DB access, just set it to 0 + return 0 while ticket_number is None: print_standard(' ') _input = input('Enter ticket number: ') @@ -242,6 +245,12 @@ def menu_diags(*args): spacer = '──────────────────────────') if selection.isnumeric(): if diag_modes[int(selection)-1]['Name'] != 'Quick drive test': + clear_screen() + print_standard(' ') + try_and_print( + message='Connecting to osTicket database...', + function=connect_to_db, + width=40) # Save log for non-quick tests ticket_number = get_osticket_number() global_vars['LogDir'] = '{}/Logs/{}_{}'.format( @@ -251,7 +260,7 @@ def menu_diags(*args): os.makedirs(global_vars['LogDir'], exist_ok=True) global_vars['LogFile'] = '{}/Hardware Diagnostics.log'.format( global_vars['LogDir']) - run_tests(diag_modes[int(selection)-1]['Tests']) + run_tests(diag_modes[int(selection)-1]['Tests'], ticket_number) elif selection == 'A': run_program(['hw-diags-audio'], check=False, pipe=False) pause('Press Enter to return to main menu... ') @@ -315,7 +324,7 @@ def osticket_needs_attention(ticket_id): except: ost_db['Errors'] = True -def osticket_reply(ticket_id, response): +def osticket_post_reply(ticket_id, response): """Post a reply to a ticket in osTicket.""" if not ticket_id: raise GenericError @@ -359,7 +368,7 @@ def osticket_set_drive_result(ticket_id, passed): except: ost_db['Errors'] = True -def run_badblocks(): +def run_badblocks(ticket_number): """Run a read-only test for all detected disks.""" aborted = False clear_screen() @@ -421,7 +430,7 @@ def run_badblocks(): run_program('tmux kill-pane -a'.split(), check=False) pass -def run_iobenchmark(): +def run_iobenchmark(ticket_number): """Run a read-only test for all detected disks.""" aborted = False clear_screen() @@ -578,7 +587,7 @@ def run_iobenchmark(): run_program('tmux kill-pane -a'.split(), check=False) pass -def run_mprime(): +def run_mprime(ticket_number): """Run Prime95 for MPRIME_LIMIT minutes while showing the temps.""" aborted = False print_log('\nStart Prime95 test') @@ -598,10 +607,10 @@ def run_mprime(): try: for i in range(int(MPRIME_LIMIT)): clear_screen() - min_left = int(MPRIME_LIMIT)-i) + min_left = int(MPRIME_LIMIT) - i print_standard('Running Prime95 ({} minute{} left)'.format( min_left, - 's' if min_left != 1 else '') + 's' if min_left != 1 else '')) print_warning('If running too hot, press CTRL+c to abort the test') sleep(60) except KeyboardInterrupt: @@ -671,10 +680,45 @@ def run_mprime(): TESTS['Prime95']['Status'] = 'Unknown' update_progress() + # Build osTicket report + if TESTS['Prime95']['Status'] not in ['Unknown', 'Aborted']: + report = ['System {} Prime95 testing.'.format( + 'FAILED' if TESTS['Prime95']['NS'] else 'passed')] + report.append('') + report.append('Prime95 log:') + log_path = '{}/prime.log'.format(global_vars['LogDir']) + try: + with open(log_path, 'r') as f: + for line in f.readlines(): + line = line.strip() + r = re.search('(completed \d+ tests.*)', line, re.IGNORECASE) + if r: + report.append(r.group(1)) + except: + report.append(' ERROR: Failed to read log.') + report.append('') + report.append('Final temps:') + log_path = '{}/Final Temps.log'.format(global_vars['LogDir']) + try: + with open(log_path, 'r') as f: + for line in f.readlines(): + line = line.strip() + if not line: + # Stop after CPU temp(s) + break + report.append(line) + except: + report.append(' ERROR: Failed to read log.') + + # Upload osTicket report + osticket_post_reply( + ticket_id=ticket_number, + response='\n'.join(report)) + # Done run_program('tmux kill-pane -a'.split()) -def run_nvme_smart(): +def run_nvme_smart(ticket_number): """Run the built-in NVMe or SMART test for all detected disks.""" aborted = False clear_screen() @@ -769,7 +813,7 @@ def run_nvme_smart(): # Done run_program('tmux kill-pane -a'.split(), check=False) -def run_tests(tests): +def run_tests(tests, ticket_number=None): """Run selected hardware test(s).""" clear_screen() print_standard('Starting Hardware Diagnostics') @@ -781,12 +825,6 @@ def run_tests(tests): TESTS['NVMe/SMART']['Quick'] = 'Quick' in tests # Initialize - if not TESTS['NVMe/SMART']['Quick']: - print_standard(' ') - try_and_print( - message='Connecting to osTicket database...', - function=connect_to_db, - width=40) if TESTS['NVMe/SMART']['Enabled'] or TESTS['badblocks']['Enabled'] or TESTS['iobenchmark']['Enabled']: print_standard(' ') scan_disks() @@ -796,16 +834,16 @@ def run_tests(tests): mprime_aborted = False if TESTS['Prime95']['Enabled']: try: - run_mprime() + run_mprime(ticket_number) except GenericError: mprime_aborted = True if not mprime_aborted: if TESTS['NVMe/SMART']['Enabled']: - run_nvme_smart() + run_nvme_smart(ticket_number) if TESTS['badblocks']['Enabled']: - run_badblocks() + run_badblocks(ticket_number) if TESTS['iobenchmark']['Enabled']: - run_iobenchmark() + run_iobenchmark(ticket_number) # Show results show_results()