Example #1
0
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 {}
Example #2
0
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
Example #3
0
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)
Example #4
0
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"'
Example #6
0
# -*- 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)))