class Connection(komand.Connection): def __init__(self): super(self.__class__, self).__init__(input=ConnectionSchema()) self.client = None self.server = None self.user_login = None self.password = None def connect(self, params): self.logger.info("Connect: Connecting...") server = params.get('server', '') user_login = params.get('credentials').get('username', '') password = params.get('credentials').get('password', '') self.server = server self.user_login = user_login self.password = password self.client = Client(server, user_login, password) def test(self): try: self.client.session_create() except Exception as e: raise Exception( "Unable to connect to OTRS webservice! Please check your connection information and \ that you have properly configured OTRS webservice. Information on configuring the webservice can be found \ in the Connection help") return {}
def connect(self, params): self.logger.info("Connect: Connecting...") server = params.get('server', '') user_login = params.get('credentials').get('username', '') password = params.get('credentials').get('password', '') self.server = server self.user_login = user_login self.password = password self.client = Client(server, user_login, password)
def connect(self, params): self.logger.info("Connect: Connecting...") server = params.get("server", "") user_login = params.get("credentials").get("username", "") password = params.get("credentials").get("password", "") self.server = server self.user_login = user_login self.password = password self.client = Client(server, user_login, password)
def get_ticket(argument): client = Client(config.CLIENT_URL, config.USER, config.PASSWD) client.session_create() ticket = client.ticket_get_by_number(argument,articles=True) result = ticket.to_dct() json_string = json.dumps(result) parsed_string = json.loads(json_string) title = (parsed_string["Ticket"]["Title"]) user = (parsed_string["Ticket"]["Article"][0]["From"]) queue = (parsed_string["Ticket"]["Queue"]) msg_body = (parsed_string["Ticket"]["Article"][0]["Body"]) date = (parsed_string["Ticket"]["Created"]) message = ('Очередь: ' + queue + '\n' + 'От кого: ' + user + '\n' + 'Тема: ' + title + '\n' + msg_body + '\n' + date) return message
def Stage(): conf = Load() client = Client("%s" % conf['otrs']['server'], "%s" % conf['otrs']['user'], "%s" % conf['otrs']['pass']) return client
def CreateTicket(SIEM_Events): conf = LoadConfig.Load() client = Client("%s" % conf['otrs']['server'], "%s" % conf['otrs']['user'], "%s" % conf['otrs']['pass']) client.session_create() with open("siem_events.csv", "rt") as events: data = csv.reader(events) for event in data: ticket = Ticket.create_basic(Title=event[0], Queue=event[1], State=event[2], Priority=event[3], CustomerUser=event[4]) article = Article({"Subject": event[5], "Body": event[6]}) logging.info(client.ticket_create(ticket, article)) sleep(30)
def main(): global otrs_client handle_proxy(demisto.params().get('proxy')) cache = demisto.getIntegrationContext() otrs_client = Client(SERVER, USERNAME, PASSWORD, https_verify=USE_SSL, use_legacy_sessions=USE_LEGACY_SESSIONS) # OTRS creates new session for each request, to avoid that behavior - # save the sessionId in integration context to use it multiple times if cache.get('SessionID'): otrs_client.session_id_store.write(cache['SessionID']) else: update_session() LOG('command is %s' % (demisto.command(), )) try: if demisto.command() == 'test-module': # Testing connectivity and credentials demisto.results('ok') elif demisto.command() == 'fetch-incidents': fetch_incidents() elif demisto.command() == 'otrs-get-ticket': get_ticket_command() elif demisto.command() == 'otrs-search-ticket': search_ticket_command() elif demisto.command() == 'otrs-create-ticket': create_ticket_command() elif demisto.command() == 'otrs-update-ticket': update_ticket_command() elif demisto.command() == 'otrs-close-ticket': close_ticket_command() except Exception as e: LOG(str(e)) LOG.print_log() return_error(str(e))
def buildTicket(OTRS_SERVER, OTRS_USER, OTRS_PASS, HOST, TRIGGERID, SEVERITY, DESCRIPTION, QUEUE, STATE, PRIORITY, CUSTOMERUSER): client = Client(OTRS_SERVER, OTRS_USER, OTRS_PASS) client.session_create() new_ticket = Ticket.create_basic(Title="Server " + HOST + " Down", Queue="" + QUEUE + "", State=u"" + STATE + "", Priority=u"" + PRIORITY + "", CustomerUser="" + CUSTOMERUSER + "") first_article = Article({ "Subject": "Server " + HOST + " Down", "Body": "Host: " + HOST + " Trigger ID: " + TRIGGERID + " Severity: " + SEVERITY + "Descricao: " + DESCRIPTION }) dynamic_field = DynamicField("TriggerID", value="" + TRIGGERID + "") client.ticket_create(new_ticket, first_article, None, dynamic_fields=[dynamic_field]) return "Ticket Build"
#!/usr/bin/env python3 import sys from pyotrs import Article, Client, DynamicField, Ticket title = "title" body = "body" client = Client(URL, USER, PASSWORD) client.session_create() new_ticket = Ticket.create_basic( Title=title, Queue="Novos tickets via telefone", State=u"new", Priority=u"Media prioridade", CustomerUser="******" ) first_article = Article({"Subject": title, "Body": body}) create_ticket = client.ticket_create(new_ticket, first_article) print(create_ticket, "Retorno função") print(create_ticket['TicketNumber']) print(type(create_ticket['TicketNumber'])) ticketnumber = create_ticket['TicketNumber'] variable = '"OTRSTICKET"'
#!/usr/bin/python2.7 from pyotrs import Client client = Client("https://suporte.qosit.com.br", "qospbx", "Qqosit-0215#") client.session_create() client.ticket_get_by_id(5764)
#!/usr/bin/env python3 import sys from pyotrs import Article, Client, DynamicField, Ticket if (len(sys.argv) == 3): title = sys.argv[1] body = sys.argv[2] client = Client("https://suporte.qosit.com.br", "qospbx", "Qqosit-0215#") client.session_create() new_ticket = Ticket.create_basic(Title=title, Queue="Novos tickets via telefone", State=u"new", Priority=u"Media prioridade", CustomerUser="******") first_article = Article({"Subject": title, "Body": body}) create_ticket = client.ticket_create(new_ticket, first_article) ticketnumber = create_ticket['TicketNumber'] else: title = " " body = " " ticketnumber = " " if (ticketnumber == " " or (title == " " and body == " ")): print(
if first_ticket: # First ticket fetched is the last created, so should set its creation time as last fetched ticket last_created = ticket['Created'] first_ticket = False demisto.incidents(incidents) if not last_created: last_created = datetime.strftime(last_run, '%Y-%m-%d %H:%M:%S') demisto.setLastRun({'time': last_created}) ''' EXECUTION CODE ''' handle_proxy(demisto.params().get('proxy')) client = Client(SERVER, USERNAME, PASSWORD, https_verify=USE_SSL) client.session_create() LOG('command is %s' % (demisto.command(), )) try: if demisto.command() == 'test-module': # Testing connectivity and credentials demisto.results('ok') elif demisto.command() == 'fetch-incidents': fetch_incidents() elif demisto.command() == 'otrs-get-ticket': get_ticket_command()
# -*- coding: utf-8 -*- from pyotrs import Article, Client, DynamicField, Ticket from datetime import datetime from datetime import timedelta client = Client( "http://192.168.0.98/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST", "adm-dsilva", "abdi@2020") #client.session_restore_or_create() print(client.session_create()) #client.ticket_get_by_id(6818180, articles=True, attachments=True, dynamic_fields=True) #print(client.ticket_search(TicketCreateTimeOlderDate=datetime(2021, 1, 20))) #print(client.ticket_search(TicketCreateTimeNewerDate=datetime.utcnow() - timedelta(days=1))) ticket_ids = client.ticket_search(States=['new', 'open'], Queues=['Raw'], OwnerIDs=[32]) print("number of my tickets:" + str(len(ticket_ids)))
from pyotrs import Client, Article, Ticket client = Client("http://172.16.1.50", "admin", "admin") client.session_create() #client.ticket_get_by_id(2, articles=True, attachments=False, dynamic_fields=False) new_ticket = Ticket.create_basic(Title="This is the Title", Queue="Junk", State=u"new", Priority=u"3 normal", CustomerUser="******") first_article = Article({"Subject": "Subj", "Body": "New Body"}) client.ticket_create(new_ticket, first_article)
# и помещаем в список tickets_1c log(f'Добавляем в tickets_1c: {row["tn"]} : {result[0]}', verbose=2) tickets_1c.append(Attr(**{'otrs': row['tn'], 'os': result[0]})) linked_tickets = {} for current_ticket in tickets_1c: if not current_ticket.os in linked_tickets: linked_tickets[current_ticket.os] = [] for other_ticket in tickets_1c: # 1c otrs if current_ticket.os == other_ticket.os and current_ticket.otrs != other_ticket.otrs: linked_tickets[current_ticket.os].append(other_ticket.otrs) client = Client(config['otrs']['uri'], config['otrs']['login'], config['otrs']['password']) if client.session_create(): logging.info("[+] Авторизация в API OTRS ОК") sleep(float(config['otrs']['operations_interval'])) # при несоблюдении интервала обращений к api апач может рвать соединение for os, link in linked_tickets.items(): dup = [] for ticket in link: if ticket not in dup: dup.append(ticket) dup.sort() else: