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 *
|
from functions.common import *
|
||||||
|
|
||||||
# osTicket Database
|
# Database connection
|
||||||
db_connection = None
|
ost_db = {
|
||||||
db_cursor = None
|
'Connection': None,
|
||||||
|
'Cursor': None,
|
||||||
|
'Errors': False
|
||||||
|
}
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
ATTRIBUTES = {
|
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 = {
|
TESTS = {
|
||||||
'Prime95': {
|
'Prime95': {
|
||||||
'Enabled': False,
|
'Enabled': False,
|
||||||
|
|
@ -80,14 +93,10 @@ TESTS = {
|
||||||
|
|
||||||
def connect_to_db():
|
def connect_to_db():
|
||||||
"""Connect to osTicket database."""
|
"""Connect to osTicket database."""
|
||||||
try:
|
ost_db['Connection'] = mariadb.connect(
|
||||||
db_connection = mariadb.connect(
|
|
||||||
user=DB_USER, password=DB_PASS, database=DB_NAME, host=DB_HOST)
|
user=DB_USER, password=DB_PASS, database=DB_NAME, host=DB_HOST)
|
||||||
db_cursor = db_connection.cursor()
|
ost_db['Cursor'] = ost_db['Connection'].cursor()
|
||||||
except:
|
ost_db['Errors'] = False
|
||||||
db_connection = None
|
|
||||||
db_cursor = None
|
|
||||||
raise
|
|
||||||
|
|
||||||
def generate_horizontal_graph(rates):
|
def generate_horizontal_graph(rates):
|
||||||
"""Generate two-line horizontal graph from rates, returns str."""
|
"""Generate two-line horizontal graph from rates, returns str."""
|
||||||
|
|
@ -246,6 +255,70 @@ def menu_diags(*args):
|
||||||
elif selection == 'Q':
|
elif selection == 'Q':
|
||||||
break
|
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():
|
def run_badblocks():
|
||||||
"""Run a read-only test for all detected disks."""
|
"""Run a read-only test for all detected disks."""
|
||||||
aborted = False
|
aborted = False
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue