├── README.md ├── zabbix-gpi-webhookv2.yaml ├── zbx_export_mediatypes_glpi.yaml └── zbx_export_mediatypes_v6.4.yaml /README.md: -------------------------------------------------------------------------------- 1 | # Zabbix-WebHook-GLPI 2 | 3 | Zabbix WebHook GLPI 4 | 5 | Develop by: Andrey Amado for AKA Sistemas 6 | 7 | Help: andreyamado@akasistemas.com 8 | 9 | The documentation can be found on: 10 | https://yourglpirootlocation/apirest.php/ 11 | 12 | Additionally, you must enable the API access from glpi and activate the user authentication and app token. 13 | 14 | Adjust the parameters according to your installation. 15 | The "To" parameter must be the id_user from GLPI. 16 | 17 | V2 what is the new: 18 | - add update and close support ticket 19 | - add URL zabbix trigger into the ticket. 20 | 21 | Instruction for test: 22 | Please remember that the script is maked for capture zabbix parameters, if you want make the test directly please set the next values: 23 | Event_Value:1 24 | Event_Update_Status:0 25 | -------------------------------------------------------------------------------- /zabbix-gpi-webhookv2.yaml: -------------------------------------------------------------------------------- 1 | zabbix_export: 2 | version: '5.2' 3 | date: '2021-05-31T18:32:02Z' 4 | media_types: 5 | - 6 | name: Glpi 7 | type: WEBHOOK 8 | parameters: 9 | 15: 10 | name: Event_Update_Status 11 | value: '{EVENT.UPDATE.STATUS}' 12 | 13: 13 | name: Event_Value 14 | value: '{EVENT.VALUE}' 15 | 3: 16 | name: glpi_apptoken 17 | value: xxxxxx5rxt6OvzXg8ljiRz1Kt3UQxxxxx(your app token) 18 | 5: 19 | name: glpi_entities_id 20 | value: '1' 21 | 20: 22 | name: glpi_event_id 23 | value: '{EVENT.ID} ​ ​' 24 | 14: 25 | name: glpi_event_severity 26 | value: '{EVENT.NSEVERITY} ​ ​' 27 | 17: 28 | name: glpi_event_update_mess 29 | value: '{EVENT.UPDATE.MESSAGE}' 30 | 7: 31 | name: glpi_impact 32 | value: '3' 33 | 9: 34 | name: glpi_itilcategories_id 35 | value: '1' 36 | 2: 37 | name: glpi_password 38 | value: glpi 39 | 8: 40 | name: glpi_priority 41 | value: '3' 42 | 19: 43 | name: glpi_tgrid 44 | value: '{TRIGGER.ID}' 45 | 16: 46 | name: glpi_ticket_id 47 | value: '{EVENT.TAGS.zbx_glpi_ticket}' 48 | 6: 49 | name: glpi_urgency 50 | value: '3' 51 | 4: 52 | name: glpi_url 53 | value: 'https://192.168.0.1/glpi/' 54 | 1: 55 | name: glpi_user 56 | value: glpi 57 | 0: 58 | name: HTTPProxy 59 | value: '' 60 | 10: 61 | name: Message 62 | value: '{ALERT.MESSAGE}' 63 | 11: 64 | name: Subject 65 | value: '{ALERT.SUBJECT}' 66 | 12: 67 | name: To 68 | value: '{ALERT.SENDTO}' 69 | 18: 70 | name: zb_web_url 71 | value: 'https://www.your-zabbix-frontend.com/zabbix/' 72 | script: | 73 | var params = JSON.parse(value), 74 | result = {tags: {}}; 75 | var url_api = params.glpi_url + "apirest.php/"; 76 | var url_ticket = params.glpi_url + "front/ticket.form.php?id="; 77 | 78 | function GetSession(){ 79 | try{ 80 | var userpass = params.glpi_user + ':' + params.glpi_password; 81 | req = new CurlHttpRequest(); 82 | proxy = params.HTTPProxy; 83 | req.SetProxy(proxy); 84 | req.AddHeader('Content-Type: application/json'); 85 | req.AddHeader('Authorization: Basic '+ btoa(userpass)); 86 | req.AddHeader('App-Token: '+params.glpi_apptoken); 87 | resp = req.Get(url_api+'initSession'); 88 | 89 | if (req.Status() != 200) { 90 | Zabbix.Log(4, '[GLPI Webhook] login failed: ' + resp); 91 | throw 'Response: '+req.Status(); 92 | } 93 | resp = JSON.parse(resp); 94 | //throw(resp.session_token); 95 | return resp.session_token; 96 | 97 | } 98 | catch (error) { 99 | Zabbix.Log(4, '[GLPI Webhook] login failed: ' + error); 100 | throw 'Login failed: ' + error + '.'; 101 | } 102 | } 103 | function CreateTicket(session_token){ 104 | try{ 105 | req = new CurlHttpRequest(); 106 | fields = {}; 107 | proxy = params.HTTPProxy; 108 | req.SetProxy(proxy); 109 | req.AddHeader('Content-Type: application/json'); 110 | req.AddHeader('Session-Token: '+ session_token); 111 | req.AddHeader('App-Token: '+params.glpi_apptoken); 112 | fields.input = {"name": params.Subject ,"content": params.Message + "URL_EVENT: " + params.zb_web_url + "tr_events.php?triggerid=" + params.glpi_tgrid +"&eventid="+params.glpi_event_id, "itilcategories_id": params.glpi_itilcategories_id,"entities_id":params.glpi_entities_id,"urgency":params.glpi_urgency,"impact":params.glpi_impact,"priority":params.glpi_priority,"_users_id_assign":params.To } 113 | resp = req.Post(url_api+'Ticket',JSON.stringify({"input":fields.input})); 114 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket response: ' + resp); 115 | resp = JSON.parse(resp); 116 | 117 | return resp.id; 118 | 119 | if (req.Status() != 201) { 120 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + resp); 121 | throw 'Response: '+req.Status(); 122 | } 123 | 124 | 125 | } 126 | catch (error) { 127 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + error); 128 | throw 'CreateTicket failed: ' + error + '.'; 129 | } 130 | } 131 | 132 | function UpdateTicket(session_token){ 133 | try{ 134 | req = new CurlHttpRequest(); 135 | fields = {}; 136 | proxy = params.HTTPProxy; 137 | req.SetProxy(proxy); 138 | req.AddHeader('Content-Type: application/json'); 139 | req.AddHeader('Session-Token: '+ session_token); 140 | req.AddHeader('App-Token: '+params.glpi_apptoken); 141 | 142 | if (params.Event_Value === '0'){ 143 | fields.input = {"itemtype": "Ticket","items_id": params.glpi_ticket_id,"content": params.Message} 144 | resp = req.Post(url_api+'Ticket/'+params.glpi_ticket_id + "/ITILSolution",JSON.stringify({"input":fields.input})); 145 | }else{ 146 | fields.input = {"itemtype": "Ticket","items_id": params.glpi_ticket_id ,"content": params.Message } 147 | resp = req.Post(url_api+'Ticket/'+params.glpi_ticket_id + "/ITILFollowup",JSON.stringify({"input":fields.input})); 148 | } 149 | 150 | 151 | Zabbix.Log(4, '[GLPI Webhook] UpdateTicket response: ' + resp); 152 | resp = JSON.parse(resp); 153 | tikedid=params.glpi_ticket_id; 154 | return resp.tikedid; 155 | 156 | if (req.Status() != 201) { 157 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + resp); 158 | throw 'Response: '+req.Status(); 159 | } 160 | 161 | 162 | } 163 | catch (error) { 164 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + error); 165 | throw 'CreateTicket failed: ' + error + '.'; 166 | } 167 | 168 | } 169 | 170 | function KillSession(session_token){ 171 | try{ 172 | req = new CurlHttpRequest(); 173 | proxy = params.HTTPProxy; 174 | req.SetProxy(proxy); 175 | req.AddHeader('Content-Type: application/json'); 176 | req.AddHeader('Session-Token: '+ session_token); 177 | req.AddHeader('App-Token: '+params.glpi_apptoken); 178 | resp = req.Get(url_api+'killSession'); 179 | Zabbix.Log(4, '[GLPI Webhook] KillSession response: ' + resp); 180 | 181 | if (req.Status() != 200) { 182 | Zabbix.Log(4, '[GLPI Webhook] KillSession failed: ' + resp); 183 | throw 'Response: '+req.Status(); 184 | } 185 | } 186 | catch (error) { 187 | Zabbix.Log(4, '[GLPI Webhook] KillSession failed: ' + error); 188 | throw 'KillSession failed: ' + error + '.'; 189 | } 190 | } 191 | 192 | try { 193 | if (params.glpi_user === "") { 194 | throw 'Incorrect value is given for parameter "glpi_user": parameter is missing'; 195 | } 196 | if (params.glpi_password === "") { 197 | throw 'Incorrect value is given for parameter "password": parameter is missing'; 198 | } 199 | if (params.glpi_apptoken === "") { 200 | throw 'Incorrect value is given for parameter "glpi_apptoken": parameter is missing'; 201 | } 202 | if (params.glpi_url === "") { 203 | throw 'Incorrect value is given for parameter "glpi_url": parameter is missing'; 204 | } 205 | session = GetSession(); 206 | Zabbix.Log(4, '[GLPI Webhook] Login OK session_token: ' + session); 207 | 208 | //Zabbix.Log(4, '[GLPI Webhook] params: ' + params.Event_Update_Status); 209 | if (params.Event_Value === '1' && params.Event_Update_Status === '0') { 210 | //if (params.Event_Value === '1' ) { 211 | nt = CreateTicket(session); 212 | Zabbix.Log(4, '[GLPI Webhook] OK ticket: ' + nt); 213 | result.tags.zbx_glpi_ticket = nt; 214 | result.tags.zbx_glpi_ticketlink = url_ticket + nt; 215 | } 216 | else{ 217 | ut = UpdateTicket(session); 218 | Zabbix.Log(4, '[GLPI Webhook] OK ticket: ' + ut); 219 | } 220 | 221 | 222 | KillSession(session); 223 | 224 | return JSON.stringify(result); 225 | } 226 | catch (error) { 227 | Zabbix.Log(4, '[GLPI Webhook] notification failed: ' + error); 228 | throw 'Sending failed: ' + error + '.'; 229 | } 230 | process_tags: 'YES' 231 | show_event_menu: 'YES' 232 | event_menu_url: '{EVENT.TAGS.zbx_glpi_ticketlink}' 233 | event_menu_name: 'GLPI:# {EVENT.TAGS.zbx_glpi_ticket}' 234 | description: | 235 | Develop by: Andrey Amado for AKA Sistemas 236 | Help: andreyamado@akasistemas.com 237 | License: GPLv2 238 | 239 | The documentation can be found on: 240 | https://yourglpirootlocation/apirest.php/ 241 | 242 | Additionally, you must enable the API access from glpi and activate the user authentication and app token. 243 | 244 | Adjust the parameters according to your installation. 245 | The "To" parameter must be the id_user from GLPI. 246 | 247 | V2 what is the new: 248 | - add update and close support ticket 249 | - add URL zabbix trigger into the ticket. 250 | 251 | 252 | message_templates: 253 | - 254 | event_source: TRIGGERS 255 | operation_mode: PROBLEM 256 | subject: 'Problem: {EVENT.NAME}' 257 | message: | 258 | Problem started at {EVENT.TIME} on {EVENT.DATE} 259 | Problem name: {EVENT.NAME} 260 | Host: {HOST.NAME} 261 | Severity: {EVENT.SEVERITY} 262 | Operational data: {EVENT.OPDATA} 263 | Original problem ID: {EVENT.ID} 264 | {TRIGGER.URL} 265 | - 266 | event_source: TRIGGERS 267 | operation_mode: UPDATE 268 | subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}' 269 | message: | 270 | {USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}. 271 | {EVENT.UPDATE.MESSAGE} 272 | 273 | Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}. 274 | 275 | - 276 | event_source: TRIGGERS 277 | operation_mode: RECOVERY 278 | subject: 'Resolved in {EVENT.DURATION}: {EVENT.NAME}' 279 | message: | 280 | Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE} 281 | Problem name: {EVENT.NAME} 282 | Problem duration: {EVENT.DURATION} 283 | Host: {HOST.NAME} 284 | Severity: {EVENT.SEVERITY} 285 | Original problem ID: {EVENT.ID} 286 | {TRIGGER.URL} 287 | Internal Message: {EVENT.UPDATE.MESSAGE} 288 | -------------------------------------------------------------------------------- /zbx_export_mediatypes_glpi.yaml: -------------------------------------------------------------------------------- 1 | zabbix_export: 2 | version: '5.2' 3 | date: '2021-02-13T23:09:49Z' 4 | media_types: 5 | - 6 | name: Glpi 7 | type: WEBHOOK 8 | parameters: 9 | 3: 10 | name: glpi_apptoken 11 | value: xxxxx 12 | 5: 13 | name: glpi_entities_id 14 | value: '1' 15 | 7: 16 | name: glpi_impact 17 | value: '3' 18 | 9: 19 | name: glpi_itilcategories_id 20 | value: '1' 21 | 2: 22 | name: glpi_password 23 | value: glpi 24 | 8: 25 | name: glpi_priority 26 | value: '3' 27 | 6: 28 | name: glpi_urgency 29 | value: '3' 30 | 4: 31 | name: glpi_url 32 | value: 'https://your_glpi_url/glpi/apirest.php/' 33 | 1: 34 | name: glpi_user 35 | value: glpi 36 | 0: 37 | name: HTTPProxy 38 | value: '' 39 | 10: 40 | name: Message 41 | value: '{ALERT.MESSAGE}' 42 | 11: 43 | name: Subject 44 | value: '{ALERT.SUBJECT}' 45 | 12: 46 | name: To 47 | value: '{ALERT.SENDTO}' 48 | script: | 49 | var params = JSON.parse(value); 50 | 51 | function GetSession(){ 52 | try{ 53 | var userpass = params.glpi_user + ':' + params.glpi_password; 54 | req = new CurlHttpRequest(); 55 | proxy = params.HTTPProxy; 56 | req.SetProxy(proxy); 57 | req.AddHeader('Content-Type: application/json'); 58 | req.AddHeader('Authorization: Basic '+ btoa(userpass)); 59 | req.AddHeader('App-Token: '+params.glpi_apptoken); 60 | resp = req.Get(params.glpi_url+'initSession'); 61 | 62 | if (req.Status() != 200) { 63 | Zabbix.Log(4, '[GLPI Webhook] login failed: ' + resp); 64 | throw 'Response: '+req.Status(); 65 | } 66 | resp = JSON.parse(resp); 67 | //throw(resp.session_token); 68 | return resp.session_token; 69 | 70 | } 71 | catch (error) { 72 | Zabbix.Log(4, '[GLPI Webhook] login failed: ' + error); 73 | throw 'Login failed: ' + error + '.'; 74 | } 75 | } 76 | 77 | function CreateTicket(session_token){ 78 | try{ 79 | req = new CurlHttpRequest(); 80 | fields = {}; 81 | proxy = params.HTTPProxy; 82 | req.SetProxy(proxy); 83 | req.AddHeader('Content-Type: application/json'); 84 | req.AddHeader('Session-Token: '+ session_token); 85 | req.AddHeader('App-Token: '+params.glpi_apptoken); 86 | fields.input = {"name": params.Subject ,"content": params.Message, "itilcategories_id": params.glpi_itilcategories_id,"entities_id":params.glpi_entities_id,"urgency":params.glpi_urgency,"impact":params.glpi_impact,"priority":params.glpi_priority,"_users_id_assign":params.To } 87 | resp = req.Post(params.glpi_url+'Ticket',JSON.stringify({"input":fields.input})); 88 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket response: ' + resp); 89 | 90 | if (req.Status() != 201) { 91 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + resp); 92 | throw 'Response: '+req.Status(); 93 | } 94 | 95 | 96 | } 97 | catch (error) { 98 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + error); 99 | throw 'CreateTicket failed: ' + error + '.'; 100 | } 101 | } 102 | 103 | function KillSession(session_token){ 104 | try{ 105 | req = new CurlHttpRequest(); 106 | proxy = params.HTTPProxy; 107 | req.SetProxy(proxy); 108 | req.AddHeader('Content-Type: application/json'); 109 | req.AddHeader('Session-Token: '+ session_token); 110 | req.AddHeader('App-Token: '+params.glpi_apptoken); 111 | resp = req.Get(params.glpi_url+'killSession'); 112 | Zabbix.Log(4, '[GLPI Webhook] KillSession response: ' + resp); 113 | 114 | if (req.Status() != 200) { 115 | Zabbix.Log(4, '[GLPI Webhook] KillSession failed: ' + resp); 116 | throw 'Response: '+req.Status(); 117 | } 118 | } 119 | catch (error) { 120 | Zabbix.Log(4, '[GLPI Webhook] KillSession failed: ' + error); 121 | throw 'KillSession failed: ' + error + '.'; 122 | } 123 | } 124 | 125 | try { 126 | if (params.glpi_user === "") { 127 | throw 'Incorrect value is given for parameter "glpi_user": parameter is missing'; 128 | } 129 | if (params.glpi_password === "") { 130 | throw 'Incorrect value is given for parameter "password": parameter is missing'; 131 | } 132 | if (params.glpi_apptoken === "") { 133 | throw 'Incorrect value is given for parameter "glpi_apptoken": parameter is missing'; 134 | } 135 | if (params.glpi_url === "") { 136 | throw 'Incorrect value is given for parameter "glpi_url": parameter is missing'; 137 | } 138 | session = GetSession(); 139 | Zabbix.Log(4, '[GLPI Webhook] Login OK session_token: ' + resp); 140 | CreateTicket(session); 141 | KillSession(session); 142 | 143 | return "OK"; 144 | } 145 | catch (error) { 146 | Zabbix.Log(4, '[GLPI Webhook] notification failed: ' + error); 147 | throw 'Sending failed: ' + error + '.'; 148 | } 149 | description: | 150 | Develop by: Andrey Amado for AKA Sistemas 151 | Help: andreyamado@akasistemas.com 152 | 153 | The documentation can be found on: 154 | https://yourglpirootlocation/apirest.php/ 155 | 156 | Additionally, you must enable the API access from glpi and activate the user authentication and app token. 157 | 158 | Adjust the parameters according to your installation. 159 | The "To" parameter must be the id_user from GLPI. 160 | 161 | message_templates: 162 | - 163 | event_source: TRIGGERS 164 | operation_mode: PROBLEM 165 | subject: 'Problem: {EVENT.NAME}' 166 | message: | 167 | Problem started at {EVENT.TIME} on {EVENT.DATE} 168 | Problem name: {EVENT.NAME} 169 | Host: {HOST.NAME} 170 | Severity: {EVENT.SEVERITY} 171 | Operational data: {EVENT.OPDATA} 172 | Original problem ID: {EVENT.ID} 173 | {TRIGGER.URL} 174 | -------------------------------------------------------------------------------- /zbx_export_mediatypes_v6.4.yaml: -------------------------------------------------------------------------------- 1 | zabbix_export: 2 | version: '6.4' 3 | media_types: 4 | - name: Glpi 5 | type: WEBHOOK 6 | parameters: 7 | - name: Event_Update_Status 8 | value: '{EVENT.UPDATE.STATUS}' 9 | - name: Event_Value 10 | value: '{EVENT.VALUE}' 11 | - name: glpi_apptoken 12 | value: CHANGE-ME 13 | - name: glpi_event_id 14 | value: '{EVENT.ID}' 15 | - name: glpi_event_severity 16 | value: '{EVENT.NSEVERITY}' 17 | - name: glpi_event_update_mess 18 | value: '{EVENT.UPDATE.MESSAGE}' 19 | - name: glpi_password 20 | value: CHANGE-ME 21 | - name: glpi_tgrid 22 | value: '{TRIGGER.ID}' 23 | - name: glpi_ticket_id 24 | value: '{EVENT.TAGS.zbx_glpi_ticket}' 25 | - name: glpi_url 26 | value: CHANGE-ME 27 | - name: glpi_user 28 | value: glpi 29 | - name: glpi_user_token 30 | value: CHANGE-ME 31 | - name: HTTPProxy 32 | - name: Message 33 | value: '{ALERT.MESSAGE}' 34 | - name: Subject 35 | value: '{ALERT.SUBJECT}' 36 | - name: To 37 | value: '{ALERT.SENDTO}' 38 | - name: zb_web_url 39 | value: CHANGE-ME 40 | script: | 41 | var params = JSON.parse(value), 42 | result = { tags: {} }; 43 | var url_api = params.glpi_url + "apirest.php/"; 44 | var url_ticket = params.glpi_url + "front/ticket.form.php?id="; 45 | 46 | function GetSession() { 47 | try { 48 | var userpass = params.glpi_user + ':' + params.glpi_password; 49 | var user_token = params.glpi_user_token; 50 | var fullUrl = url_api + 'initSession' + '?app_token=' + encodeURIComponent(params.glpi_apptoken) + '&user_token=' + encodeURIComponent(user_token); 51 | req = new HttpRequest(); 52 | proxy = params.HTTPProxy; 53 | req.setProxy(proxy); 54 | req.addHeader('Content-Type', 'application/json'); 55 | resp = req.get(fullUrl); 56 | 57 | if (req.getStatus() != 200) { 58 | Zabbix.log(4, '[GLPI Webhook] login failed: ' + resp); 59 | throw 'Response: ' + req.getStatus(); 60 | } 61 | resp = JSON.parse(resp); 62 | return resp.session_token; 63 | 64 | } catch (error) { 65 | Zabbix.log(4, '[GLPI Webhook] login failed: ' + error); 66 | throw 'Login failed: ' + error + '.'; 67 | } 68 | } 69 | 70 | 71 | function CreateTicket(session_token) { 72 | try { 73 | req = new HttpRequest(); 74 | fields = {}; 75 | proxy = params.HTTPProxy; 76 | req.setProxy(proxy); 77 | req.addHeader('Content-Type: application/json'); 78 | req.addHeader('Session-Token:' + session_token); 79 | req.addHeader('App-Token:' + params.glpi_apptoken); 80 | fields.input = { 81 | "name": params.Subject, 82 | "content": params.Message + "URL_EVENT: " + params.zb_web_url + "tr_events.php?triggerid=" + params.glpi_tgrid + "&eventid=" + params.glpi_event_id, 83 | "itilcategories_id": params.glpi_itilcategories_id, 84 | "entities_id": params.glpi_entities_id, 85 | "urgency": params.glpi_urgency, 86 | "impact": params.glpi_impact, 87 | "priority": params.glpi_priority, 88 | "_users_id_assign": params.To 89 | }; 90 | 91 | resp = req.post(url_api + 'Ticket', JSON.stringify({ "input": fields.input })); 92 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket response: ' + resp); 93 | resp = JSON.parse(resp); 94 | return resp.id; 95 | } catch (error) { 96 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + error); 97 | throw 'CreateTicket failed: ' + error + '.'; 98 | } 99 | } 100 | 101 | function UpdateTicket(session_token) { 102 | try { 103 | req = new HttpRequest(); 104 | fields = {}; 105 | proxy = params.HTTPProxy; 106 | req.setProxy(proxy); 107 | req.addHeader('Content-Type: application/json'); 108 | req.addHeader('Session-Token:' + session_token); 109 | req.addHeader('App-Token:' + params.glpi_apptoken); 110 | 111 | if (params.Event_Value === '0') { 112 | fields.input = { "itemtype": "Ticket", "items_id": params.glpi_ticket_id, "content": params.Message }; 113 | resp = req.post(url_api + 'Ticket/' + params.glpi_ticket_id + "/ITILSolution", JSON.stringify({ "input": fields.input })); 114 | } else { 115 | fields.input = { "itemtype": "Ticket", "items_id": params.glpi_ticket_id, "content": params.Message }; 116 | resp = req.post(url_api + 'Ticket/' + params.glpi_ticket_id + "/ITILFollowup", JSON.stringify({ "input": fields.input })); 117 | } 118 | 119 | Zabbix.Log(4, '[GLPI Webhook] UpdateTicket response: ' + resp); 120 | resp = JSON.parse(resp); 121 | tikedid = params.glpi_ticket_id; 122 | return resp.tikedid; 123 | } catch (error) { 124 | Zabbix.Log(4, '[GLPI Webhook] CreateTicket failed: ' + error); 125 | throw 'CreateTicket failed: ' + error + '.'; 126 | } 127 | 128 | } 129 | 130 | function KillSession(session_token) { 131 | try { 132 | req = new HttpRequest(); 133 | proxy = params.HTTPProxy; 134 | req.setProxy(proxy); 135 | req.addHeader('Content-Type: application/json'); 136 | req.addHeader('Session-Token:' + session_token); 137 | req.addHeader('App-Token:' + params.glpi_apptoken); 138 | resp = req.get(url_api + 'killSession'); 139 | Zabbix.Log(4, '[GLPI Webhook] KillSession response: ' + resp); 140 | 141 | if (req.getStatus() != 200) { 142 | Zabbix.Log(4, '[GLPI Webhook] KillSession failed: ' + resp); 143 | throw 'Response: ' + req.getStatus(); 144 | } 145 | } catch (error) { 146 | Zabbix.Log(4, '[GLPI Webhook] KillSession failed: ' + error); 147 | throw 'KillSession failed: ' + error + '.'; 148 | } 149 | } 150 | 151 | 152 | try { 153 | if (params.glpi_user === "") { 154 | throw 'Incorrect value is given for parameter "glpi_user": parameter is missing'; 155 | } 156 | if (params.glpi_password === "") { 157 | throw 'Incorrect value is given for parameter "password": parameter is missing'; 158 | } 159 | if (params.glpi_apptoken === "") { 160 | throw 'Incorrect value is given for parameter "glpi_apptoken": parameter is missing'; 161 | } 162 | if (params.glpi_url === "") { 163 | throw 'Incorrect value is given for parameter "glpi_url": parameter is missing'; 164 | } 165 | session = GetSession(); 166 | Zabbix.log(4, '[GLPI Webhook] Login OK session_token: ' + session); 167 | 168 | if (params.Event_Value === '1' && params.Event_Update_Status === '0') { 169 | nt = CreateTicket(session); 170 | Zabbix.log(4, '[GLPI Webhook] OK ticket: ' + nt); 171 | result.tags.zbx_glpi_ticket = nt; 172 | result.tags.zbx_glpi_ticketlink = url_ticket + nt; 173 | } else { 174 | ut = UpdateTicket(session); 175 | Zabbix.log(4, '[GLPI Webhook] OK ticket: ' + ut); 176 | } 177 | 178 | KillSession(session); 179 | 180 | return JSON.stringify(result); 181 | } catch (error) { 182 | Zabbix.log(4, '[GLPI Webhook] notification failed: ' + error); 183 | throw 'Sending failed: ' + error + '.'; 184 | } 185 | process_tags: 'YES' 186 | show_event_menu: 'YES' 187 | event_menu_url: '{EVENT.TAGS.zbx_glpi_ticketlink}' 188 | event_menu_name: 'GLPI:# {EVENT.TAGS.zbx_glpi_ticket}' 189 | description: | 190 | Develop by: Andrey Amado for AKA Sistemas 191 | Help: andreyamado@akasistemas.com 192 | License: GPLv2 193 | 194 | The documentation can be found on: 195 | https://yourglpirootlocation/apirest.php/ 196 | 197 | Additionally, you must enable the API access from glpi and activate the user authentication and app token. 198 | 199 | Adjust the parameters according to your installation. 200 | The "To" parameter must be the id_user from GLPI. 201 | 202 | V2 what is the new: 203 | - add update and close support ticket 204 | - add URL zabbix trigger into the ticket. 205 | - V6.4 support by empereira (https://github.com/empereira) 206 | message_templates: 207 | - event_source: TRIGGERS 208 | operation_mode: PROBLEM 209 | subject: 'Problem: {EVENT.NAME}' 210 | message: | 211 | Problem started at {EVENT.TIME} on {EVENT.DATE} 212 | Problem name: {EVENT.NAME} 213 | Host: {HOST.NAME} 214 | Severity: {EVENT.SEVERITY} 215 | Operational data: {EVENT.OPDATA} 216 | Original problem ID: {EVENT.ID} 217 | {TRIGGER.URL} 218 | - event_source: TRIGGERS 219 | operation_mode: RECOVERY 220 | subject: 'Resolved in {EVENT.DURATION}: {EVENT.NAME}' 221 | message: | 222 | Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE} 223 | Problem name: {EVENT.NAME} 224 | Problem duration: {EVENT.DURATION} 225 | Host: {HOST.NAME} 226 | Severity: {EVENT.SEVERITY} 227 | Original problem ID: {EVENT.ID} 228 | {TRIGGER.URL} 229 | Internal Message: {EVENT.UPDATE.MESSAGE} 230 | - event_source: TRIGGERS 231 | operation_mode: UPDATE 232 | subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}' 233 | message: | 234 | {USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}. 235 | {EVENT.UPDATE.MESSAGE} 236 | 237 | Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}. 238 | --------------------------------------------------------------------------------