Include more details when selecting a ticket
* Ticket ID is shown in BLUE * Ticket subject is shown in CYAN * Fixes issue #68
This commit is contained in:
parent
2a0a80b09a
commit
fe6762cf05
1 changed files with 47 additions and 29 deletions
|
|
@ -402,22 +402,6 @@ class osTicket():
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
return flag_value
|
return flag_value
|
||||||
|
|
||||||
def get_ticket_name(self, ticket_id):
|
|
||||||
"""Lookup ticket and return name as str."""
|
|
||||||
name = None
|
|
||||||
sql_cmd = "SELECT name FROM `{Ticket}`".format(**OSTICKET['Tables'])
|
|
||||||
sql_cmd += " WHERE `ticket_id` = {}".format(ticket_id)
|
|
||||||
sql_cmd += ";"
|
|
||||||
|
|
||||||
# Lookup name
|
|
||||||
# NOTE: If multiple entries are found it will return the last
|
|
||||||
self.db_cursor.execute(sql_cmd)
|
|
||||||
for s in self.db_cursor:
|
|
||||||
name = s[0]
|
|
||||||
|
|
||||||
# Done
|
|
||||||
return name
|
|
||||||
|
|
||||||
def get_ticket_details(self):
|
def get_ticket_details(self):
|
||||||
"""Get ticket number and name from osTicket DB, returns tuple."""
|
"""Get ticket number and name from osTicket DB, returns tuple."""
|
||||||
ticket_name = None
|
ticket_name = None
|
||||||
|
|
@ -441,40 +425,74 @@ class osTicket():
|
||||||
# Main loop
|
# Main loop
|
||||||
while ticket_number is None:
|
while ticket_number is None:
|
||||||
print_standard(' ')
|
print_standard(' ')
|
||||||
_input = input('Enter ticket number (or leave blank to disable): ')
|
_ticket_id = input('Enter ticket number (or leave blank to disable): ')
|
||||||
_input = _input.strip()
|
_ticket_id = _ticket_id.strip()
|
||||||
|
|
||||||
# No ticket ID entered
|
# No ticket ID entered
|
||||||
if re.match(r'^\s*$', _input):
|
if re.match(r'^\s*$', _ticket_id):
|
||||||
if ask('Disable osTicket integration for this run?'):
|
if ask('Disable osTicket integration for this run?'):
|
||||||
self.disabled = True
|
self.disabled = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# Invalid ID entered
|
# Invalid ID entered
|
||||||
if not re.match(r'^(\d+)$', _input):
|
if not re.match(r'^(\d+)$', _ticket_id):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Valid ID entered, lookup name
|
# Valid ID entered, lookup name
|
||||||
try:
|
try:
|
||||||
_name = self.get_ticket_name(_input)
|
_name = self.get_ticket_field(_ticket_id, 'name')
|
||||||
except Exception:
|
except Exception:
|
||||||
# Ignore and return None below
|
# Ignore and return None below
|
||||||
break
|
break
|
||||||
|
|
||||||
# Verify
|
# Verify ticket exists
|
||||||
if _name is None:
|
if _name is None:
|
||||||
print_error('ERROR: Ticket {} not found.'.format(_input))
|
print_error('ERROR: Ticket {} not found.'.format(_ticket_id))
|
||||||
elif _name:
|
continue
|
||||||
print_standard('You have selected ticket #{} {}'.format(
|
|
||||||
_input, _name))
|
# Lookup subject
|
||||||
|
try:
|
||||||
|
_subject = self.get_ticket_field(_ticket_id, 'subject')
|
||||||
|
except Exception:
|
||||||
|
# Ignore and set to None
|
||||||
|
_subject = None
|
||||||
|
|
||||||
|
# Verify the selected ticket is correct
|
||||||
|
print_standard(
|
||||||
|
'You have selected ticket {BLUE}#{ticket_id}{CLEAR} {name}'.format(
|
||||||
|
ticket_id=_ticket_id,
|
||||||
|
name=_name,
|
||||||
|
**COLORS))
|
||||||
|
print_standard('{CYAN} {subject}{CLEAR}'.format(
|
||||||
|
subject=_subject,
|
||||||
|
**COLORS))
|
||||||
|
print_standard(' ')
|
||||||
if ask('Is this correct?'):
|
if ask('Is this correct?'):
|
||||||
ticket_name = _name
|
ticket_name = _name
|
||||||
ticket_number = _input
|
ticket_number = _ticket_id
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
return (ticket_number, ticket_name)
|
return (ticket_number, ticket_name)
|
||||||
|
|
||||||
|
def get_ticket_field(self, ticket_id, field):
|
||||||
|
"""Lookup ticket and return field as str."""
|
||||||
|
data = None
|
||||||
|
sql_cmd = "SELECT {field} FROM `{Ticket}`".format(
|
||||||
|
field=field,
|
||||||
|
**OSTICKET['Tables'])
|
||||||
|
sql_cmd += " WHERE `ticket_id` = {}".format(ticket_id)
|
||||||
|
sql_cmd += ";"
|
||||||
|
|
||||||
|
# Lookup data
|
||||||
|
# NOTE: If multiple entries are found it will return the last
|
||||||
|
self.db_cursor.execute(sql_cmd)
|
||||||
|
for s in self.db_cursor:
|
||||||
|
data = s[0]
|
||||||
|
|
||||||
|
# Done
|
||||||
|
return data
|
||||||
|
|
||||||
def post_device_results(self, dev, ticket_id, ticket_name):
|
def post_device_results(self, dev, ticket_id, ticket_name):
|
||||||
"""Generate osTicket friendly report and post as response to ticket."""
|
"""Generate osTicket friendly report and post as response to ticket."""
|
||||||
if not dev.tests:
|
if not dev.tests:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue