def test_ticket_update_attrs_by_number(self): t = Ticket(State='new', Priority='3 normal', Queue='Postmaster', Title='Problem test', CustomerUser='******', Type='Unclassified') a = Article(Subject='UnitTest', Body='bla', Charset='UTF8', MimeType='text/plain') t_id, t_number = self.c.tc.TicketCreate(t, a) t = Ticket(Title='Foubar') upd_tid, upd_tnumber = self.c.tc.TicketUpdate( ticket_number=t_number, ticket=t) self.assertIsInstance(upd_tid, int) self.assertIsInstance(upd_tnumber, int) self.assertTrue(len(str(upd_tnumber)) >= 12) self.assertEqual(upd_tid, t_id) self.assertEqual(upd_tnumber, t_number) upd_t = self.c.tc.TicketGet(t_id) self.assertEqual(upd_t.Title, 'Foubar') self.assertEqual(upd_t.Queue, 'Postmaster')
def test_ticket_to_xml(self): t = Ticket(State='open', Priority='3 normal', Queue='Postmaster') xml = t.to_xml() xml_childs = xml.getchildren() xml_childs_dict = {i.tag: i.text for i in xml_childs} self.assertEqual(xml.tag, 'Ticket') self.assertEqual(len(xml_childs), 3) self.assertEqual(xml_childs_dict['State'], 'open') self.assertEqual(xml_childs_dict['Priority'], '3 normal') self.assertEqual(xml_childs_dict['Queue'], 'Postmaster')
def abrirTicket(): corpo = sys.argv[3] + " " + sys.argv[4] evento = sys.argv[4] t = Ticket(State='new', Priority='3 normal', Queue='Zabbix', Title=sys.argv[1], CustomerUser='******', Type='Unclassified') a = Article(Subject=sys.argv[2], Body=corpo, Charset='UTF8', MimeType='text/plain') df1 = DynamicField(Name='ZabbixIdTrigger', Value=sys.argv[5]) df2 = DynamicField(Name='ZabbixStateTrigger', Value=sys.argv[6]) df3 = DynamicField(Name='ZabbixEvento', Value=sys.argv[4]) ticket_id, numero_ticket = client.tc.TicketCreate(t, a, [df1, df2, df3]) comando = "python /usr/lib/zabbix/externalscripts/ack_zabbix.py " + str( evento) + " " + str(numero_ticket) os.system(comando)
def __call__(self, ticket_id, get_articles=False, get_dynamic_fields=False, get_attachments=False, *args, **kwargs): """Get a ticket by id ; beware, TicketID != TicketNumber. @param ticket_id : the TicketID of the ticket @param get_articles : grab articles linked to the ticket @param get_dynamic_fields : include dynamic fields in result @param get_attachments : include attachments in result @return a `Ticket`, Ticket.articles() will give articles if relevant. Ticket.articles()[i].attachments() will return the attachments for an article, wheres Ticket.articles()[i].save_attachments(<folderpath>) will save the attachments of article[i] to the specified folder. """ params = {'TicketID': str(ticket_id)} params.update(kwargs) if get_articles: params['AllArticles'] = True if get_dynamic_fields: params['DynamicFields'] = True if get_attachments: params['Attachments'] = True ret = self.req('TicketGet', **params) return TicketObject.from_xml(self._unpack_resp_one(ret))
def test_ticket_update_new_article(self): t = Ticket(State='new', Priority='3 normal', Queue='Postmaster', Title='Problem test', CustomerUser='******', Type='Unclassified') a = Article(Subject='UnitTest', Body='bla', Charset='UTF8', MimeType='text/plain') t_id, t_number = self.c.tc.TicketCreate(t, a) a2 = Article(Subject='UnitTest2', Body='bla', Charset='UTF8', MimeType='text/plain') a3 = Article(Subject='UnitTest3', Body='bla', Charset='UTF8', MimeType='text/plain') self.c.tc.TicketUpdate(t_id, article=a2) self.c.tc.TicketUpdate(t_id, article=a3) t_upd = self.c.tc.TicketGet(t_id, get_articles=True) arts_upd = t_upd.articles() self.assertIsInstance(arts_upd, list) self.assertEqual(len(arts_upd), 3) self.assertEqual(arts_upd[0].Subject, 'UnitTest') self.assertEqual(arts_upd[1].Subject, 'UnitTest2') self.assertEqual(arts_upd[2].Subject, 'UnitTest3')
def abrirTicket(): corpo = sys.argv[3] + " " + sys.argv[4] evento = sys.argv[4] t = Ticket(State='new', Priority='3 normal', Queue='Zabbix', Title=sys.argv[1], CustomerUser='******', Type='Unclassified') a = Article(Subject=sys.argv[2], Body=corpo, Charset='UTF8', MimeType='text/plain') df1 = DynamicField(Name='ZabbixIdTrigger', Value=sys.argv[5]) df2 = DynamicField(Name='ZabbixStateTrigger', Value=sys.argv[6]) df3 = DynamicField(Name='ZabbixEvento', Value=sys.argv[4]) ticket_id, numero_ticket = client.tc.TicketCreate(t, a, [df1, df2, df3]) conexao.event.acknowledge({ "eventids": evento, "action": 2, "message": "O ticket Nº " + str(numero_ticket) + " foi criado com sucesso no OTRS." }) conexao.event.acknowledge({ "eventids": evento, "action": 4, "message": "O ticket Nº " + str(numero_ticket) + " foi criado com sucesso no OTRS." })
def test_ticket_from_xml_with_articles(self): xml = etree.fromstring(SAMPLE_TICKET_W_ARTICLES) t = Ticket.from_xml(xml) self.assertEqual(t.TicketID, 32) self.assertEqual(t.CustomerUserID, '*****@*****.**') articles = t.articles() self.assertIsInstance(articles, list) self.assertEqual(len(articles), 1) self.assertIsInstance(articles[0], Article) self.assertEqual(articles[0].AgeTimeUnix, 863982)
def open_ticket(title, body, typeid, queue, eventid, client): t = Ticket(State='open', Priority='3 normal', Queue=queue, Title=title, CustomerUser='******', TypeID=typeid) a = Article(Subject=title, Body=body, Charset='UTF8', MimeType='text/plain') df1 = DynamicField(Name='EventID', Value=eventid) t_id, t_number = client.tc.TicketCreate(t, a, [df1])
def test_ticket_create(self): t = Ticket(State='new', Priority='3 normal', Queue='Postmaster', Title='Problem test', CustomerUser='******', Type='Unclassified') a = Article(Subject='UnitTest', Body='bla', Charset='UTF8', MimeType='text/plain') t_id, t_number = self.c.tc.TicketCreate(t, a) self.assertIsInstance(t_id, int) self.assertIsInstance(t_number, int) self.assertTrue(len(str(t_number)) >= 12) exit
def createTicket(cliente, titulo, asunto, cuerpo, responsable): import mimetypes import base64 priorities = ['1 very low', '2 low', '3 normal', '4 high', '5 very high'] prior = random.choice(priorities) print prior lock = ['lock', 'unlock'] bloqueado = random.choice(lock) print bloqueado states = [ 'new', 'open', 'closed successful', 'closed unsuccessful', 'merged', 'pending auto close+', 'pending auto close-', 'pending reminder', 'removed' ] state = random.choice(states) print state t = Ticket(State=state, Priority=prior, Queue='Postmaster', Title=titulo, CustomerUser='******', Responsible=responsable, Lock=bloqueado) a = Article(NoAgentNotify=1, Subject=asunto, Body=cuerpo, Charset='UTF8', MimeType='text/plain', SenderType='customer', ArticleType='email-external', From='*****@*****.**', To=responsable) print cliente.tc.TicketCreate(t, a) print "Ticket Creado"
parser.add_argument('--triggerid', dest='triggerid', help='Trigger ID do zabbix') parser.add_argument('--host', dest='host', help='Nome do host no zabbix') parser.add_argument('--status', dest='status', help='Indisponibilidade') args = parser.parse_args() #print(args) # Conexao com o OTRS server_uri = 'http://'+args.server+'/' webservice_name = args.webservice client = GenericInterfaceClient(server_uri, tc=GenericTicketConnectorSOAP(webservice_name)) client.tc.SessionCreate(user_login=args.user, password=args.password) #Criando o ticket t = Ticket(State='Aberto', Priority='3 normal', Queue=args.fila, Title=args.title.decode('UTF8'), CustomerUser=args.customer, Type='Incidente', Service=args.servico, SLA=args.sla) a = Article(Subject=args.title.decode('UTF8'), Body=args.descricao.decode('UTF8'), Charset='UTF8', MimeType='text/plain') t_id, t_number = client.tc.TicketCreate(t, a, None, None) print('Ticket criado: '+str(t_number)) print('Ticket criado: '+str(t_number)+'::'+args.title) # Ticket em atendimento t_upd = Ticket(State='Aberto') new_article = Article(Subject='Em atendimento', Body='Analisando o incidente.', Charset='UTF8', MimeType='text/plain') client.tc.TicketUpdate(t_id, ticket=t_upd,article=new_article, attachments=None)
def close_ticket(eventid, client): ticket = search_ticket(eventid, client) t_upd = Ticket(State='closed successful') client.tc.TicketUpdate(ticket, ticket=t_upd)
# Versao: 1.0 # ############################################################### from otrs.ticket.template import GenericTicketConnectorSOAP from otrs.client import GenericInterfaceClient from otrs.ticket.objects import Ticket, Article, DynamicField, Attachment import sys, os server_uri = 'http://127.0.0.1' # IP do servidor web do OTRS webservice_name = 'IntegraZabbix' # Nome do webservice importado no OTRS client = GenericInterfaceClient(server_uri, tc=GenericTicketConnectorSOAP(webservice_name)) client.tc.SessionCreate(user_login='******', password='******') fechar_ticket = Ticket(State='fechado automaticamente') assunto_artigo_fechado = "Ticket fechado automaticamente atraves do evento " + sys.argv[ 4] estado_trigger = sys.argv[6] artigo_fechar = Article(Subject=assunto_artigo_fechado, Body=assunto_artigo_fechado, Charset='UTF8', MimeType='text/plain') def abrirTicket(): corpo = sys.argv[3] + " " + sys.argv[4] evento = sys.argv[4] t = Ticket(State='new',
def test_ticket_from_xml(self): xml = etree.fromstring(SAMPLE_TICKET) t = Ticket.from_xml(xml) self.assertEqual(t.TicketID, 32) self.assertEqual(t.CustomerUserID, '*****@*****.**')
def test_ticket(self): t = Ticket(TicketID=42, EscalationResponseTime='43') self.assertEqual(t.TicketID, 42) self.assertEqual(t.EscalationResponseTime, 43)