Added post_response()
This commit is contained in:
parent
dcd1525c4f
commit
b4e07a0d88
1 changed files with 36 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
import atexit
|
import atexit
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
import time
|
||||||
|
|
||||||
import mysql.connector as mariadb
|
import mysql.connector as mariadb
|
||||||
|
|
||||||
|
|
@ -174,6 +175,41 @@ class osTicket(): # pylint: disable=invalid-name
|
||||||
LOG.error('Ticket ID not set')
|
LOG.error('Ticket ID not set')
|
||||||
raise RuntimeError('Ticket ID not set')
|
raise RuntimeError('Ticket ID not set')
|
||||||
|
|
||||||
|
def post_response(self, response, color='Normal'):
|
||||||
|
"""Post a reply to a ticket in osTicket."""
|
||||||
|
self._connect()
|
||||||
|
self._verify_ticket_id()
|
||||||
|
|
||||||
|
# Bail if disabled
|
||||||
|
if self.disabled:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Format response
|
||||||
|
response = str(response).replace("`", "'").replace("'", "\\'")
|
||||||
|
|
||||||
|
# Build SQL cmd
|
||||||
|
sql_cmd = (
|
||||||
|
f"INSERT INTO `{SQL['DB']}`.`{TABLE_RESPONSE}` "
|
||||||
|
f"(ticket_id, staff_id, staff_name, response, created, code) "
|
||||||
|
f"VALUES ("
|
||||||
|
f" '{self.ticket_id}',"
|
||||||
|
f" '{STAFF['ID']}',"
|
||||||
|
f" '{STAFF['Name']}',"
|
||||||
|
f" '{response}',"
|
||||||
|
f" '{time.strftime('%Y-%m-%d %H:%M:%S')}',"
|
||||||
|
f" '{RESPONSE_COLOR_CODES.get(color, 'Normal')}'"
|
||||||
|
f");"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run SQL cmd
|
||||||
|
try:
|
||||||
|
self.db_cursor.execute(sql_cmd)
|
||||||
|
except mariadb.errors.Error:
|
||||||
|
self.errors = True
|
||||||
|
|
||||||
|
# Done
|
||||||
|
self._disconnect()
|
||||||
|
|
||||||
def select_ticket(self):
|
def select_ticket(self):
|
||||||
"""Set ticket number and name from osTicket DB."""
|
"""Set ticket number and name from osTicket DB."""
|
||||||
print_standard('Connecting to osTicket...')
|
print_standard('Connecting to osTicket...')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue