Esempio n. 1
0
def access_otrs(user, passwd):
    server_uri = r'http://192.168.0.193'
    webservice_name = 'GenericTicketConnectorSOAP'
    client = GenericInterfaceClient(
        server_uri, tc=GenericTicketConnectorSOAP(webservice_name))
    client.tc.SessionCreate(user_login=user, password=passwd)
    return client
Esempio n. 2
0
def initSession(user, passwd):
    server_uri = r'http://localhost/otrs/nph-genericinterface.pl'
    webservice_name = 'GenericTicketConnectorSOAP'
    client = GenericInterfaceClient(
        server_uri, tc=GenericTicketConnectorSOAP(webservice_name))

    client.tc.SessionCreate(user_login=user, password=passwd)

    return client
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     try:
         self.client = GenericInterfaceClient(
             self.get_config('OTRS', 'Url'),
             tc=GenericTicketConnectorSOAP(
                 self.get_config('OTRS', 'Webservice')))
         self.client.tc.SessionCreate(
             user_login=self.get_config('OTRS', 'User'),
             password=self.get_config('OTRS', 'Password'))
     except Exception as exc:
         self.logger.error('Unable to init a Notifier {}'.format(exc))
         quit(1)
Esempio n. 4
0
def otrs(update, context):
    # type: (Update, CallbackContext) -> None

    from otrs.ticket.template import GenericTicketConnectorSOAP
    from otrs.client import GenericInterfaceClient
    from otrs.ticket.objects import Ticket, Article, DynamicField, Attachment

    otrs_settings = context.user_data.get('otrs', {})
    otrs_address = otrs_settings.get('address', None)
    otrs_username = otrs_settings.get('username', None)
    otrs_password = otrs_settings.get('password', None)
    webservice_name = 'GenericTicketConnectorSOAP'

    if otrs_address and otrs_username and otrs_password:
        client = GenericInterfaceClient(otrs_address, tc=GenericTicketConnectorSOAP(webservice_name))
        client.tc.SessionCreate(user_login=otrs_username, password=otrs_password)

        issues = [int(i) for i in ','.join(context.args).split(',') if i.isdigit()]
        message = ''
        for i in issues:
            try:
                ticket = client.tc.TicketGet(i, get_articles=True, get_dynamic_fields=True, get_attachments=False)
                title = ticket.attrs.get('Title', '-')
                state = ticket.attrs.get('State', '-')
                plan_time_str = ticket.attrs.get('DynamicField_Plantime', None)
                plan_time = int(plan_time_str) if plan_time_str is not None else None
                formatted_time = format_time(m=plan_time)
                message += '**' + md2_prepare(f'#{i}: {title}') + '**\n'
                message += md2_prepare(f'[{state}] ({formatted_time})\n')
                for article in ticket.articles():
                    subject = article.attrs.get('Subject', '-')
                    # I use subject template `(Ф:0+30) comment`
                    # for adding internal note/article about spent time
                    if article.attrs.get('ArticleType') == 'note-internal' \
                            and subject.startswith('('):
                        created = article.attrs.get('Created', '-')
                        from_user = article.attrs.get('FromRealname', '-')
                        message += md2_prepare(f' - {created} ({from_user}): {subject}\n')
                message += '\n'
            except Exception as e:
                message += md2_prepare(f'#{i}: {e}')
        update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN_V2)
    else:
        otrs_auth(update, context)
Esempio n. 5
0
parser.add_argument('--title', dest='title', help='Titulo do chamado')
parser.add_argument('--desc', dest='descricao', help='Descricao')
parser.add_argument('--fila', dest='fila', help='Fila de atendimento')
parser.add_argument('--servico', dest='servico', help='Servico de abertura')
parser.add_argument('--sla', dest='sla', help='SLA')
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')
Esempio n. 6
0
 def setUp(self):
     self.c = GenericInterfaceClient(
         OTRS_SERVER, tc=GenericTicketConnectorSOAP(OTRS_WEBSERVICE))
     self.c.register_credentials(OTRS_LOGIN, OTRS_PASSWORD)
Esempio n. 7
0
    class TestOTRSAPI(unittest.TestCase):
        def setUp(self):
            self.c = GenericInterfaceClient(
                OTRS_SERVER, tc=GenericTicketConnectorSOAP(OTRS_WEBSERVICE))
            self.c.register_credentials(OTRS_LOGIN, OTRS_PASSWORD)

        def test_session_create(self):
            sessid = self.c.tc.SessionCreate(user_login=OTRS_LOGIN,
                                             password=OTRS_PASSWORD)
            self.assertEqual(len(sessid), 32)

        def test_ticket_get(self):
            t = self.c.tc.TicketGet(1)
            self.assertEqual(t.TicketID, 1)
            self.assertEqual(t.StateType, 'new')

        def test_ticket_get_with_articles(self):
            t = self.c.tc.TicketGet(1, get_articles=True)
            self.assertEqual(t.TicketID, 1)
            self.assertEqual(t.StateType, 'new')
            articles = t.articles()
            self.assertIsInstance(articles, (list, tuple))
            self.assertIsInstance(articles[0], Article)
            self.assertEqual(articles[0].SenderType, 'customer')

        def test_ticket_search(self):
            t_list = self.c.tc.TicketSearch(Title='Welcome to OTRS!')
            self.assertIsInstance(t_list, list)
            self.assertIn(1, t_list)

        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 test_ticket_update_attrs_by_id(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_id=t_id,
                                                          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_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_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')
Esempio n. 8
0
 def setUp(self):
     self.c = GenericInterfaceClient(OTRS_SERVER, tc=GenericTicketConnectorSOAP(OTRS_WEBSERVICE))
     self.c.register_credentials(OTRS_LOGIN, OTRS_PASSWORD)
Esempio n. 9
0
    class TestOTRSAPI(unittest.TestCase):
        def setUp(self):
            self.c = GenericInterfaceClient(OTRS_SERVER, tc=GenericTicketConnectorSOAP(OTRS_WEBSERVICE))
            self.c.register_credentials(OTRS_LOGIN, OTRS_PASSWORD)

        def test_session_create(self):
            sessid = self.c.tc.SessionCreate(user_login=OTRS_LOGIN,
                                             password=OTRS_PASSWORD)
            self.assertEqual(len(sessid), 32)

        def test_ticket_get(self):
            t = self.c.tc.TicketGet(1)
            self.assertEqual(t.TicketID, 1)
            self.assertEqual(t.StateType, 'new')

        def test_ticket_get_with_articles(self):
            t = self.c.tc.TicketGet(1, get_articles=True)
            self.assertEqual(t.TicketID, 1)
            self.assertEqual(t.StateType, 'new')
            articles = t.articles()
            self.assertIsInstance(articles, (list, tuple))
            self.assertIsInstance(articles[0], Article)
            self.assertEqual(articles[0].SenderType, 'customer')

        def test_ticket_search(self):
            t_list = self.c.tc.TicketSearch(Title='Welcome to OTRS!')
            self.assertIsInstance(t_list, list)
            self.assertIn(1, t_list)

        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 test_ticket_update_attrs_by_id(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_id=t_id,
                                                          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_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_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')