From 214e2c345d7cb682f7040c077776f47a20e81643 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 18 Nov 2019 18:47:39 -0700 Subject: [PATCH] Expanded HW-Diags - osTicket checkbox sections --- .bin/Scripts/functions/hw_diags.py | 85 ++++++++++++++++++++---------- .bin/Scripts/functions/osticket.py | 30 +++++++++++ .bin/Scripts/functions/sensors.py | 16 ++++++ .bin/Scripts/settings/osticket.py | 8 +++ 4 files changed, 110 insertions(+), 29 deletions(-) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index e8b955f9..39286f5b 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -39,6 +39,14 @@ class CpuObj(): self.name = self.lscpu.get('Model name', 'Unknown CPU') self.description = self.name + def all_tests_passed(self): + """Check if all tests passed, returns bool.""" + return all([results.passed for results in self.tests.values()]) + + def any_test_failed(self): + """Check if any test failed, returns bool.""" + return any([results.failed for results in self.tests.values()]) + def get_details(self): """Get CPU details from lscpu.""" cmd = ['lscpu', '--json'] @@ -117,6 +125,14 @@ class DiskObj(): # A dict is used to avoid duplicate notes self.nvme_smart_notes[note] = None + def all_tests_passed(self): + """Check if all tests passed, returns bool.""" + return all([results.passed for results in self.tests.values()]) + + def any_test_failed(self): + """Check if any test failed, returns bool.""" + return any([results.failed for results in self.tests.values()]) + def calc_io_dd_values(self): """Calcualte I/O benchmark dd values. @@ -1227,11 +1243,9 @@ def run_hw_tests(state): v['Objects'][-1].update_status('N/A') if k == TESTS_CPU[-1]: # Last CPU test run, post CPU results - cpu_failed = False - for test in state.cpu.tests.values(): - cpu_failed = cpu_failed or test.failed - cpu_failed = cpu_failed or not test.passed - color_code = 'Diags FAIL' if cpu_failed else 'Diags' + color_code = 'Diags' + if state.cpu.any_test_failed(): + color_code = 'Diags FAIL' state.ost.post_device_results( state.cpu, state.ticket_id, state.ticket_name, color_code) # Recheck attributes @@ -1270,33 +1284,11 @@ def run_hw_tests(state): for disk in state.disks: # Set color code color_code = 'Diags' - for test in disk.tests.values(): - if test.disabled: - if test.failed: - color_code = 'Diags FAIL' - continue - if test.failed or not (test.passed or 'N/A' in test.status): - color_code = 'Diags FAIL' + if disk.any_test_failed(): + color_code = 'Diags FAIL' state.ost.post_device_results( disk, state.ticket_id, state.ticket_name, color_code) - # Check if disk checkbox needs updating - all_disks_passed = True - disk_failures = False - for disk in state.disks: - if disk.checkbox is None: - # Aborted/Unknown/etc - all_disks_passed = False - else: - all_disks_passed = all_disks_passed and disk.checkbox - disk_failures = disk_failures or not disk.checkbox - - # Update checkbox if necessary - if disk_failures: - state.ost.set_disk_failed(state.ticket_id) - elif all_disks_passed: - state.ost.set_disk_passed(state.ticket_id) - # Spacer print_standard(' ') @@ -1319,6 +1311,40 @@ def run_hw_tests(state): global_vars=global_vars, reason='Review') + # Do we need to update checkboxes? + all_disks_passed = all([disk.all_tests_passed() for disk in state.disks]) + all_disk_tests_enabled = all( + [state.tests[name]['Enabled'] for name in TESTS_DISK]) + any_disk_failures = any([disk.any_test_failed() for disk in state.disks]) + cpu_failed = state.cpu.any_test_failed() + cpu_max_temp = get_cpu_max_temp(state.cpu.sensor_data) + cpu_max_temp = f'{cpu_max_temp:2.0f}' + cpu_passed = state.cpu.all_tests_passed() + update_checkboxes = False + if state.ticket_id: + if state.tests['Prime95']: + update_checkboxes = True + elif any_disk_failures: + update_checkboxes = True + elif all_disk_tests_enabled and all_disks_passed: + update_checkboxes = True + + + # Ask to update checkboxes + if update_checkboxes and ask('Update checkboxes using above results?'): + # CPU checkboxes + if cpu_failed: + state.ost.set_cpu_failed(state.ticket_id) + elif cpu_passed: + state.ost.set_cpu_passed(state.ticket_id) + state.ost.set_cpu_temp(state.ticket_id, temp=cpu_max_temp) + + # Disk checkboxes + if any_disk_failures: + state.ost.set_disk_failed(state.ticket_id) + elif all_disk_tests_enabled and all_disks_passed: + state.ost.set_disk_passed(state.ticket_id) + # Done sleep(1) if state.quick_mode: @@ -1548,6 +1574,7 @@ def run_mprime_test(state, test): command=['hw-diags-prime95', global_vars['TmpDir']], working_dir=global_vars['TmpDir']) time_limit = MPRIME_LIMIT * 60 + time_limit = 14 try: for i in range(time_limit): #clear_screen() diff --git a/.bin/Scripts/functions/osticket.py b/.bin/Scripts/functions/osticket.py index 09141ab7..f2369534 100644 --- a/.bin/Scripts/functions/osticket.py +++ b/.bin/Scripts/functions/osticket.py @@ -544,6 +544,36 @@ class osTicket(): # Done self.disconnect() + def set_cpu_failed(self, ticket_id): + """Mark cpu as failed in osTicket.""" + self.set_flag( + ticket_id, + OSTICKET['CPU Flag']['Name'], + OSTICKET['CPU Flag']['Fail']) + + def set_cpu_passed(self, ticket_id): + """Mark cpu as passed in osTicket.""" + current_value = self.get_flag(ticket_id, OSTICKET['CPU Flag']['Name']) + + # Bail early? + if current_value == OSTICKET['CPU Flag']['Fail']: + print_warning('Not replacing osTicket cpu checkbox FAILED value') + return + + # Current value != FAILED, set to passed + self.set_flag( + ticket_id, + OSTICKET['CPU Flag']['Name'], + OSTICKET['CPU Flag']['Pass']) + + def set_cpu_max_temp(self, ticket_id, temp): + """Set CPU temp string in osTicket.""" + self.set_flag( + ticket_id, + OSTICKET['CPU Temp']['Name'], + temp, + ) + def set_disk_failed(self, ticket_id): """Mark disk as failed in osTicket.""" self.set_flag( diff --git a/.bin/Scripts/functions/sensors.py b/.bin/Scripts/functions/sensors.py index 49a7472c..47fabf28 100644 --- a/.bin/Scripts/functions/sensors.py +++ b/.bin/Scripts/functions/sensors.py @@ -101,6 +101,22 @@ def get_colored_temp_str(temp): **COLORS) +def get_cpu_max_temp(sensor_data): + """get max temp""" + max_temp = 0.0 + + # Check all CPU Temps + for section, adapters in sensor_data.items(): + if not section.startswith('CPU'): + continue + for sources in adapters.values(): + for source_data in sources.values(): + max_temp = max(max_temp, source_data.get('Max', 0)) + + # Done + return max_temp + + def get_raw_sensor_data(): """Read sensor data and return dict.""" json_data = {} diff --git a/.bin/Scripts/settings/osticket.py b/.bin/Scripts/settings/osticket.py index 66a360f0..3c10ba83 100644 --- a/.bin/Scripts/settings/osticket.py +++ b/.bin/Scripts/settings/osticket.py @@ -7,6 +7,14 @@ OSTICKET = { 'Diags': '2', 'Diags FAIL': '3', }, + 'CPU Flag': { + 'Name': 'zTemps', + 'Pass': 1, + 'Fail': 2, + }, + 'CPU Temp': { + 'Name': 'zMaxTemp', + }, 'Database': { 'Name': 'osticket', 'User': 'wizardkit',