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 2019-09-20 21:05:27

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

[SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

Hello again to All

I'm here again, because I've made some tests and still in the same..

I can create tickerts on glpi by your API, working fine.

I will remember for you about my scenario: actually it's running a glpi 0.90 with integration with zabbix 3.0.25. Both system communicate to each other between plugin webservices. In the Zabbix side have scripts pointing to GLPI 0.90 in /usr/lib/zabbix/externalscripts and in the GLPI-side have an Zabbix agent pointing to Zabbix server. I know that plugin stopped your version till the GLPI 9.3. I know too that GLPI have a API to work with other applications. all that integration wasn't made by me, an another person did it a long time ago, and still running.

Now, I have a new instance of GLPI 9.4.2 that not work with webservices plugin and the Zabbix it's the same yet. But I'm with many doubts, already search for this integration, but all i've found it's by using the webservices plugin.

I did try follow this link https://janssenlima.blogspot.com/2013/1 … -glpi.html, but no success, because it's very old, it's using webservices plugin. I cannot found any topic by using native API for this integration.

Zabbix have a API too, but i have no idea to perform this integration.

Already turned the whole internet looking for practical answers, nothing yet.

Need help again, please.

Last edited by mecmav (2019-09-20 21:12:18)

Offline

#2 2019-09-20 23:09:04

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

I Don't know much about Zabbix, but I guess some events triggers actions in Zabbix.

https://www.zabbix.com/documentation/4. … dia/script

from this doc, i would try to
-write a script that calls glpi API  , initsession create a ticket, kill session
-launch this script when triggrerd by some alert.

if it work i would try to pass some parameters to the script ( title, description)


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#3 2019-09-23 20:53:22

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

I Don't know much about Zabbix, but I guess some events triggers actions in Zabbix.

https://www.zabbix.com/documentation/4. … dia/script

from this doc, i would try to
-write a script that calls glpi API  , initsession create a ticket, kill session
-launch this script when triggrerd by some alert.

if it work i would try to pass some parameters to the script ( title, description)

After study and read nearly all documentation, finally I can open a ticket when occurs an event in zabbix.
it's gave me a lot of work, but I need firstly say thanks to you @LaDenrée because since your first reply helping me I can see the light in the end of tunnel, and I got an north to follow.
The unique remaining thing now it's to discover the method how to close the ticket, almost there...

Offline

#4 2019-09-23 21:55:22

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

i guess glpi ticket name is like "zabbix alert event #1234 ... "

and when close alert in zabbix you can get this "#1234"  ID.

so write a script that :
initsession
search GLPI ticket  with the name " zabbix alert event #1234";  and get glpi $ticket_ID

then add solution ti ticket to close it

curl -X POST -H 'Content-Type: application/json'
-H "Authorization: user_token xxxxxxxx"
-H "Session-Token: xxxxxxxx"
-H "App-Token: xxxxxxxx"
-d '{"input": {"itemtype":"Ticket","items_id": "$ticket_ID","solutiontypes_id":"2","solutiontype_name":"null","content":"MySolutionDescription","status":"3"}}' '../glpi/apirest.php/ITILSolution/'


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#5 2019-09-24 04:08:58

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

i guess glpi ticket name is like "zabbix alert event #1234 ... "

and when close alert in zabbix you can get this "#1234"  ID.

so write a script that :
initsession
search GLPI ticket  with the name " zabbix alert event #1234";  and get glpi $ticket_ID

then add solution ti ticket to close it

curl -X POST
-H 'Content-Type: application/json'
-H "Authorization: user_token xxxxxxxx"
-H "Session-Token: xxxxxxxx"
-H "App-Token: xxxxxxxx"
-d '{"input": {"itemtype":"Ticket","items_id": "$ticket_ID","solutiontypes_id":"2","solutiontype_name":"null","content":"MySolutionDescription","status":"3"}}' '../glpi/apirest.php/ITILSolution/'

How can I read the id of a ticket?

It's necessary mix php and json ?

I'm using that to open a ticket in glpi by zabbix. Some global variables from Zabbix.

I believe that code below can help to any others that finding for an integration between Zabbix and GLPI via API. There are some other steps not mentioned here.

curl -X POST \
  http://my-ip/apirest.php/Ticket/ \
  -H 'App-Token: xxxxx' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: glpi_token' \
  -H 'Host: localhost' \
  -H 'Session-Token: xxxxxxxx' \
  -d '{
    "input": {
        "name": "{TRIGGER.STATUS}:{HOST.NAME} down! - Event {EVENT.ID} generated automatically by Zabbix & GLPI",
        "content": "Hostname: {HOST.NAME}. Trigger ID:{TRIGGER.ID},{TRIGGER.DESCRIPTION}. Trigger status: {TRIGGER.STATUS}",
        "itilcategories_id": 112,
        "requesttypes_id": 6,
        "urgency": 4,
        "impact": 5,
        "priority": 5,
        "type": 1
    }
}'

Finally after an event on zabbix the ticket is created with my pre-assigned rules.

Should I make multiple requests on the same object array or separated by commas?

Offline

#6 2019-09-24 09:16:39

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

to get ticket ID :

curl -X GET
-H 'Content-Type: application/json'
-H "Authorization: user_token xxxxxxxx"
-H "Session-Token: xxxxxxxx"
-H "App-Token: xxxxxxxx"
"../glpi/apirest.php/search/Ticket?\
criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=1\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\={EVENT.ID}
"

then you should get a json containing yout ticket ID


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#7 2019-09-24 13:57:25

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

to get ticket ID :

curl -X GET
-H 'Content-Type: application/json'
-H "Authorization: user_token xxxxxxxx"
-H "Session-Token: xxxxxxxx"
-H "App-Token: xxxxxxxx"
"../glpi/apirest.php/search/Ticket?\
criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=1\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\={EVENT.ID}
"

then you should get a json containing yout ticket ID

it works, returns some data below:

{
    "totalcount": 129,
    "count": 20,
    "sort": 1,
    "order": "ASC",
    "data": [
        {
            "2": 142,
            "1": "",
            "12": 1,
            "19": "2019-09-20 09:43:42",
            "15": "2019-09-20 09:43:42",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 143,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:19:24",
            "15": "2019-09-23 11:19:24",
            "3": 5,
            "4": 2,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "glpi"
        },
        {
            "2": 144,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:27:50",
            "15": "2019-09-23 11:27:50",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 145,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:45:03",
            "15": "2019-09-23 11:45:03",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 146,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:47:04",
            "15": "2019-09-23 11:47:04",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 147,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:50:04",
            "15": "2019-09-23 11:50:04",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 148,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:52:05",
            "15": "2019-09-23 11:52:05",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 149,
            "1": "",
            "12": 1,
            "19": "2019-09-23 12:02:02",
            "15": "2019-09-23 12:02:02",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 150,
            "1": "",
            "12": 1,
            "19": "2019-09-23 12:04:02",
            "15": "2019-09-23 12:04:02",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 35,
            "1": "DETRAN (Cidade) - PICSXXXX, I ou J XXXX, PSGYYYY com falhas.",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-03 20:16:56",
            "3": 3,
            "4": 2,
            "8": "N2 - Técnica",
            "5": null,
            "7": "Serviços de Impressão > Falha no Serviço de Impressão",
            "18": "2019-09-04 11:30:00",
            "14": 1,
            "22": "glpi"
        },
        {
            "2": 67,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:21:21",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-04 16:21:21",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 73,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:45:37",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 07:45:37",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 74,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:50:12",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 07:50:12",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 75,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:52:10",
            "3": 3,
            "4": 3257,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Manutenção",
            "18": "2019-09-05 16:30:00",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 79,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 15:33:37",
            "3": 3,
            "4": 3257,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Erro/Indisponibilidade",
            "18": "2019-09-05 10:33:37",
            "14": 1,
            "22": "glpi"
        },
        {
            "2": 80,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 15:37:49",
            "3": 3,
            "4": 5,
            "8": "NIMP",
            "5": 1793,
            "7": "BPMS > Manutenção",
            "18": "2019-09-05 16:30:00",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 81,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 15:57:12",
            "3": 3,
            "4": 2,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 08:57:12",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 83,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 16:19:20",
            "3": 3,
            "4": 3257,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 09:19:20",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 64,
            "1": "DETRAN Sede - BPMS - Dúvidas",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 10:28:53",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-04 12:28:53",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 65,
            "1": "DETRAN Sede - BPMS - duvidas",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 10:31:49",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-04 12:31:49",
            "14": 2,
            "22": "glpi"
        }
    ],
    "content-range": "0-20/129"
}

But I don't understand how these values are returned. How it works the criterias for search ticket?

Offline

#8 2019-09-24 14:44:47

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

there are no title  in tickets. 
have a look to tiket #142 :

        {
            "2": 142,
            "1": "",
            "12": 1,
            "19": "2019-09-20 09:43:42",
            "15": "2019-09-20 09:43:42",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },

field 1 is empty. ( ticket title) 
title/name  should be :   "name": "{TRIGGER.STATUS}:{HOST.NAME} down! - Event {EVENT.ID} generated automatically by Zabbix & GLPI",  as written in post #5: 


is {EVENT.ID}  a unique number ?


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#9 2019-09-24 15:07:35

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

there are no title  in tickets. 
have a look to tiket #142 :

        {
            "2": 142,
            "1": "",
            "12": 1,
            "19": "2019-09-20 09:43:42",
            "15": "2019-09-20 09:43:42",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },

field 1 is empty. ( ticket title) 
title/name  should be :   "name": "{TRIGGER.STATUS}:{HOST.NAME} down! - Event {EVENT.ID} generated automatically by Zabbix & GLPI",  as written in post #5: 


is {EVENT.ID}  a unique number ?

yes, it comes from zabbix event. It's a unique number.

But for I search, do I need type {EVENT.ID} or his value?

I'm very confusing now.. But I don't give up.

I'm trying apirest.php/search/Ticket?\
criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=1\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\={EVENT.ID}\
\&criteria\[1\]\[field\]\=2\

I know that number of each field, for example id 1 is title ticket, 2 it's id ticket, 3 priority...

But I'm locked in the part that I need obtain an specific ticket_id

Offline

#10 2019-09-24 15:15:38

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

step by step :

1)create a glpi ticket with title containing Zabbix eventid ( the number)

when event is closed by Zabbix ( few minutes/hours later ?)

2) with GLPI api search a ticket  with title containing Zabbix eventid ( the number)=> returns ticket with glpi ticket id, title, desc….  (should be only 1 ticket with this eventid in glpi) 

3) add solution to this glpi's ticket


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#11 2019-09-24 15:38:24

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

step by step :

1)create a glpi ticket with title containing Zabbix eventid ( the number)

when event is closed by Zabbix ( few minutes/hours later ?)

2) with GLPI api search a ticket  with title containing Zabbix eventid ( the number)=> returns ticket with glpi ticket id, title, desc….  (should be only 1 ticket with this eventid in glpi) 

3) add solution to this glpi's ticket

Really I have some tickets without title, but other with have.

Any request I do in the postman, returns the same result. I already have an open ticket (ID=161), was opened by zabbix and closes at a few time later. For my case i'm stopping the ssh service in the glpi-server, zabbix by monitoring him when occurs it, zabbix triggers an action to open ticket.

The result by request apirest.php/search/Ticket its the same below.

Now, to retrieve that ticket I run:

apirest.php/search/Ticket?\
criteria\[0\]\[link\]\=AND\
\&criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=1\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\=17480

Am I doing something wrong?

Last edited by mecmav (2019-09-24 15:38:37)

Offline

#12 2019-09-24 15:50:07

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

do you initsession with Zabbix user ?

can you search for ticket with title containing 17480 in GLPI ? ( GUI, not with API, login in with Zabbix user)


with API can you search ticket by ID  :

../apirest.php/search/Ticket?\
criteria\[0\]\[link\]\=AND\
\&criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=2\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\=161


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#13 2019-09-24 15:59:40

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

do you initsession with Zabbix user ?

can you search for ticket with title containing 17480 in GLPI ? ( GUI, not with API, login in with Zabbix user)


with API can you search ticket by ID  :

../apirest.php/search/Ticket?\
criteria\[0\]\[link\]\=AND\
\&criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=2\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\=161

Yes, I have a session for zabbix user.

Sorry for that.

I was performing search in API. Now I've done search in GUI by the number of EVENT.ID and the specific ticket returns with the id 161, like I need.

Now in the API I Run
Ticket?\
criteria\[0\]\[link\]\=AND\
\&criteria\[0\]\[itemtype\]\=Ticket\
\&criteria\[0\]\[field\]\=2\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\=161

and returns all again.

{
    "totalcount": 129,
    "count": 20,
    "sort": 1,
    "order": "ASC",
    "data": [
        {
            "2": 142,
            "1": "",
            "12": 1,
            "19": "2019-09-20 09:43:42",
            "15": "2019-09-20 09:43:42",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 143,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:19:24",
            "15": "2019-09-23 11:19:24",
            "3": 5,
            "4": 2,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "glpi"
        },
        {
            "2": 144,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:27:50",
            "15": "2019-09-23 11:27:50",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 145,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:45:03",
            "15": "2019-09-23 11:45:03",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 146,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:47:04",
            "15": "2019-09-23 11:47:04",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 147,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:50:04",
            "15": "2019-09-23 11:50:04",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 148,
            "1": "",
            "12": 1,
            "19": "2019-09-23 11:52:05",
            "15": "2019-09-23 11:52:05",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 149,
            "1": "",
            "12": 1,
            "19": "2019-09-23 12:02:02",
            "15": "2019-09-23 12:02:02",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 150,
            "1": "",
            "12": 1,
            "19": "2019-09-23 12:04:02",
            "15": "2019-09-23 12:04:02",
            "3": 5,
            "4": 3271,
            "8": null,
            "5": null,
            "7": "Serviço de Rede e Internet > Falha de Conexão de Rede > Zabbix",
            "18": null,
            "14": 1,
            "22": "zabbix"
        },
        {
            "2": 35,
            "1": "DETRAN (Cidade) - PICSXXXX, I ou J XXXX, PSGYYYY com falhas.",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-03 20:16:56",
            "3": 3,
            "4": 2,
            "8": "N2 - Técnica",
            "5": null,
            "7": "Serviços de Impressão > Falha no Serviço de Impressão",
            "18": "2019-09-04 11:30:00",
            "14": 1,
            "22": "glpi"
        },
        {
            "2": 67,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:21:21",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-04 16:21:21",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 73,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:45:37",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 07:45:37",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 74,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:50:12",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 07:50:12",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 75,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 14:52:10",
            "3": 3,
            "4": 3257,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Manutenção",
            "18": "2019-09-05 16:30:00",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 79,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 15:33:37",
            "3": 3,
            "4": 3257,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Erro/Indisponibilidade",
            "18": "2019-09-05 10:33:37",
            "14": 1,
            "22": "glpi"
        },
        {
            "2": 80,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 15:37:49",
            "3": 3,
            "4": 5,
            "8": "NIMP",
            "5": 1793,
            "7": "BPMS > Manutenção",
            "18": "2019-09-05 16:30:00",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 81,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 15:57:12",
            "3": 3,
            "4": 2,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 08:57:12",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 83,
            "1": "DETRAN Sede - BPMS",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 16:19:20",
            "3": 3,
            "4": 3257,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-05 09:19:20",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 64,
            "1": "DETRAN Sede - BPMS - Dúvidas",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 10:28:53",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-04 12:28:53",
            "14": 2,
            "22": "glpi"
        },
        {
            "2": 65,
            "1": "DETRAN Sede - BPMS - duvidas",
            "12": 2,
            "19": "2019-09-18 13:26:56",
            "15": "2019-09-04 10:31:49",
            "3": 3,
            "4": 1804,
            "8": "NIMP",
            "5": null,
            "7": "BPMS > Dúvidas",
            "18": "2019-09-04 12:31:49",
            "14": 2,
            "22": "glpi"
        }
    ],
    "content-range": "0-20/129"
}

I don't know what's happening...

Now when I copy exactly the url of the result (GUI) and put in the API request returns only that ticket.

?is_deleted=0&as_map=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=1&criteria%5B0%5D%5Bsearchtype%5D=contains&criteria%5B0%5D%5Bvalue%5D=17480&search=Pesquisar&itemtype=Ticket&start=0

Offline

#14 2019-09-24 16:12:12

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

when I run
…../apirest.php/search/Ticket?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=Myvalue&forcedisplay[0]=2

it works ( with php and GLPI 9.4.3).


try url without escaping special caracters.  ( without  \ ).


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#15 2019-09-24 16:28:23

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

when I run
…../apirest.php/search/Ticket?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=Myvalue&forcedisplay[0]=2

it works ( with php and GLPI 9.4.3).


try url without escaping special caracters.  ( without  \ ).

Using like you say I have a correct response. Need to use without \

Ticket?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=17480&forcedisplay[0]=2

returns

{
    "totalcount": 1,
    "count": 1,
    "sort": 1,
    "order": "ASC",
    "data": [
        {
            "2": 161,
            "1": "PROBLEM:glpi-teste fora do ar! - Evento 17480 gerado automaticamente pelo Zabbix & GLPI."
        }
    ],
    "content-range": "0-0/1"
}

Offline

#16 2019-09-24 20:22:07

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

Now, I can't think a way to save request results to use in next.

I have a ticket opened by Zabbix, which contain an EVENT.ID

First request to discover the ticket_id, need pass the EVENT.ID directly in [value]:

apirest.php/Ticket?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=17480&forcedisplay[0]=2

returns

{
    "totalcount": 1,
    "count": 1,
    "sort": 1,
    "order": "ASC",
    "data": [
        {
            "2": 161,
            "1": "PROBLEM:glpi-teste fora do ar! - Evento 17480 gerado automaticamente pelo Zabbix & GLPI."
        }
    ],
    "content-range": "0-0/1"
}

after that I need store the returned id 161 to next request.

Next request is close that ticket.

apirest.php/ITILSolution

{
    "input": {
        "items_id": 161,
        "content": "OK: {HOST.NAME}. Chamado fechado automaticamente atraves do evento {EVENT.ID}",
        "solutiontypes_id": 16,
        "itemtype": "Ticket",
        "status": 3
       
    }
}

How Can I do that ?

Last edited by mecmav (2019-09-24 20:27:46)

Offline

#17 2019-09-24 23:33:00

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

you want to store ticket id in a variable ?

sorry, I don't know how to do that with zabbix.


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#18 2019-09-25 13:46:17

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

you want to store ticket id in a variable ?

sorry, I don't know how to do that with zabbix.

Yeah, I need to store for use in next request. I can open and close the tickets in glpi by API normally.

But for a ticket be closed automatically by an event on zabbix, it's necessary set up a rule on zabbix side which load the parameters to execute the action on API glpi, since the zabbix have the permission rule to access the GLPI API.

For do that have to be executed 3 remote commands,  every with your own parameters to execute in glpi API. In zabbix have a option to insert only one command per event , because this I will find a way to discover the response of ticket_id (from a request) and execute other request with passed the ticket_id to close the ticket when event become up again.

I need to know if it's possible run two or three requests in same sent.

Offline

#19 2019-09-25 14:11:46

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

is it possible to run a command like this  ?

C:\xampp\php\php.exe  Zabbix_ticket_solve.php     EVENT.ID


and write a Zabbix_ticket_solve.php script that
<?php
     initsession
     search for ticket
     get ticketID in a variable
     add a solution


?>


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#20 2019-09-25 14:28:39

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

is it possible to run a command like this  ?

C:\xampp\php\php.exe  Zabbix_ticket_solve.php     EVENT.ID


and write a Zabbix_ticket_solve.php script that
<?php
     initsession
     search for ticket
     get ticketID in a variable
     add a solution


?>

I will create a php file inside the /etc/zabbix (agent directory) on my glpi and set up a rule on zabbix (another machine) to execute a remotte command and pointing to that path, when occurs an event.

EVENT.ID must be passed through GET?

Can't understand that part.

In the php file, Can I write a different file for each request and include them or write all requests and store his result?

Offline

#21 2019-09-25 16:12:35

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

you can use this php file (with envent.id as param from zabbix)

<?php
	$event_id = $argv[1]; 
	$app_token='mytoken';
	$user_token='zabbixtoken';
	$api_url='localhost/glpi94/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); 
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	$json = curl_exec($ch); 

	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); 
	curl_close ($ch); 
	$obj = json_decode($json,true); 
	//check if ticket is unique;
	if ( $obj['totalcount']<>1)
	{exit;}
	$ticket_id=$obj['data'][0][2];
	echo $ticket_id;
	

$fields='{
    "input": {
        "items_id": "'.$ticket_id.'",
        "content": "OK: . Chamado fechado automaticamente atraves do evento '.$event_id.'",
        "solutiontypes_id": 2,
        "itemtype": "Ticket",
        "status": 3
        
    }
}';
//print_r($fields);
	$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);
	curl_close ($ch);
	$obj = json_decode($json,true);
	//return $obj;
	//print_r($obj);
	
	$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); 
	curl_close ($ch); 

	
?>

Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#22 2019-09-25 20:30:45

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

you can use this php file (with envent.id as param from zabbix)

<?php
	$event_id = $argv[1]; 
	$app_token='mytoken';
	$user_token='zabbixtoken';
	$api_url='localhost/glpi94/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); 
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	$json = curl_exec($ch); 

	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); 
	curl_close ($ch); 
	$obj = json_decode($json,true); 
	//check if ticket is unique;
	if ( $obj['totalcount']<>1)
	{exit;}
	$ticket_id=$obj['data'][0][2];
	echo $ticket_id;
	

$fields='{
    "input": {
        "items_id": "'.$ticket_id.'",
        "content": "OK: . Chamado fechado automaticamente atraves do evento '.$event_id.'",
        "solutiontypes_id": 2,
        "itemtype": "Ticket",
        "status": 3
        
    }
}';
//print_r($fields);
	$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);
	curl_close ($ch);
	$obj = json_decode($json,true);
	//return $obj;
	//print_r($obj);
	
	$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); 
	curl_close ($ch); 

	
?>

I did some changes in that code.

Here it is:

<?php
    $event_id = $argv[1]; 
    $app_token='xxxxxxx';
    $user_token='xxxxxxxxx';
    $api_url='myIP/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); 
    $headers = array(
    'Content-Type: application/json',
    'App-Token: ' .$app_token,
    'Session-Token: '.$sess_token
    );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $json = curl_exec($ch); 

    curl_close ($ch); 
    $obj = json_decode($json,true); 

    $sess_token = $obj['session_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); 
    curl_close ($ch); 
    $obj = json_decode($json,true); 
    //check if ticket is unique;
    if($obj['totalcount']<>1) { 
        exit;
    }
    $ticket_id=$obj['data'][0]["2"];
    echo $ticket_id;

$fields['input']['items_id'] = "".$ticket_id;    
$fields['input']['content'] = "OK: . Chamado fechado automaticamente atraves do evento '.$event_id.'";
$fields['input']['solutiontypes_id'] = 2;
$fields['input']['itemtype'] = "Ticket";
$fields['input']['status'] = 6;

// $fields='{
//     "input": {
//         "items_id": "'.$ticket_id.'",
//         "content": "OK: . Chamado fechado automaticamente atraves do evento '.$event_id.'",
//         "solutiontypes_id": 2,
//         "itemtype": "Ticket",
//         "status": 3
        
//     }
// }';
//print_r($fields);
    $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, json_encode($fields));
    $json = curl_exec($ch);
    curl_close ($ch);
    $obj = json_decode($json,true);
    //return $obj;
    //print_r($obj);
    
    $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); 
    curl_close ($ch); 

    
?>

The script is executed on zabbix, but the ticket don't closes.

Is this correct ?

Let me know if I'm doing something wrong

edit by "la denrée" :  ip, and tokens hidden

Offline

#23 2019-09-25 22:13:15

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

your init session  is not good; you try to set session token in header, but session token is defined a few lines later.

try this : 

//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); 
    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
    );

nothing should be echoed when calling from zabbix so delete or comment

echo $ticket_id;


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

#24 2019-09-26 14:13:49

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 86

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

LaDenrée wrote:

your init session  is not good; you try to set session token in header, but session token is defined a few lines later.

try this : 

//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); 
    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
    );

nothing should be echoed when calling from zabbix so delete or comment

echo $ticket_id;

<?php
    $event_id = $argv[1];
    $app_token='my app_token';
    $user_token='my user_token';
    $api_url='my-ip/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);
    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
    );
   
    $obj = json_decode($json,true);

    $sess_token = $obj['session_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);
    curl_close ($ch);
    $obj = json_decode($json,true);
    //check if ticket is unique;
    if($obj['totalcount']<>1) {
        exit;
    }
    $ticket_id=$obj['data'][0]["2"];
//    echo $ticket_id;

//$fields['input']['items_id'] = $ticket_id;   
//$fields['input']['content'] = "OK: . Chamado fechado automaticamente atraves do evento '.$event_id.'";
//$fields['input']['solutiontypes_id'] = 16;
//$fields['input']['itemtype'] = "Ticket";
//$fields['input']['status'] = 6;

$fields='{
     "input": {
         "items_id": "'.$ticket_id.'",
         "content": "OK: . Chamado fechado automaticamente atraves do evento '.$event_id.'",
         "solutiontypes_id": 2,
         "itemtype": "Ticket",
        "status": 3
       
     }
}';
//print_r($fields);
    $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, json_encode($fields));
    $json = curl_exec($ch);
    curl_close ($ch);
    $obj = json_decode($json,true);
    //return $obj;
    //print_r($obj);
   
    $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);
    curl_close ($ch);

   
?>

That code named "zabbix-close-ticket.php" are in /etc/zabbix on GLPI machine. When I run directly in terminal  "php zabbix-close-ticket.php {EVENT.ID}" or "php zabbix-close-ticket.php 24109" I got no errors but the ticket in Zabbix don't closes.

The Zabbix is monitoring the template SSH Service on GLPI, when SSH become down , the ticket is opened correctly.

When I start again the SSH service , have a action rule which execute this on zabbix-agent (installed on glpi): php /etc/zabbix/zabbix-close-ticket.php {EVENT.ID}

What can be wrong in that ?

Offline

#25 2019-09-26 14:23:23

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 4,715

Re: [SOLVED]Zabbix open ticket in GLPI 9.4.2 Native API without webservice

for debug purpose only :

uncomment echo $ticket_id;


after each " $json = curl_exec($ch);"   add    "print_r($json); "

then run from console "php zabbix-close-ticket.php 24109"

glpi should return some usefull infos about what is wrong


Trouver la panne avant de réparer...
*GLPI 9.1.6+fusion9.1+1.1+behaviours1.5.0+reports+fields+appliances+pdf+badges+formcreator2.5.2 PHP7.0 Mariadb10
*GLPI 9.4.4(behaviours2.2.1+fusioninventoty 9.4+1.1+applicatifs2.5.0+fields 1.9.1)hebergé sur serveur mutualisé.

Offline

Board footer

Powered by FluxBB