Started integrating osTicket functions in HW Diags
This commit is contained in:
parent
7e69eff7a8
commit
ceee0495eb
2 changed files with 52 additions and 1 deletions
|
|
@ -13,7 +13,7 @@ import time
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
from wk import cfg, debug, exe, graph, log, net, std, tmux
|
from wk import cfg, debug, exe, graph, log, net, osticket, std, tmux
|
||||||
from wk.hw import obj as hw_obj
|
from wk.hw import obj as hw_obj
|
||||||
from wk.hw import sensors as hw_sensors
|
from wk.hw import sensors as hw_sensors
|
||||||
|
|
||||||
|
|
@ -72,6 +72,8 @@ MENU_SETS = {
|
||||||
'Disk Diagnostic (Quick)': ('Disk Attributes',),
|
'Disk Diagnostic (Quick)': ('Disk Attributes',),
|
||||||
}
|
}
|
||||||
MENU_TOGGLES = (
|
MENU_TOGGLES = (
|
||||||
|
'osTicket Integration',
|
||||||
|
'osTicket Note (optional)',
|
||||||
'Skip USB Benchmarks',
|
'Skip USB Benchmarks',
|
||||||
)
|
)
|
||||||
PLATFORM = std.PLATFORM
|
PLATFORM = std.PLATFORM
|
||||||
|
|
@ -96,12 +98,14 @@ class DeviceTooSmallError(RuntimeError):
|
||||||
|
|
||||||
# Classes
|
# Classes
|
||||||
class State():
|
class State():
|
||||||
|
# pylint: disable=too-many-instance-attributes
|
||||||
"""Object for tracking hardware diagnostic data."""
|
"""Object for tracking hardware diagnostic data."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cpu = None
|
self.cpu = None
|
||||||
self.disks = []
|
self.disks = []
|
||||||
self.layout = cfg.hw.TMUX_LAYOUT.copy()
|
self.layout = cfg.hw.TMUX_LAYOUT.copy()
|
||||||
self.log_dir = None
|
self.log_dir = None
|
||||||
|
self.ost = osticket.osTicket()
|
||||||
self.panes = {}
|
self.panes = {}
|
||||||
self.tests = OrderedDict({
|
self.tests = OrderedDict({
|
||||||
'CPU & Cooling': {
|
'CPU & Cooling': {
|
||||||
|
|
@ -235,6 +239,11 @@ class State():
|
||||||
for test_data in self.tests.values():
|
for test_data in self.tests.values():
|
||||||
test_data['Objects'].clear()
|
test_data['Objects'].clear()
|
||||||
|
|
||||||
|
# osTicket
|
||||||
|
self.top_text = std.color_string('Hardware Diagnostics', 'GREEN')
|
||||||
|
self.ost.init()
|
||||||
|
self.ost.disabled = not menu.toggles['osTicket Integration']['Selected']
|
||||||
|
|
||||||
# Set log
|
# Set log
|
||||||
self.log_dir = log.format_log_path()
|
self.log_dir = log.format_log_path()
|
||||||
self.log_dir = pathlib.Path(
|
self.log_dir = pathlib.Path(
|
||||||
|
|
@ -340,6 +349,10 @@ class State():
|
||||||
_f.write(f'\n{name}:\n')
|
_f.write(f'\n{name}:\n')
|
||||||
_f.write('\n'.join(debug.generate_object_report(test, indent=1)))
|
_f.write('\n'.join(debug.generate_object_report(test, indent=1)))
|
||||||
|
|
||||||
|
# osTicket
|
||||||
|
with open(f'{debug_dir}/osTicket.report', 'a') as _f:
|
||||||
|
_f.write('\n'.join(debug.generate_object_report(self.ost)))
|
||||||
|
|
||||||
def update_progress_pane(self):
|
def update_progress_pane(self):
|
||||||
"""Update progress pane."""
|
"""Update progress pane."""
|
||||||
report = []
|
report = []
|
||||||
|
|
@ -411,6 +424,9 @@ def build_menu(cli_mode=False, quick_mode=False):
|
||||||
menu.add_set(name, {'Targets': targets})
|
menu.add_set(name, {'Targets': targets})
|
||||||
menu.actions['Start']['Separator'] = True
|
menu.actions['Start']['Separator'] = True
|
||||||
|
|
||||||
|
# osTicket
|
||||||
|
menu.toggles['osTicket Note (optional)']['Selected'] = False
|
||||||
|
|
||||||
# Update default selections for quick mode if necessary
|
# Update default selections for quick mode if necessary
|
||||||
if quick_mode:
|
if quick_mode:
|
||||||
for name in menu.options:
|
for name in menu.options:
|
||||||
|
|
@ -1100,6 +1116,7 @@ def main():
|
||||||
|
|
||||||
# Quick Mode
|
# Quick Mode
|
||||||
if args['--quick']:
|
if args['--quick']:
|
||||||
|
menu.toggles['osTicket Integration']['Selected'] = False
|
||||||
run_diags(state, menu, quick_mode=True)
|
run_diags(state, menu, quick_mode=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -1216,12 +1233,33 @@ def run_diags(state, menu, quick_mode=False):
|
||||||
atexit.register(state.save_debug_reports)
|
atexit.register(state.save_debug_reports)
|
||||||
state.init_diags(menu)
|
state.init_diags(menu)
|
||||||
|
|
||||||
|
def _init_osticket():
|
||||||
|
"""Dumb private function to avoid pylint error."""
|
||||||
|
if not state.ost.disabled:
|
||||||
|
# Select Ticket
|
||||||
|
state.ost.select_ticket()
|
||||||
|
|
||||||
|
# Update top_text
|
||||||
|
if state.ost.ticket_id:
|
||||||
|
state.top_text += std.color_string(
|
||||||
|
[f' #{state.ost.ticket_id}', state.ost.ticket_name],
|
||||||
|
[None, 'CYAN'],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add note
|
||||||
|
if (state.ost.ticket_id
|
||||||
|
and menu.toggles['osTicket Note (optional)']['Selected']):
|
||||||
|
state.ost.add_note()
|
||||||
|
|
||||||
# Just return if no tests were selected
|
# Just return if no tests were selected
|
||||||
if not any([details['Enabled'] for details in state.tests.values()]):
|
if not any([details['Enabled'] for details in state.tests.values()]):
|
||||||
std.print_warning('No tests selected?')
|
std.print_warning('No tests selected?')
|
||||||
std.pause()
|
std.pause()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# osTicket
|
||||||
|
_init_osticket()
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
for name, details in state.tests.items():
|
for name, details in state.tests.items():
|
||||||
if not details['Enabled']:
|
if not details['Enabled']:
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,15 @@ class osTicket(): # pylint: disable=invalid-name
|
||||||
for line in lines:
|
for line in lines:
|
||||||
self.note += f'\n...{line}'
|
self.note += f'\n...{line}'
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
"""Revert to defaults."""
|
||||||
|
self._disconnect()
|
||||||
|
self.disabled = False
|
||||||
|
self.errors = False
|
||||||
|
self.note = None
|
||||||
|
self.ticket_id = None
|
||||||
|
self.ticket_name = None
|
||||||
|
|
||||||
def post_response(self, response, color='Normal'):
|
def post_response(self, response, color='Normal'):
|
||||||
"""Post a reply to a ticket in osTicket."""
|
"""Post a reply to a ticket in osTicket."""
|
||||||
lines = []
|
lines = []
|
||||||
|
|
@ -232,6 +241,10 @@ class osTicket(): # pylint: disable=invalid-name
|
||||||
"""Set ticket number and name from osTicket DB."""
|
"""Set ticket number and name from osTicket DB."""
|
||||||
std.print_standard('Connecting to osTicket...')
|
std.print_standard('Connecting to osTicket...')
|
||||||
|
|
||||||
|
# Bail if disabled
|
||||||
|
if self.disabled:
|
||||||
|
return
|
||||||
|
|
||||||
# Connect
|
# Connect
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue