Ad Widget

Collapse

OTRS Integration not working ZBX 5.0.3 OTRS 6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dynux
    Junior Member
    • Aug 2020
    • 12

    #1

    OTRS Integration not working ZBX 5.0.3 OTRS 6

    Hello,

    i'm having some troubles letting the integration ZBX-OTRS working.

    I've followed the guide here https://www.zabbix.com/integrations/otrs and seems ok, but it cannot open tickets saying that something was wrong.

    Trying to test the ticket opening i receive this message:


    Code:
    00:00:00.003 [Debug] [ OTRS Webhook ] Sending request: https://****/otrs/nph-genericinterface.pl/Webservice/ZabbixTicketConnector/Ticket?UserLogin=****&Password=***** {"Ticket":{"Title":"{ALERT.SUBJECT}","Queue":"****","State":"new","PriorityID":"3","*****"},"Article":{"Su bject":"{ALERT.SUBJECT}","Body":"{ALERT.MESSAGE}", "TimeUnit":"0","ContentType":"text/plain; charset=utf8"}}
    00:00:00.394 [Debug] [ OTRS Webhook ] Received response with status code 200: {"Error":{"ErrorMessage":"TicketCreate: Ticket->TypeID or Ticket->Type parameter is required by sysconfig option!","ErrorCode":"TicketCreate.MissingParamete r"}}
    00:00:00.394 [Warning] [ OTRS Webhook ] ERROR: Cannot create OTRS ticket. Check debug log for more information.
    I looked into the zabbix's server logs without success.

    How can i investigate to understand what is wrong?

    Thank you very much.
  • Hugh
    Junior Member
    • Dec 2019
    • 3

    #2
    Hi dynux,
    I found the same issue, that guide IMO has not been properly detailed for functionality that is new and requires additional explanations.

    A workaround is:

    1) In "Administration" -> "Media type" -> "OTRS"
    2) Under "Parameters" you have to create a new field mapping for the missing "Ticket->TypeID or Ticket->Type parameter" by clicking Add

    Click image for larger version  Name:	add.png Views:	13 Size:	53.9 KB ID:	412557


    3) Fill a name like "otrs_ticket_type" with a Value according to OTRS values, (in my case "Incidente")

    Click image for larger version  Name:	fill.png Views:	13 Size:	51.6 KB ID:	412558


    4) Click on edit Script button

    Click image for larger version  Name:	edit.png Views:	13 Size:	58.0 KB ID:	412559

    Look for "createTicket: function"you will find nested:


    Ticket: {
    Title: subject,
    Queue: OTRS.params.queue,
    State: OTRS.params.ticket_state,
    PriorityID: priority || OTRS.params.default_priority_id,
    CustomerUser: OTRS.params.customer
    },

    Change it by adding the new value created in Step 3 as "Type" mapping field:

    Ticket: {
    Title: subject,
    Queue: OTRS.params.queue,
    State: OTRS.params.ticket_state,
    PriorityID: priority || OTRS.params.default_priority_id,
    CustomerUser: OTRS.params.customer,
    Type: OTRS.params.ticket_type
    },

    (pay attention to the ",")

    5) Click on "Apply" then "Update".

    Good Luck !
    Last edited by Hugh; 09-11-2020, 00:37.

    Comment

    • gumis_148
      Member
      • Jan 2019
      • 52

      #3
      Originally posted by Hugh
      Hi dynux,
      I found the same issue, that guide IMO has not been properly detailed for functionality that is new and requires additional explanations.

      A workaround is:

      1) In "Administration" -> "Media type" -> "OTRS"
      2) Under "Parameters" you have to create a new field mapping for the missing "Ticket->TypeID or Ticket->Type parameter" by clicking Add

      Click image for larger version Name:	add.png Views:	13 Size:	53.9 KB ID:	412557


      3) Fill a name like "otrs_ticket_type" with a Value according to OTRS values, (in my case "Incidente")

      Click image for larger version Name:	fill.png Views:	13 Size:	51.6 KB ID:	412558


      4) Click on edit Script button

      Click image for larger version Name:	edit.png Views:	13 Size:	58.0 KB ID:	412559

      Look for "createTicket: function"you will find nested:


      Ticket: {
      Title: subject,
      Queue: OTRS.params.queue,
      State: OTRS.params.ticket_state,
      PriorityID: priority || OTRS.params.default_priority_id,
      CustomerUser: OTRS.params.customer
      },

      Change it by adding the new value created in Step 3 as "Type" mapping field:

      Ticket: {
      Title: subject,
      Queue: OTRS.params.queue,
      State: OTRS.params.ticket_state,
      PriorityID: priority || OTRS.params.default_priority_id,
      CustomerUser: OTRS.params.customer,
      Type: OTRS.params.ticket_type
      },

      (pay attention to the ",")

      5) Click on "Apply" then "Update".

      Good Luck !
      It doesn't work for me. I added according to your recommendations but I have the same error as dynux.

      Click image for larger version

Name:	image_18192.png
Views:	2208
Size:	27.9 KB
ID:	417843

      Click image for larger version

Name:	image_18193.png
Views:	2142
Size:	5.2 KB
ID:	417844

      Click image for larger version

Name:	image_18191.png
Views:	2195
Size:	15.9 KB
ID:	417842

      Comment

      • Hugh
        Junior Member
        • Dec 2019
        • 3

        #4
        Originally posted by gumis_148

        It doesn't work for me. I added according to your recommendations but I have the same error as dynux.

        Click image for larger version

Name:	image_18192.png
Views:	2208
Size:	27.9 KB
ID:	417843

        Click image for larger version

Name:	image_18193.png
Views:	2142
Size:	5.2 KB
ID:	417844

        Click image for larger version

Name:	image_18191.png
Views:	2195
Size:	15.9 KB
ID:	417842
        Hi,
        Before all: you're not getting the same error as dynux ( "Ticket->TypeID or Ticket->Type parameter is required" ), you're having an error related to OTRS ("Failed to parse responde received from OTRS"), in fact you're getting some kind of error from OTRS not related to the quantity parameters you're sending (as dynux case was).

        Look at Admin -> Overview -> System Log for any additional info.

        Comment

        • gumis_148
          Member
          • Jan 2019
          • 52

          #5

          Hi,
          Before all: you're not getting the same error as dynux ( "Ticket->TypeID or Ticket->Type parameter is required" ), you're having an error related to OTRS ("Failed to parse responde received from OTRS"), in fact you're getting some kind of error from OTRS not related to the quantity parameters you're sending (as dynux case was).

          Look at Admin -> Overview -> System Log for any additional info.
          I have no errors in OTRS. I have the same bugs in Zabbix.

          Click image for larger version  Name:	image_18196.png Views:	4 Size:	12.9 KB ID:	417869
          Click image for larger version  Name:	image_18197.png Views:	4 Size:	49.0 KB ID:	417870
          Click image for larger version  Name:	err6.PNG Views:	2 Size:	13.8 KB ID:	417875

          EDIT: It's ok. My error. I put wrong URL OTRS (client, not admin).
          Attached Files
          Last edited by gumis_148; 01-02-2021, 22:21.

          Comment

          • zhsv
            Junior Member
            • Dec 2020
            • 14

            #6
            Hello! Same error
            [ OTRS Webhook ] ERROR: TypeError: cannot read property 'Error' of null

            I do not know what to do.

            Comment

            • gumis_148
              Member
              • Jan 2019
              • 52

              #7
              Originally posted by zhsv
              Hello! Same error
              [ OTRS Webhook ] ERROR: TypeError: cannot read property 'Error' of null

              I do not know what to do.
              Do you have correct URL OTRS? You try with this option.

              Comment

              • zhsv
                Junior Member
                • Dec 2020
                • 14

                #8
                These are the settings. There is also a required dynamic field, but I added it

                Code:
                var OTRS = {
                params: {},
                entrypoint: 'nph-genericinterface.pl/Webservice/ZabbixTicketConnector/Ticket',
                
                setParams: function (params) {
                if (typeof params !== 'object') {
                return;
                }
                
                OTRS.params = params;
                if (typeof OTRS.params.url === 'string') {
                if (!OTRS.params.url.endsWith('/')) {
                OTRS.params.url += '/';
                }
                }
                },
                
                addDynamicFields: function (data, fields) {
                if (typeof fields === 'object' && Object.keys(fields).length) {
                data.DynamicField = [];
                
                Object.keys(fields)
                .forEach(function(field) {
                if (field !== undefined) {
                if (fields[field].match(/^\d{4}[.-]\d{2}[.-]\d{2}$/)) {
                fields[field] = fields[field].replace(/\./g, '-');
                }
                
                data.DynamicField.push({Name: field, Value: fields[field]});
                }
                });
                }
                
                return data;
                },
                
                request: function (method, query, data) {
                ['url', 'auth_user', 'auth_password', 'queue',
                'customer', 'ticket_state', 'default_priority_id', 'time_unit'].forEach(function (field) {
                if (typeof OTRS.params !== 'object' || typeof OTRS.params[field] === 'undefined'
                || OTRS.params[field] === '' ) {
                throw 'Required param is not set: "' + field + '".';
                }
                });
                
                var response,
                request = new CurlHttpRequest(),
                url = OTRS.params.url + query +
                '?UserLogin=' + encodeURIComponent(OTRS.params.auth_user) +
                '&Password=' + encodeURIComponent(OTRS.params.auth_password);
                
                if (typeof OTRS.HTTPProxy !== 'undefined' && OTRS.HTTPProxy.trim() !== '') {
                request.SetProxy(OTRS.HTTPProxy);
                }
                
                request.AddHeader('Content-Type: application/json');
                
                if (typeof data !== 'undefined') {
                data = JSON.stringify(data);
                }
                
                Zabbix.Log(4, '[ OTRS Webhook ] Sending request: ' +
                url + ((typeof data === 'string') ? (' ' + data) : ''));
                
                switch (method) {
                case 'get':
                response = request.Get(url, data);
                break;
                
                case 'post':
                response = request.Post(url, data);
                break;
                
                case 'put':
                response = request.Put(url, data);
                break;
                
                default:
                throw 'Unsupported HTTP request method: ' + method;
                }
                
                Zabbix.Log(4, '[ OTRS Webhook ] Received response with status code ' + request.Status() + ': ' + response);
                
                if (request.Status() < 200 || request.Status() >= 300) {
                var message = 'Request failed with status code ' + request.Status();
                
                message += ': ' + response;
                throw message + ' Check debug log for more information.';
                }
                
                if (response !== null) {
                try {
                response = JSON.parse(response);
                }
                catch (error) {
                Zabbix.Log(4, '[ OTRS Webhook ] Failed to parse response received from OTRS');
                response = null;
                }
                }
                
                if (typeof response.Error !== 'undefined'
                && Object.keys(response.Error).length > 0) {
                message = 'Request failed: ' + JSON.stringify(response.Error);
                }
                
                
                return {
                status: request.Status(),
                response: response
                };
                },
                
                createTicket: function(subject, message, priority, fields) {
                var result,
                data = {
                Ticket: {
                Title: subject,
                Queue: OTRS.params.queue,
                State: OTRS.params.ticket_state,
                PriorityID: priority || OTRS.params.default_priority_id,
                CustomerUser: OTRS.params.customer,
                
                DynamicField: OTRS.params.dynamicfield_FIO
                },
                Article: {
                Subject: subject,
                Body: message,
                TimeUnit: OTRS.params.time_unit,
                ContentType: 'text/plain; charset=utf8'
                }
                };
                
                result = OTRS.request('post', OTRS.entrypoint, OTRS.addDynamicFields(data, fields));
                
                if (typeof result.response !== 'object'
                || typeof result.response.TicketID === 'undefined'
                || result.status != 200) {
                throw 'Cannot create OTRS ticket. Check debug log for more information.';
                }
                
                return result.response.TicketID;
                },
                
                updateTicket: function(subject, message) {
                var result,
                data = {
                Article: {
                Subject: subject,
                Body: message || '',
                TimeUnit: OTRS.params.time_unit,
                ContentType: 'text/plain; charset=utf8'
                }
                };
                
                result = OTRS.request('put', OTRS.entrypoint + '/' + encodeURIComponent(OTRS.params.ticket_id), data);
                
                if (typeof result.response !== 'object'
                || typeof result.response.TicketID === 'undefined'
                || result.status != 200) {
                throw 'Cannot update OTRS ticket. Check debug log for more information.';
                }
                }
                };
                
                try {
                var params = JSON.parse(value),
                params_otrs = {},
                params_fields = {},
                params_update = {},
                result = {tags: {}},
                required_params = [
                'alert_subject', 'event_source',
                'event_value', 'event_update_status'
                ],
                severities = [
                {name: 'not_classified', color: '#97AAB3'},
                {name: 'information', color: '#7499FF'},
                {name: 'warning', color: '#FFC859'},
                {name: 'average', color: '#FFA059'},
                {name: 'high', color: '#E97659'},
                {name: 'disaster', color: '#E45959'},
                {name: 'resolved', color: '#009900'},
                {name: null, color: '#000000'}
                ],
                priority;
                
                Object.keys(params)
                .forEach(function (key) {
                if (key.startsWith('otrs_')) {
                params_otrs[key.substring(5)] = params[key];
                }
                else if (key.startsWith('dynamicfield_')) {
                params_fields[key.substring(13)] = params[key];
                }
                else if (key.startsWith('event_update_')) {
                params_update[key.substring(13)] = params[key];
                }
                else if (required_params.indexOf(key) !== -1 && params[key].trim() === '') {
                throw 'Parameter "' + key + '" cannot be empty.';
                }
                });
                
                if ([0, 1, 2, 3].indexOf(parseInt(params.event_source)) === -1) {
                throw 'Incorrect "event_source" parameter given: ' + params.event_source + '\nMust be 0-3.';
                }
                
                // Check {EVENT.VALUE} for trigger-based and internal events.
                if (params.event_value !== '0' && params.event_value !== '1'
                && (params.event_source === '0' || params.event_source === '3')) {
                throw 'Incorrect "event_value" parameter given: ' + params.event_value + '\nMust be 0 or 1.';
                }
                
                // Check {EVENT.UPDATE.STATUS} only for trigger-based events.
                if (params.event_source === '0' && params.event_update_status !== '0' && params.event_update_status !== '1') {
                throw 'Incorrect "event_update_status" parameter given: ' + params.event_update_status + '\nMust be 0 or 1.';
                }
                
                if (params.event_source !== '0' && params.event_value === '0') {
                throw 'Recovery operations are supported only for trigger-based actions.';
                }
                
                if (params.event_source === '0'
                && ((params.event_value === '1' && params.event_update_status === '1')
                || (params.event_value === '0'
                && (params.event_update_status === '0' || params.event_update_status === '1')))
                && (isNaN(parseInt(params.otrs_ticket_id)) || parseInt(params.otrs_ticket_id) < 1 )) {
                throw 'Incorrect "otrs_ticket_id" parameter given: ' + params.otrs_ticket_id +
                '\nMust be positive integer.';
                }
                
                if ([0, 1, 2, 3, 4, 5].indexOf(parseInt(params.event_nseverity)) === -1) {
                params.event_nseverity = '7';
                }
                
                if (params.event_value === '0') {
                params.event_nseverity = '6';
                }
                
                priority = params['severity_' + severities[params.event_nseverity].name];
                priority = priority && priority.trim() || severities[7].name;
                
                OTRS.setParams(params_otrs);
                OTRS.HTTPProxy = params.HTTPProxy;
                
                // Create ticket for non trigger-based events.
                if (params.event_source !== '0'
                && params.event_value !== '0') {
                OTRS.createTicket(params.alert_subject, params.alert_message, priority);
                }
                // Create ticket for trigger-based events.
                else if (params.event_value === '1' && params_update.status === '0') {
                var ticket_id = OTRS.createTicket(params.alert_subject,
                params.alert_subject + '\n' + params.alert_message + '\n' +
                params.zabbix_url + (params.zabbix_url.endsWith('/') ? '' : '/') +
                'tr_events.php?triggerid=' + params.trigger_id + '&eventid=' + params.event_id + '\n',
                priority,
                params_fields);
                
                result.tags.__zbx_otrs_ticket_id = ticket_id;
                result.tags.__zbx_otrs_ticketlink = params.otrs_url +
                (params.otrs_url.endsWith('/') ? '' : '/') + 'index.pl?Action=AgentTicketZoom;TicketID=' + ticket_id;
                }
                // Update created ticket for trigger-based event.
                else {
                OTRS.updateTicket(params.alert_subject, params.alert_message);
                }
                
                return JSON.stringify(result);
                }
                catch (error) {
                Zabbix.Log(3, '[ OTRS Webhook ] ERROR: ' + error);
                throw 'Sending failed: ' + error;
                }
                Attached Files

                Comment

                • zhsv
                  Junior Member
                  • Dec 2020
                  • 14

                  #9
                  For the test: is it possible to create a request through a string by pasting it into a web browser?


                  Sending request: http://10.0.80.30/otrs/customer.pl/n...assword=zabbix {"Ticket":{"Title":"1","Queue":"1","State":"1", "Pr iorityID":"1","CustomerUser":"[email protected]"},"A rticle":{"Subject":"1","Body":"1","TimeUnit":"0"," ContentType":"text/plain; charset=utf8"}}

                  Comment

                  • dynux
                    Junior Member
                    • Aug 2020
                    • 12

                    #10
                    Originally posted by Hugh
                    Hi dynux,
                    I found the same issue, that guide IMO has not been properly detailed for functionality that is new and requires additional explanations.

                    A workaround is:

                    1) In "Administration" -> "Media type" -> "OTRS"
                    2) Under "Parameters" you have to create a new field mapping for the missing "Ticket->TypeID or Ticket->Type parameter" by clicking Add

                    Click image for larger version Name:	add.png Views:	13 Size:	53.9 KB ID:	412557


                    3) Fill a name like "otrs_ticket_type" with a Value according to OTRS values, (in my case "Incidente")

                    Click image for larger version Name:	fill.png Views:	13 Size:	51.6 KB ID:	412558


                    4) Click on edit Script button

                    Click image for larger version Name:	edit.png Views:	13 Size:	58.0 KB ID:	412559

                    Look for "createTicket: function"you will find nested:


                    Ticket: {
                    Title: subject,
                    Queue: OTRS.params.queue,
                    State: OTRS.params.ticket_state,
                    PriorityID: priority || OTRS.params.default_priority_id,
                    CustomerUser: OTRS.params.customer
                    },

                    Change it by adding the new value created in Step 3 as "Type" mapping field:

                    Ticket: {
                    Title: subject,
                    Queue: OTRS.params.queue,
                    State: OTRS.params.ticket_state,
                    PriorityID: priority || OTRS.params.default_priority_id,
                    CustomerUser: OTRS.params.customer,
                    Type: OTRS.params.ticket_type
                    },

                    (pay attention to the ",")

                    5) Click on "Apply" then "Update".

                    Good Luck !
                    Hello, suddendly my otrs integrations is giving this error:
                    Code:
                    00:00:00.000 [Debug] [ OTRS Webhook ] Sending request: https://tickets.mysite.com/otrs/nph-genericinterface.pl/Webservice/ZabbixTicketConnector/Ticket?UserLogin=mysuer&Password=mypèassword 4LB {"Ticket":{"Title":"{ALERT.SUBJECT}","Queue":"customer_coda","State":"new","PriorityID":"3","Customer User":"user","Type":"Problem"}," Article":{"Subject":"{ALERT.SUBJECT}","Body":"{ALE RT.MESSAGE}","TimeUnit":"0","ContentType":"text/plain; charset=utf8"}}
                    00:00:00.740 [Debug] [ OTRS Webhook ] Received response with status code 200: HTTP/2.0 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 74 Connection: close {"ArticleID":651031,"TicketNumber":"20210412340011 25","TicketID":"540198"}
                    00:00:00.740 [Debug] [ OTRS Webhook ] Failed to parse response received from OTRS
                    00:00:00.740 [Warning] [ OTRS Webhook ] ERROR: TypeError: cannot read property 'Error' of null
                    nothing is changed and i cannot face whats happening.

                    Can you help me find the reason?

                    Thank you.

                    Comment

                    • judsonab
                      Junior Member
                      • Jun 2021
                      • 1

                      #11
                      Hello, this webhook does not close a ticket on OTRS after a zabbix event gets status OK?

                      Comment

                      • joaop_pimenta
                        Junior Member
                        • Feb 2022
                        • 3

                        #12
                        Hi,
                        Is there any way to close the ticket? after alarm stop

                        Comment

                        • dynux
                          Junior Member
                          • Aug 2020
                          • 12

                          #13
                          Originally posted by dynux

                          Hello, suddendly my otrs integrations is giving this error:
                          Code:
                          00:00:00.000 [Debug] [ OTRS Webhook ] Sending request: https://tickets.mysite.com/otrs/nph-genericinterface.pl/Webservice/ZabbixTicketConnector/Ticket?UserLogin=mysuer&Password=mypèassword 4LB {"Ticket":{"Title":"{ALERT.SUBJECT}","Queue":"customer_coda","State":"new","PriorityID":"3","Customer User":"user","Type":"Problem"}," Article":{"Subject":"{ALERT.SUBJECT}","Body":"{ALE RT.MESSAGE}","TimeUnit":"0","ContentType":"text/plain; charset=utf8"}}
                          00:00:00.740 [Debug] [ OTRS Webhook ] Received response with status code 200: HTTP/2.0 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 74 Connection: close {"ArticleID":651031,"TicketNumber":"20210412340011 25","TicketID":"540198"}
                          00:00:00.740 [Debug] [ OTRS Webhook ] Failed to parse response received from OTRS
                          00:00:00.740 [Warning] [ OTRS Webhook ] ERROR: TypeError: cannot read property 'Error' of null
                          nothing is changed and i cannot face whats happening.

                          Can you help me find the reason?

                          Thank you.
                          The problem with this is that Zabbix 5.0.14 fails to parse the response because of HTTP/2.0 (maybe the "/" is not properly escaped?).

                          Turning back on HTTP/1.1 solves the problem.

                          Has this been resolved in the future releases?

                          Comment

                          • notify.teamapp
                            Junior Member
                            • May 2024
                            • 1

                            #14
                            Hi Guys,

                            Same Error for me also Zabbix version :6.4 and Otrs Version:6.0.1

                            When testing web hook its shows error.

                            Kindly help to resolve the issue


                            Click image for larger version

Name:	log.png
Views:	449
Size:	7.5 KB
ID:	483892

                            Click image for larger version

Name:	Error.png
Views:	447
Size:	38.5 KB
ID:	483893
                            Attached Files

                            Comment

                            Working...