Ad Widget

Collapse

GLPI Webhook Mediatype not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Carlos_Castillo
    Junior Member
    • Apr 2020
    • 6

    #1

    GLPI Webhook Mediatype not working

    Hi Everyone!

    I have a problem with the GLPI webhook media type, I just enabled and set the webhook but is not working, is not creating problems in my GLPI. I'm currently using Zabbix 6.4.13 and GLPI 10.0.12 and the webhook is this: https://www.zabbix.com/la/integrations/glpi.

    This is what I see when I try to test the webhook:





    This is the log:

    Code:
    [B]Media type test log[/B]
    00:00:00.116 [Debug] [ GLPi Webhook ] Sending request: http://172.16.18.68/apirest.php/Problem/ {"input":{"name":"{ALERT.SUBJECT}","content":"{ALE RT.MESSAGE}\n<a href=http://172.16.5.10/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVEN T.ID}>Link to problem in Zabbix</a>","status":1,"urgency":"{EVENT.NSEVERITY}"}}
    00:00:00.189 [Debug] [ GLPi Webhook ] Received response with status code 200
    00:00:00.189 [Debug] [ GLPi Webhook ] Failed to parse response received from GLPi
    00:00:00.189 [Debug] [ GLPi Webhook ] ERROR: Failed to process response received from GLPi. Check debug log for more information.
  • Carlos_Castillo
    Junior Member
    • Apr 2020
    • 6

    #2
    Here is the webhook configuration:

    Click image for larger version

Name:	image.png
Views:	1582
Size:	51.6 KB
ID:	482313

    Comment

    • Carlos_Castillo
      Junior Member
      • Apr 2020
      • 6

      #3
      and this is the _log in the GLPI server:

      Click image for larger version

Name:	image.png
Views:	1580
Size:	94.7 KB
ID:	482318
      One important stuff to mention is that I'm not seeing any requests for today, is like Zabbix is not reaching GLPI side

      Comment

      • Carlos_Castillo
        Junior Member
        • Apr 2020
        • 6

        #4
        I made an update in Home / Setup / General / API Clients and set the Log Connections to "Logs" and after that I'm able to see the API calls in the logs

        Click image for larger version

Name:	image.png
Views:	1563
Size:	78.1 KB
ID:	482322

        Click image for larger version

Name:	image.png
Views:	1592
Size:	17.9 KB
ID:	482321

        Comment

        • Carlos_Castillo
          Junior Member
          • Apr 2020
          • 6

          #5
          I found the issue after checking the GLPI php-errors.log file:

          Code:
          [2024-04-15 15:01:31] glpiphplog.CRITICAL:   *** Uncaught Exception TypeError: Unsupported operand types: int << string in /var/www/html/glpi/src/CommonITILObject.php at line 2583
            Backtrace :
            src/Problem.php:298                                CommonITILObject->prepareInputForAdd()
            src/CommonDBTM.php:1297                            Problem->prepareInputForAdd()
            src/Api/API.php:1856                               CommonDBTM->add()
            src/Api/APIRest.php:317                            Glpi\Api\API->createItems()
            apirest.php:57                                     Glpi\Api\APIRest->call()
            public/index.php:82                                require()
          zz0.c5goe3sddb7zz
          The severity can't be a string, it must be an int

          Comment

          • cyber
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Dec 2006
            • 4806

            #6
            But your media type parameters contain severity as number.. {EVENT.NSEVERITY} So where the string comes from ?

            Comment

            • davbaq
              Junior Member
              • Jun 2024
              • 3

              #7
              Hello, I have the same problem, my version of GLPI is 10.0.15 and zabbix is ​7.0. When I see the GLPI logs, the error is as follows

              Click image for larger version

Name:	Captura de pantalla 2024-06-08 225005.png
Views:	1482
Size:	40.2 KB
ID:	485249
              When validating the line that mentions this is what it indicates

              if (
              !isset($input["urgency"])
              || !($CFG_GLPI['urgency_mask'] & (1 << $input["urgency"]))

              The error appears to be related to the "urgency" variable being passed as a string instead of an integer but I don't know how to solve it


              Comment

              • axis360
                Junior Member
                • Jun 2024
                • 1

                #8
                Did anyone has some progress on the said matter?
                i am stuck too at this error.
                Anyone found any solution?

                Comment

                • davbaq
                  Junior Member
                  • Jun 2024
                  • 3

                  #9
                  Validating error indicates that there is a problem with data type manipulation in the GLPI code. Specifically, you are trying to use the bit shift operator (<<) with a text string, which is not supported.

                  Solution

                  Take backup of the CommonITILObject.php file

                  Review the Code: Open the file mentioned in the error (/GLPI path /glpi/src/CommonITILObject.php) on line 2583 and review the code that causes the error.

                  Adjust the Data Type: Make sure that the variables involved in the operation are of the correct type. For example, if an integer is expected, convert the string to an integer before performing the operation.

                  Valor original
                  Click image for larger version  Name:	image.png Views:	0 Size:	8.1 KB ID:	487325

                  if (
                  !isset($input["urgency"])
                  || !($CFG_GLPI['urgency_mask'] & (1 << $input["urgency"]))
                  ) {
                  $input["urgency"] = 3;
                  }


                  Add(int) like this;

                  Click image for larger version  Name:	image.png Views:	0 Size:	8.2 KB ID:	487326

                  if (
                  !isset($input["urgency"])
                  || !($CFG_GLPI['urgency_mask'] & (1 << (int)$input["urgency"]))
                  ) {

                  Save and restart the web server service

                  With that it already worked for me



                  Click image for larger version  Name:	image.png Views:	0 Size:	64.0 KB ID:	487327

                  What Did the Original Line Do?
                  1. Existence check: !isset($input["urgency"]) checks if the urgency value is not present in the $input array.
                  2. Validity check: !($CFG_GLPI['urgency_mask'] & (1 << $input["urgency"])) checks if the urgency value is valid based on the configured urgency mask ($CFG_GLPI['urgency_mask']) . The 1 << $input["urgency"] operation shifts bit 1 to the left by the urgency value, creating a specific bit mask for that value, and then performs a bitwise AND operation with the configured urgency mask .
                  Solution

                  The error occurred because $input["urgency"] was not always an integer. The solution involves forcing the conversion of $input["urgency"] to integer before using the bit shift operator. This ensures that the operation succeeds and prevents the type error.

                  Explicitly converting $input["urgency"] to integer ((int)$input["urgency"]) ensures that the bit shift operation executes correctly, eliminating the type error and allowing urgency checking works as expected. This modification is crucial to maintain the robustness of the code when handling different types of data input.​
                  Last edited by davbaq; 11-07-2024, 23:03.

                  Comment

                  • markosa
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                    • Aug 2022
                    • 104

                    #10
                    Carlos_Castillo in your first post, there can be seen that media type sends data (event.nseverity) as string, "urgency":"{EVENT.NSEVERITY}"} as we can see that macro {EVENT.NSEVERITY} is placed within double quotes. I would fix GLPi media type script which creates post request instead of changing GLPi php.

                    Comment

                    • davbaq
                      Junior Member
                      • Jun 2024
                      • 3

                      #11
                      If you are right, by adjusting the .yaml file as follows, I was able to leave the glpi php file unchanged

                      Original

                      data = {
                      'input': {
                      'name': params.alert_subject,
                      'content': params.alert_message + '\n<a href=' + GLPi.getProblemUrl(params.zabbix_url, params.trigger_id, params.event_id, params.event_source) + '>Link to problem in Zabbix</a>',
                      'status': 1, // Set status "New"
                      'urgency': params.event_nseverity
                      }
                      };
                      response = GLPi.request('post', glpi.url + 'apirest.php/Problem/', data);

                      tight

                      data = {
                      'input': {
                      'name': params.alert_subject,
                      'content': params.alert_message + '\n<a href=' + GLPi.getProblemUrl(params.zabbix_url, params.trigger_id, params.event_id, params.event_source) + '>Link to incident in Zabbix</a>',
                      'status': 1, // Set status "New"
                      'urgency': parseInt(params.event_nseverity) // Convert urgency to integer
                      }
                      };
                      response = GLPi.request('post', glpi.url + 'apirest.php/Problem/', data);

                      Comment

                      • renatobeiriz
                        Junior Member
                        • Nov 2023
                        • 20

                        #12
                        davbaq i triyed bur the problem persist
                        Click image for larger version  Name:	glpi_005.png Views:	0 Size:	6.6 KB ID:	492090

                        Click image for larger version  Name:	glpi_006.png Views:	0 Size:	31.4 KB ID:	492091

                        Comment

                        • steven b
                          Junior Member
                          • Aug 2024
                          • 2

                          #13
                          bonjour á tous !
                          je rencontre aussi un problème toujours le type media Glpi sur ZABBIX en se moment je suis a la version 7.0.4 de ZABBIX et 10.0.6 de GLPI lorsque je configure une erreur persiste et me parle beuacoup de l'app_token manquant. ce pendant j'ai beau activer l'API restfull de GLPI , creer un client API, generer l'le jeton API d'un utilisateur GLPI le copier le coller sur le parametre glpi_token preciser les urls l'erreur reste inchanger j'ai fait des recherches mais je suis un novice dans le domaine de la programmation et pour les API je souhaite que vous eclairez ma lanterne comment devrai-je m'y prends pour que l'utilisateur GLPI que j'ai creer puisse recevoir des notification venant de zabbix. Dans le pieces jointes
                          Attached Files
                          Last edited by steven b; 10-10-2024, 12:21.

                          Comment


                          • leonardon
                            leonardon commented
                            Editing a comment
                            Hi, were you able to resolve this issue? I'm having the same problem.

                          • CLem8667
                            CLem8667 commented
                            Editing a comment
                            Bonjour,
                            J'ai le même problème, avez vous trouvez une solution depuis votre post ?
                        • osmoonlight
                          Junior Member
                          • Jul 2022
                          • 9

                          #14
                          I am having also problems with getting this to work. I just started using the ticketing function in GLPI and I would like Zabbix to create its own tickets. I followed the set-up information from the official template (Source of README.md - Zabbix - ZABBIX GIT), but I am stumbling at the last hurdle it seems.

                          Zabbix 7.4 on a Ubuntu server, GLPI 11 as docker container

                          In GLPI, enabled legacy REST API and created a API client:



                          I did not create the app_token, thus did not change the script on the Zabbix side.
                          Created a user, gave super-admin rights (just in case, to test) and created a API token. The token works, more below...

                          In Zabbix, imported the template, added the necessary information

                          The glpi_user_token is a left over from testing, but shouldn't make a difference

                          Created a Zabbix user with the GLPI media attached and attached super admin rights for testing.

                          Ran the two scripts from Zabbix:

                          curl -X POST http://10.10.11.30:8769/apirest.php/initSession -H "Content-Type: application/json" -d "{"user_token":"[redacted]"}"

                          and

                          sudo curl -X POST http://10.10.11.30:8769/apirest.php/Ticket -H "Content-Type: application/json" -H "Session-Token: [redacted]" -d '{
                          "input": {
                          "name": "Zabbix Alert: Disk Space Low",
                          "content": "Host: server01\nProblem: Disk usage over 90%\nSeverity: High",
                          "status": 1,
                          "urgency": 4,
                          "requester": 10
                          }
                          }'

                          and received the test ticket in GLPI.

                          Okay, should work. However, when a problem pops up in Zabbix, I get the ominous "Unknown INFO" error.

                          Grateful if somebody could point out my error(s) and make me a happy system admin again.


                          ​​

                          Comment

                          Working...