InfotelGLPI / mydashboard

Plugin mydashboard for GLPI
http://blogglpi.infotel.com/
GNU General Public License v2.0
42 stars 19 forks source link

GLPI API Break #75

Closed stonebuzz closed 4 years ago

stonebuzz commented 5 years ago

With the last version of mydashboard 1.7.4 (and previous version 1.6.8) , after installing this plugin, GLPI API is broken.

We have a referenced issue into GLPI repo https://github.com/glpi-project/glpi/issues/5880

mecmav commented 4 years ago

I have this issue too. Using API to create an automatic ticket when occurs a event in another Server like Zabbix. In this case, when the plugin are activated and try create a ticket by API, the functions are broke and do not open ticket. When plugin disabled, the ticket creates normally.

mecmav commented 4 years ago

I'm using GLPI 9.4.2 and MyDashboard 1.7.4.

Franck-Thomas commented 4 years ago

I have this issue too, a fix is planned?

danielpq commented 4 years ago

To fix it you can put this code in the line 84 of setup.php:

if (strpos($_SERVER['REQUEST_URI'], 'central.php?redirect') === false && strpos($_SERVER['REQUEST_URI'], 'apirest.php') === false) {

mecmav commented 4 years ago

not work for me. same result. even reinstalling from a new setup.php

Franck-Thomas commented 4 years ago

mecmav > It did not work for me either, I had to add in line 91:

           if (strpos($_SERVER['REQUEST_URI'], 'central.php?redirect') === false && strpos($_SERVER['REQUEST_URI'], 'apirest.php') === false) {
danielpq commented 4 years ago

Because my version is the 1.5.2. I checked in the version 1.7.5 and the line is 90 now. But the goal is complete the checks to don't do the redirects with the check of calls going from apirest.php puting strpos($_SERVER['REQUEST_URI'], 'apirest.php') === false in some place.

mecmav commented 4 years ago

maybe the issue i'm having it's different from this

mecmav commented 4 years ago

INFO: GLPI 9.4.2 Plugin: Mydashboard 1.7.6 (same behavior from 1.7.1) Zabbix-server: 3.0.26

I have following: a script that call GLPI API to create a ticket when occurs a event "DOWN" in zabbix. Zabbix Server open ticket in GLPI using this:

curl -X POST \ http://myinstance/apirest.php/Ticket/ \ -H 'App-Token: app-token for Zabbix-Server' \ -H 'Content-Type: application/json' \ -H 'Host: myinstance' \ -H 'Session-Token: session-token for glpi-user named zabbix' \ -d ' { "input": { "users_id":1876, "type":1, "itilcategories_id":16, "requesttypes_id":7, "urgency":4, "impact":5, "priority":3, "name":"{TRIGGER.STATUS}: {HOST.NAME} out of working! Event {EVENT.ID} generated automatically by Zabbix & GLPI.", "content":"Hostname: {HOST.NAME}. Trigger_ID: {TRIGGER.ID}, Trigger_status: {EVENT.NAME}"

}

}'

After zabbix-server get acknowledge OK for that event, run this: php /etc/zabbix/script-close-ticket.php {EVENT.ID}

An zabbix-agent installed on GLPI-Server run the script for close the ticket.

This is my code named script-close-ticket.php for close the ticket-->

<?php $event_id = $argv[1]; $app_token='my-app-token'; $user_token='user-token'; $api_url='myinstance/apirest.php';

//initsession for zabbix user;

$url=$api_url."/initSession?Content-Type=application/json&app_token=".$app_token ."&user_token=".$user_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$json = curl_exec($ch); 
print_r($json);
curl_close ($ch); 
$obj = json_decode($json,true); 
$sess_token = $obj['session_token'];
$headers = array(
'Content-Type: application/json',
'App-Token: ' .$app_token,
'Session-Token: '.$sess_token
);
$url=$api_url."/search/Ticket?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=".$event_id."&forcedisplay[0]=2";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$json = curl_exec($ch);
print_r($json); 
curl_close ($ch); 
$obj = json_decode($json,true); 

//check if ticket is unique;

if($obj['totalcount']<>1) { 
    exit;
}
$ticket_id=$obj['data'][0]["2"];

$fields='{ "input": { "items_id": "'.$ticket_id.'", "content": "OK: . Ticket closed automatically by event '.$event_id.'", "solutiontypes_id": 16, "itemtype": "Ticket", "status": 6

 }

}';

$ch = curl_init();
$url=$api_url ."/ITILSolution/";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$json = curl_exec($ch);
print_r($json);
curl_close ($ch);
$obj = json_decode($json,true);

$url=$api_url ."/killSession/";

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $json = curl_exec($ch); print_r($json); curl_close ($ch);

?>

Now occurs the issue! When the plugin MyDashboard is active, the ticket can be opened but don't close. When plugin's disabled, ticket can be open and closed normally.

I did try make these changes but no effect for me.

Any suggest?

danielpq commented 4 years ago

Before I did this fix I was having random behavior like you. Calling the same url two times the first didn't work and the second worked.

Check the response of the second call, that fail. If it is composed by the HTML of the GLPI's login page the problem is the same. My problem was caused by redirect.

You can try the same code in JS calling by a browser and see the network traffic or install something like Wireshark in the server and watch the protocol communication to understand the problem.

Tell me if worked.

mecmav commented 4 years ago

So, I think my problem it's different from that. If I disable the plugin I have no problems to close ticket running GLPI API from host zabbix.

I don't know programming with javascript, so I can't test other ways.

Anyway, Thanks by suggestions to help me with this.

For a while, I think disable the plugin, even don't want, because have too many widgets utils to my users, but impacts directly in integration with pther systems, like zabbix and redmine, because if the plugin is activated, crashes my requests in API.

tsmr commented 4 years ago

Fixed into #95