Ad Widget

Collapse

Webhook GLPI - ERROR_SESSION_TOKEN_MISSING

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • keat
    Junior Member
    • Apr 2023
    • 4

    #1

    Webhook GLPI - ERROR_SESSION_TOKEN_MISSING

    OS : Debian 11 Bullseye
    Zabbix : v6.2
    GLPI : v10

    Hi,
    i'm trying to setup GLPI webhook to create a new "problem" based on the default "GLPi" media type.
    When I test it, i got a error from GPLI API (see screenshot).
    Click image for larger version

Name:	image.png
Views:	1988
Size:	11.7 KB
ID:	463346

    What I understand :
    • Webhook authenticate correctly using the API token that i provided
    • Then, webhook send a request to GLPI server with an empty 'Session-Token'

    It seems Zabbix can connect to GLPI because I receive a response.

    I thought the problem was on GLPI side so i checked and cURL.
    When i send a request, I get a SSL certificate error. It's because GLPI certificate is signed using my own root CA.
    I tried passing the root CA using --cacert cURL option and it works. Same using --insecure option.

    I added my root CA in /usr/share/ca-certificates and did a 'sudo apt update-ca-certificates'. Nothing
    I added my root CA in /etc/ssl/certs/. Same

    I don't know if the issue is the root CA because it seems GLPI server respond to webhook's requests.
    Nothing in the logs on both side.

    Anyone knows which service is executing webhooks ?
    Which path is Zabbix reading root CA files from ?

    Thanks​
    Attached Files
  • Answer selected by keat at 10-05-2023, 18:08.
    keat
    Junior Member
    • Apr 2023
    • 4

    I couldn't figure how to use the default webhook so I wrote mine from scratch using the following documentation :
    Zabbix JS Preprocessing : https://www.zabbix.com/documentation...ing/javascript
    Objects, methods supported by JS Duktape : https://www.zabbix.com/documentation...script_objects

    My script only allow me to create a new ticket on alert trigger. It is crappy but I share it in case it can help someone.

    Code:
    // Script Engine : Duktape
    // Parse value from Zabbix params
    params = JSON.parse(value),
    
    AUTH_TOKEN = params.auth_token
    GLPI_URL = params.glpi_url
    TITLE = params.alert_subject
    MESSAGE = params.alert_message
    URGENCY = params.event_nseverity
    
    function getAuthToken(url, auth_token) {
    
    auth_header = 'Authorization: user_token ' + auth_token
    
    // Embbed cURL
    request = new HttpRequest()
    request.addHeader('Content-Type: application/json');
    request.addHeader(auth_header);
    
    response = request.get(url + 'apirest.php/initSession/');
    response = JSON.parse(response)
    
    // Return only data from key "session_token"
    return response.session_token
    }
    
    // Create a ticket
    try {
    SESSION_TOKEN = getAuthToken(GLPI_URL, AUTH_TOKEN)
    
    // Request body
    ticket_data = {
    'input': {
    'name': TITLE,
    'requesttypes_id': 7, // Modify the "demand source"
    'status': 1, // Set status "New"
    'content': MESSAGE,
    'entities_id': 0, // Set to root entity
    'urgency': URGENCY
    }
    };
    
    glpi_ticket_url = GLPI_URL + "apirest.php/Ticket/"
    
    request = new HttpRequest()
    
    request.addHeader('Content-Type: application/json');
    request.addHeader('Session-Token: ' + SESSION_TOKEN);
    
    
    // Send POST request.
    // Data has to be converted from Object to JSON using JSON.stringify().
    response = request.post(glpi_ticket_url, JSON.stringify(ticket_data));
    
    Zabbix.log(4, '[ GLPI Webhook ] Result: ' + JSON.stringify(response));
    return JSON.stringify(response);
    
    }
    catch (error) {
    Zabbix.log(4, '[ GLPI Webhook ] ERROR: ' + error);
    
    throw 'Sending failed: ' + error + ' data :' + JSON.stringify(ticket_data);
    }
    The media type I created :
    Click image for larger version

Name:	image.png
Views:	2059
Size:	42.1 KB
ID:	464266

    Message template is the default "Problem" one ​.​

    Comment

    • Telmo Marques
      Junior Member
      • Apr 2023
      • 17

      #2
      I am with the same problem! Before yesterday everything was okay and today the zabbix can't connect to glpi...and i don't know why

      Comment

      • Telmo Marques
        Junior Member
        • Apr 2023
        • 17

        #3
        i already fix the problem! Removing Application token (App_Token) from client of API in GLPi will fix the error.

        Comment


        • Lauro Italo
          Lauro Italo commented
          Editing a comment
          @telmo you removed the Removing Application token from the media type script ? post the fix please
      • keat
        Junior Member
        • Apr 2023
        • 4

        #4
        I couldn't figure how to use the default webhook so I wrote mine from scratch using the following documentation :
        Zabbix JS Preprocessing : https://www.zabbix.com/documentation...ing/javascript
        Objects, methods supported by JS Duktape : https://www.zabbix.com/documentation...script_objects

        My script only allow me to create a new ticket on alert trigger. It is crappy but I share it in case it can help someone.

        Code:
        // Script Engine : Duktape
        // Parse value from Zabbix params
        params = JSON.parse(value),
        
        AUTH_TOKEN = params.auth_token
        GLPI_URL = params.glpi_url
        TITLE = params.alert_subject
        MESSAGE = params.alert_message
        URGENCY = params.event_nseverity
        
        function getAuthToken(url, auth_token) {
        
        auth_header = 'Authorization: user_token ' + auth_token
        
        // Embbed cURL
        request = new HttpRequest()
        request.addHeader('Content-Type: application/json');
        request.addHeader(auth_header);
        
        response = request.get(url + 'apirest.php/initSession/');
        response = JSON.parse(response)
        
        // Return only data from key "session_token"
        return response.session_token
        }
        
        // Create a ticket
        try {
        SESSION_TOKEN = getAuthToken(GLPI_URL, AUTH_TOKEN)
        
        // Request body
        ticket_data = {
        'input': {
        'name': TITLE,
        'requesttypes_id': 7, // Modify the "demand source"
        'status': 1, // Set status "New"
        'content': MESSAGE,
        'entities_id': 0, // Set to root entity
        'urgency': URGENCY
        }
        };
        
        glpi_ticket_url = GLPI_URL + "apirest.php/Ticket/"
        
        request = new HttpRequest()
        
        request.addHeader('Content-Type: application/json');
        request.addHeader('Session-Token: ' + SESSION_TOKEN);
        
        
        // Send POST request.
        // Data has to be converted from Object to JSON using JSON.stringify().
        response = request.post(glpi_ticket_url, JSON.stringify(ticket_data));
        
        Zabbix.log(4, '[ GLPI Webhook ] Result: ' + JSON.stringify(response));
        return JSON.stringify(response);
        
        }
        catch (error) {
        Zabbix.log(4, '[ GLPI Webhook ] ERROR: ' + error);
        
        throw 'Sending failed: ' + error + ' data :' + JSON.stringify(ticket_data);
        }
        The media type I created :
        Click image for larger version

Name:	image.png
Views:	2059
Size:	42.1 KB
ID:	464266

        Message template is the default "Problem" one ​.​

        Comment

        • frmoronari
          Junior Member
          • Nov 2023
          • 1

          #5
          Originally posted by keat
          OS : Debian 11 Bullseye
          Zabbix : v6.2
          GLPI : v10

          Hi,
          i'm trying to setup GLPI webhook to create a new "problem" based on the default "GLPi" media type.
          When I test it, i got a error from GPLI API (see screenshot).
          Click image for larger version  Name:	image.png Views:	306 Size:	11.7 KB ID:	463346

          What I understand :
          • Webhook authenticate correctly using the API token that i provided
          • Then, webhook send a request to GLPI server with an empty 'Session-Token'

          It seems Zabbix can connect to GLPI because I receive a response.

          I thought the problem was on GLPI side so i checked and cURL.
          When i send a request, I get a SSL certificate error. It's because GLPI certificate is signed using my own root CA.
          I tried passing the root CA using --cacert cURL option and it works. Same using --insecure option.

          I added my root CA in /usr/share/ca-certificates and did a 'sudo apt update-ca-certificates'. Nothing
          I added my root CA in /etc/ssl/certs/. Same

          I don't know if the issue is the root CA because it seems GLPI server respond to webhook's requests.
          Nothing in the logs on both side.

          Anyone knows which service is executing webhooks ?
          Which path is Zabbix reading root CA files from ?

          Thanks​
          I have a same error,
          do you grant solution for this case?​

          Comment

          • soumya
            Junior Member
            • Nov 2013
            • 21

            #6
            HI keat,
            all you need to do, is to delete the app_token, got generated for the apiclient, in GLPI & save. This will solve your problem.Click image for larger version

Name:	image.png
Views:	969
Size:	41.7 KB
ID:	490478

            Comment

            • renatobeiriz
              Junior Member
              • Nov 2023
              • 20

              #7
              keat

              when i use ur code, and test, have this error
              Click image for larger version

Name:	image.png
Views:	836
Size:	13.1 KB
ID:	492142
              Click image for larger version

Name:	image.png
Views:	854
Size:	31.1 KB
ID:	492143

              Comment


              • leonardon
                leonardon commented
                Editing a comment
                I have the same problem, did you manage to solve it?
            Working...