parent
8be59c2c13
commit
85212fb171
1 changed files with 24 additions and 15 deletions
|
|
@ -18,6 +18,11 @@ REGEX_TEMPS = re.compile(r'^\s*(.*?)\s+(idle:)(.*)$')
|
|||
REGEX_SENSOR = re.compile(r'^(.*?)(\s*)$')
|
||||
|
||||
|
||||
# Error Classes
|
||||
class osTicketConnectionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# Classes
|
||||
class osTicket():
|
||||
"""Class to track osTicket data and functions."""
|
||||
|
|
@ -70,15 +75,9 @@ class osTicket():
|
|||
# Connection established
|
||||
break
|
||||
|
||||
# Disable if necessary
|
||||
if self.db_cursor is None:
|
||||
self.disabled = True
|
||||
self.tunnel_proc.kill()
|
||||
if not silent:
|
||||
print_warning('Failed to connect to osTicket')
|
||||
print_standard('Integration disabled for this session')
|
||||
print_standard(' ')
|
||||
pause()
|
||||
# Raise exception unless silenced
|
||||
if self.db_cursor is None and not silent:
|
||||
raise osTicketConnectionError('Failed to connect to osTicket.')
|
||||
|
||||
def convert_report(self, name, test):
|
||||
"""Convert report into an osTicket friendly format, returns list."""
|
||||
|
|
@ -347,7 +346,7 @@ class osTicket():
|
|||
def get_flag(self, ticket_id, flag_name):
|
||||
"""Get flag in osTicket."""
|
||||
flag_value = None
|
||||
self.connect(silent=True)
|
||||
self.connect()
|
||||
|
||||
# Bail if disabled
|
||||
if self.disabled:
|
||||
|
|
@ -395,11 +394,21 @@ class osTicket():
|
|||
def get_ticket_number(self):
|
||||
"""Get ticket number and confirm with name from osTicket DB."""
|
||||
ticket_number = None
|
||||
self.connect(silent=False)
|
||||
|
||||
# Bail if disabled
|
||||
if self.disabled:
|
||||
return None
|
||||
# Connect
|
||||
while True:
|
||||
try:
|
||||
self.connect(silent=False)
|
||||
except osTicketConnectionError:
|
||||
print_warning('Failed to connect to osTicket')
|
||||
if not ask('Try again?'):
|
||||
print_standard('Integration disabled for this session')
|
||||
self.disabled = True
|
||||
self.tunnel_proc.kill()
|
||||
return None
|
||||
else:
|
||||
# Connection successful
|
||||
break
|
||||
|
||||
# Main loop
|
||||
while ticket_number is None:
|
||||
|
|
@ -498,7 +507,7 @@ class osTicket():
|
|||
|
||||
def set_flag(self, ticket_id, flag_name, flag_value):
|
||||
"""Set flag in osTicket."""
|
||||
self.connect(silent=True)
|
||||
self.connect()
|
||||
|
||||
# Bail if disabled
|
||||
if self.disabled:
|
||||
|
|
|
|||
Loading…
Reference in a new issue