Support new color codes in osTicket posts

* Addresses #105
This commit is contained in:
2Shirt 2019-07-02 20:53:35 -06:00
parent a868d28452
commit 0077240255
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
3 changed files with 25 additions and 7 deletions

View file

@ -1215,8 +1215,12 @@ 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
color_code = 'Diags FAIL' if cpu_failed else 'Diags'
state.ost.post_device_results(
state.cpu, state.ticket_id, state.ticket_name)
state.cpu, state.ticket_id, state.ticket_name, color_code)
# Recheck attributes
if state.tests['NVMe / SMART']['Enabled']:
for test_obj in state.tests['NVMe / SMART']['Objects']:
@ -1251,8 +1255,15 @@ def run_hw_tests(state):
if _disk_tests_enabled and state.disks and not state.ost.disabled:
print_standard('Posting results to osTicket...')
for disk in state.disks:
# Set color code
color_code = 'Diags'
for test in disk.tests.values():
if test.disabled:
continue
if test.failed or not (test.passed or 'N/A' in test.status):
color_code = 'Diags FAIL'
state.ost.post_device_results(
disk, state.ticket_id, state.ticket_name)
disk, state.ticket_id, state.ticket_name, color_code)
# Check if disk checkbox needs updating
all_disks_passed = True

View file

@ -502,15 +502,15 @@ class osTicket():
# Done
return data
def post_device_results(self, dev, ticket_id, ticket_name):
def post_device_results(self, dev, ticket_id, ticket_name, color='Diags'):
"""Generate osTicket friendly report and post as response to ticket."""
if not dev.tests:
# No test results available, aborting post
return
response = self.generate_report(dev, ticket_id, ticket_name)
self.post_response(response, ticket_id)
self.post_response(response, ticket_id, color)
def post_response(self, response, ticket_id):
def post_response(self, response, ticket_id, color='Normal'):
"""Post a reply to a ticket in osTicket."""
self.connect()
@ -525,12 +525,13 @@ class osTicket():
# Build SQL cmd
sql_cmd = "INSERT INTO `{Name}`.`{Response}`".format(
**OSTICKET['Database'], **OSTICKET['Tables'])
sql_cmd += " (ticket_id, staff_id, staff_name, response, created)"
sql_cmd += " (ticket_id, staff_id, staff_name, response, created, code)"
sql_cmd += " VALUES ("
sql_cmd += " '{}',".format(ticket_id)
sql_cmd += " '{ID}', '{Name}',".format(**OSTICKET['Staff'])
sql_cmd += " '{}',".format(response.replace("'", "\\'"))
sql_cmd += " '{}'".format(time.strftime("%Y-%m-%d %H:%M:%S"))
sql_cmd += " '{}',".format(time.strftime("%Y-%m-%d %H:%M:%S"))
sql_cmd += " '{}'".format(OSTICKET['Color Codes'][color])
sql_cmd += " );"
# Run SQL cmd

View file

@ -1,6 +1,12 @@
# Wizard Kit: Settings - osTicket
OSTICKET = {
'Color Codes': {
'Normal': '0',
'Contact': '1',
'Diags': '2',
'Diags FAIL': '3',
},
'Database': {
'Name': 'osticket',
'User': 'wizardkit',