Added osTicket DB functions
* osticket_needs_attention() * osticket_reply() * osticket_set_drive_result()
This commit is contained in:
parent
555a661e92
commit
58dead2382
1 changed files with 84 additions and 11 deletions
|
|
@ -6,9 +6,12 @@ import mysql.connector as mariadb
|
|||
|
||||
from functions.common import *
|
||||
|
||||
# osTicket Database
|
||||
db_connection = None
|
||||
db_cursor = None
|
||||
# Database connection
|
||||
ost_db = {
|
||||
'Connection': None,
|
||||
'Cursor': None,
|
||||
'Errors': False
|
||||
}
|
||||
|
||||
# STATIC VARIABLES
|
||||
ATTRIBUTES = {
|
||||
|
|
@ -56,6 +59,16 @@ IO_VARS = {
|
|||
'███▏', '███▎', '███▍', '███▌',
|
||||
'███▋', '███▊', '███▉', '████'),
|
||||
}
|
||||
OST_STAFF_ID = '23'
|
||||
OST_STAFF_NAME = 'Wizard Kit'
|
||||
OST_SQL_SET_HOLD = "UPDATE `{db_name}`.`ost_ticket` SET `hold` = '{hold_type}' WHERE `ost_ticket`.`ticket_id` = {ticket_id};"
|
||||
OST_SQL_SET_FLAG = "UPDATE `{db_name}`.`ost_ticket` SET `{flag}` = '{value}' WHERE `ost_ticket`.`ticket_id` = {ticket_id};"
|
||||
OST_SQL_POST_REPLY = ("INSERT INTO `{db_name}`.`ost_ticket_response` (ticket_id, staff_id, staff_name, response, created) "
|
||||
"VALUES ('{ticket_id}', '{staff_id}', '{staff_name}', '{response}', '{created}');")
|
||||
OST_DRIVE_FLAG = 'zHDTune'
|
||||
OST_DRIVE_PASSED = 1
|
||||
OST_DRIVE_FAILED = 2
|
||||
OST_NEEDS_ATTENTION = 4
|
||||
TESTS = {
|
||||
'Prime95': {
|
||||
'Enabled': False,
|
||||
|
|
@ -80,14 +93,10 @@ TESTS = {
|
|||
|
||||
def connect_to_db():
|
||||
"""Connect to osTicket database."""
|
||||
try:
|
||||
db_connection = mariadb.connect(
|
||||
user=DB_USER, password=DB_PASS, database=DB_NAME, host=DB_HOST)
|
||||
db_cursor = db_connection.cursor()
|
||||
except:
|
||||
db_connection = None
|
||||
db_cursor = None
|
||||
raise
|
||||
ost_db['Connection'] = mariadb.connect(
|
||||
user=DB_USER, password=DB_PASS, database=DB_NAME, host=DB_HOST)
|
||||
ost_db['Cursor'] = ost_db['Connection'].cursor()
|
||||
ost_db['Errors'] = False
|
||||
|
||||
def generate_horizontal_graph(rates):
|
||||
"""Generate two-line horizontal graph from rates, returns str."""
|
||||
|
|
@ -246,6 +255,70 @@ def menu_diags(*args):
|
|||
elif selection == 'Q':
|
||||
break
|
||||
|
||||
def osticket_needs_attention(ticket_id):
|
||||
"""Marks the ticket as "NEEDS ATTENTION" in osTicket."""
|
||||
if not ticket_id:
|
||||
raise GenericError
|
||||
if not ost_db['Cursor']:
|
||||
# Skip section
|
||||
return
|
||||
|
||||
# Set command
|
||||
sql_cmd = OST_SQL_SET_HOLD.format(
|
||||
db_name=DB_NAME,
|
||||
hold_type=OST_NEEDS_ATTENTION,
|
||||
ticket_id=ticket_id)
|
||||
|
||||
# Run command
|
||||
try:
|
||||
ost_db['Cursor'].execute(sql_cmd)
|
||||
except:
|
||||
sql_errors = True
|
||||
|
||||
def osticket_reply(ticket_id, response):
|
||||
"""Post a reply to a ticket in osTicket."""
|
||||
if not ticket_id:
|
||||
raise GenericError
|
||||
if not ost_db['Cursor']:
|
||||
# Skip section
|
||||
return
|
||||
|
||||
# Set command
|
||||
sql_cmd = OST_SQL_POST_REPLY.format(
|
||||
db_name=DB_NAME,
|
||||
ticket_id=ticket_id,
|
||||
staff_id=OST_STAFF_ID,
|
||||
staff_name=OST_STAFF_NAME,
|
||||
response=response,
|
||||
created=time.strftime("%Y-%m-%d %H:%M:%S"))
|
||||
|
||||
# Run command
|
||||
try:
|
||||
ost_db['Cursor'].execute(sql_cmd)
|
||||
except:
|
||||
sql_errors = True
|
||||
|
||||
def osticket_set_drive_result(ticket_id, passed):
|
||||
"""Marks the pass/fail box for the drive(s) in osTicket."""
|
||||
if not ticket_id:
|
||||
raise GenericError
|
||||
if not ost_db['Cursor']:
|
||||
# Skip section
|
||||
return
|
||||
|
||||
# Set command
|
||||
sql_cmd = OST_SQL_SET_FLAG.format(
|
||||
db_name=DB_NAME,
|
||||
flag=OST_DRIVE_FLAG,
|
||||
value=OST_DRIVE_PASSED if passed else OST_DRIVE_FAILED,
|
||||
ticket_id=ticket_id)
|
||||
|
||||
# Run command
|
||||
try:
|
||||
ost_db['Cursor'].execute(sql_cmd)
|
||||
except:
|
||||
sql_errors = True
|
||||
|
||||
def run_badblocks():
|
||||
"""Run a read-only test for all detected disks."""
|
||||
aborted = False
|
||||
|
|
|
|||
Loading…
Reference in a new issue