Show volume report if all disk tests are run
* Enable CoreStorage mounting only if all tests were CS, N/A, or OVERRIDE
This commit is contained in:
parent
2c0093aa9a
commit
7d7cf21263
1 changed files with 66 additions and 17 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import mysql.connector as mariadb
|
||||
|
||||
from functions.data import *
|
||||
from functions.io_graph import *
|
||||
from settings.osticket import *
|
||||
|
||||
|
|
@ -122,6 +123,23 @@ class osTicket():
|
|||
# Done
|
||||
return out_report
|
||||
|
||||
def disconnect(self, reset_errors=False):
|
||||
"""Close osTicket connection."""
|
||||
try:
|
||||
self.db_cursor.close()
|
||||
self.db_connection.close()
|
||||
except Exception:
|
||||
# TODO: Fix exception handling
|
||||
pass
|
||||
|
||||
# Reset errors
|
||||
if reset_errors:
|
||||
self.errors = False
|
||||
|
||||
# Reset vars
|
||||
self.db_cursor = None
|
||||
self.db_connection = None
|
||||
|
||||
def generate_report(self, dev, ticket_id):
|
||||
"""Generate device report for osTicket, returns list."""
|
||||
report = []
|
||||
|
|
@ -163,10 +181,10 @@ class osTicket():
|
|||
report.append(' ')
|
||||
|
||||
# Volumes
|
||||
if results['Dev Type'] == 'Disk':
|
||||
# TODO: Mount all volumes and extend report
|
||||
if results['Dev Type'] == 'Disk' and results['Full Diag']:
|
||||
# Mount all volumes and extend report
|
||||
report.append('Volumes:')
|
||||
report.append('TODO')
|
||||
report.extend(self.generate_volume_report(dev, results))
|
||||
report.append(' ')
|
||||
|
||||
# Asterisk
|
||||
|
|
@ -176,31 +194,56 @@ class osTicket():
|
|||
# Done
|
||||
return report
|
||||
|
||||
def disconnect(self, reset_errors=False):
|
||||
"""Close osTicket connection."""
|
||||
try:
|
||||
self.db_cursor.close()
|
||||
self.db_connection.close()
|
||||
except Exception:
|
||||
# TODO: Fix exception handling
|
||||
pass
|
||||
def generate_volume_report(self, dev, results):
|
||||
"""Mount all volumes for dev and generate report, returns list."""
|
||||
report = []
|
||||
mount_report = mount_volumes(
|
||||
all_devices=False,
|
||||
device_path='{}'.format(dev.path),
|
||||
core_storage=results['Core'])
|
||||
|
||||
# Reset errors
|
||||
if reset_errors:
|
||||
self.errors = False
|
||||
# Format report
|
||||
for v_path, v_data in sorted(mount_report.items()):
|
||||
label = v_data.get('label', '')
|
||||
if label:
|
||||
label = '"{}"'.format(label)
|
||||
else:
|
||||
# Ensure string type
|
||||
label = ''
|
||||
size = v_data.get('size', '')
|
||||
if size:
|
||||
size = '{} {}B'.format(size[:-1], size[-1:]).upper()
|
||||
else:
|
||||
size = 'UNKNOWN'
|
||||
size_used = v_data.get('size_used', 'UNKNOWN').upper()
|
||||
size_avail = v_data.get('size_avail', 'UNKNOWN').upper()
|
||||
v_data = [v_path, label, size, size_used, size_avail]
|
||||
v_data = [v.strip().replace(' ', '_') for v in v_data]
|
||||
for i in range(len(v_data)):
|
||||
pad = 8
|
||||
if i < 2:
|
||||
pad += 4 * (2 - i)
|
||||
v_data[i] = pad_with_dots(
|
||||
'{s:<{p}}'.format(s=v_data[i], p=pad),
|
||||
pad_right=True)
|
||||
v_data[-1] = re.sub(r'\.*$', '', v_data[-1])
|
||||
v_data = [v.replace('_', ' ') for v in v_data]
|
||||
report.append(
|
||||
'{}..{}..Total..{}..(Used..{}..Free..{})'.format(*v_data))
|
||||
|
||||
# Reset vars
|
||||
self.db_cursor = None
|
||||
self.db_connection = None
|
||||
# Done
|
||||
return report
|
||||
|
||||
def get_device_overall_results(self, dev):
|
||||
"""Get overall results from tests for device, returns dict."""
|
||||
results = {
|
||||
'Core': False,
|
||||
'Dev Type': self.get_device_type(dev),
|
||||
'Full Diag': False,
|
||||
'Asterisk': None,
|
||||
'Failed': 0,
|
||||
'N/A': 0,
|
||||
'OVERRIDE': 0,
|
||||
'Passed': 0,
|
||||
'Status': 'Unknown',
|
||||
}
|
||||
|
|
@ -228,6 +271,8 @@ class osTicket():
|
|||
results['Passed'] += 1
|
||||
if 'N/A' in test.status:
|
||||
results['N/A'] += 1
|
||||
if 'OVERRIDE' in test.status:
|
||||
results['OVERRIDE'] += 1
|
||||
|
||||
# Set overall status
|
||||
if results['Failed'] > 0:
|
||||
|
|
@ -242,6 +287,10 @@ class osTicket():
|
|||
results['Asterisk'] = True
|
||||
results['Status'] += '*'
|
||||
|
||||
# Enable CoreStorage searches
|
||||
results['Core'] = (results['Full Diag'] and
|
||||
results['Passed']+results['N/A']+results['OVERRIDE'] == len(test_list))
|
||||
|
||||
# Done
|
||||
return results
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue