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()
|
||||
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):
|
||||
"""Get ticket number and name from osTicket DB, returns tuple."""
|
||||
ticket_name = None
|
||||
|
|
@ -441,40 +425,74 @@ class osTicket():
|
|||
# Main loop
|
||||
while ticket_number is None:
|
||||
print_standard(' ')
|
||||
_input = input('Enter ticket number (or leave blank to disable): ')
|
||||
_input = _input.strip()
|
||||
_ticket_id = input('Enter ticket number (or leave blank to disable): ')
|
||||
_ticket_id = _ticket_id.strip()
|
||||
|
||||
# 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?'):
|
||||
self.disabled = True
|
||||
break
|
||||
|
||||
# Invalid ID entered
|
||||
if not re.match(r'^(\d+)$', _input):
|
||||
if not re.match(r'^(\d+)$', _ticket_id):
|
||||
continue
|
||||
|
||||
# Valid ID entered, lookup name
|
||||
try:
|
||||
_name = self.get_ticket_name(_input)
|
||||
_name = self.get_ticket_field(_ticket_id, 'name')
|
||||
except Exception:
|
||||
# Ignore and return None below
|
||||
break
|
||||
|
||||
# Verify
|
||||
# Verify ticket exists
|
||||
if _name is None:
|
||||
print_error('ERROR: Ticket {} not found.'.format(_input))
|
||||
elif _name:
|
||||
print_standard('You have selected ticket #{} {}'.format(
|
||||
_input, _name))
|
||||
if ask('Is this correct?'):
|
||||
ticket_name = _name
|
||||
ticket_number = _input
|
||||
print_error('ERROR: Ticket {} not found.'.format(_ticket_id))
|
||||
continue
|
||||
|
||||
# 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?'):
|
||||
ticket_name = _name
|
||||
ticket_number = _ticket_id
|
||||
|
||||
# Done
|
||||
self.disconnect()
|
||||
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):
|
||||
"""Generate osTicket friendly report and post as response to ticket."""
|
||||
if not dev.tests:
|
||||
|
|
|
|||
Loading…
Reference in a new issue