From df2a7c03c1647e678f49a6b00c978130c1da7345 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Wed, 8 Jan 2020 22:05:23 -0700 Subject: [PATCH] Added initial osTicket files --- scripts/wk/ost.py | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 scripts/wk/ost.py diff --git a/scripts/wk/ost.py b/scripts/wk/ost.py new file mode 100644 index 00000000..8894ee7a --- /dev/null +++ b/scripts/wk/ost.py @@ -0,0 +1,113 @@ +"""WizardKit: osTicket Functions""" +# vim: sts=2 sw=2 ts=2 + +import atexit +import socket + +import mysql.connector as mariadb + + +# Classes +class osTicket(): # pylint: disable=invalid-name + """Class to track osTicket data and functions.""" + def __init__(self): + self.db_connection = None + self.db_cursor = None + self.disabled = False + self.tunnel_proc = None + + def connect(self, silent=True): + """Establish connection to osTicket via SSH tunnel.""" + # TODO connect + + def convert_report(self, name, report): + """Convert report into an osTicket friendly format, returns list.""" + out_report = [] + #TODO: Convert report + + def disconnect(self): + """Close osTicket connection.""" + # TODO: disconnect + + def get_flag(self, ticket_id, flag_name): + """Get flag for ticket_id from osTicket, returns int.""" + # TODO Get flag value, is it a consistent type? ^^ + + def get_ticket_id(self): + """Get ticket number and name from osTicket DB.""" + # TODO Get ticket number and name, save to self + + def get_ticket_field(self, ticket_id, field): + """Get field for ticket_id from osTicket, returns str.""" + # TODO: Get ticket field + + def set_cpu_failed(self, ticket_id): + """Set CPU as failed in osTicket for ticket_id.""" + # TODO Set CPU failed + + def set_cpu_passed(self, ticket_id): + """Set CPU as passed in osTicket for ticket_id. + + NOTE: This will not overwrite a failed status. + """ + # TODO Set CPU passed + + def set_disk_failed(self, ticket_id): + """Set disk as failed in osTicket for ticket_id.""" + # TODO Set disk failed + + def set_disk_passed(self, ticket_id): + """Set disk as passed in osTicket for ticket_id. + + NOTE: This will not overwrite a failed status. + """ + # TODO Set disk passed + + def set_flag(self, ticket_id, flag_name, flag_value): + """Set flag_name to flag_value for ticket_id in osTicket. + + NOTE: This will overwrite any existing value. + """ + # TODO: Set flag value + + +# Functions +def get_test_station_name(): + """Get test station name from hostname, returns str. + + NOTES: This is quite broad and may include false-positives. + If not a test station then an empty string is returned. + """ + hostname = socket.getfqdn() + + # Check if this is a test station + if TEST_STATIONS['Domain'] in hostname: + hostname = hostname.replace(TEST_STATIONS['Domain'], '') + if hostname.lower() in TEST_STATIONS['Known Names']: + hostname = TEST_STATIONS['Known Names'][hostname.lower()] + else: + hostname = '' + + # Done + return hostname + + +def pad_with_dots(text, pad_right=False): + """Replace space padding with dots, returns str. + + NOTE: This is a dumb hack to better align text in osTicket. + """ + text = str(text) + text = text.replace(' ', '..') + if '.' in text: + if pad_right: + text = f'{text}.' + else: + text = f'.{text}' + + # Done + return text + + +if __name__ == '__main__': + print("This file is not meant to be called directly.")