You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-03-24 04:29:55

JVGomes
Member
Registered: 2022-02-16
Posts: 14

A plugin to send ticket info

I am creating a plugin to integrate GLPI's tickets with azure devops work items. Every time a ticket is created or updated with some predefined users assigned to it, I want to send a http POST request to the azure RESTful API.
This is what I managed to do so far:

<?php

define('TEST_VERSION', '1.2.10');

function plugin_init_test()
{
   global $PLUGIN_HOOKS;

   $PLUGIN_HOOKS['csrf_compliant']['test'] = true;
   $PLUGIN_HOOKS['item_add']['test'] = ['Ticket' => 'sendTicketInfo'];
   $PLUGIN_HOOKS['item_update']['test'] = ['Ticket' => 'sendTicketInfo'];
}

function plugin_version_test()
{
   return [
      'name'           => 'Plugin name that will be displayed',
      'version'        => TEST_VERSION,
      'author'         => 'John Doe and <a href="http://foobar.com">Foo Bar</a>',
      'license'        => 'GLPv3',
      'homepage'       => 'http://test.com',
      'requirements'   => [
         'glpi'   => [
            'min' => '9.1'
         ]
      ]
   ];
}

function plugin_test_install()
{
   return true;
}

function plugin_test_uninstall()
{
   return true;
}

function sendTicketInfo($ticket)
{
   $webhookUrl = 'http://localhost:8081';
   $payload = $ticket->getDefaultValues();
   $ch = curl_init($webhookUrl);
   curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload, JSON_UNESCAPED_UNICODE));
   curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_exec($ch);
   curl_close($ch);
}

My problem is that the hook item_update doesn't fire when I change the ticket's assigned users. Is there any way I can solve this problem?

Offline

#2 2023-03-24 18:09:07

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: A plugin to send ticket info

A better solution may be using the add and purge hooks for the individual actor link classes "Ticket_User", "Group_Ticket" and "Supplier_Ticket". That way, even if changing a ticket's requesters, watchers, or assigned technicians, you will still be able to know when they change.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

Board footer

Powered by FluxBB