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 2024-03-27 11:30:52

tobrein
Member
Registered: 2024-03-27
Posts: 5

rules actions external command or url

hello,

is it possible in the rules in the action set to execute an url or external command ?
For example when the rule criteria "valiation is granted" than as action to execute an ansible automation platform api to create a new VM.

Or how can I execute an external command/url when a ticket approval is granted ?

best regards
TobRein

Offline

#2 2024-03-27 11:47:08

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

Re: rules actions external command or url

No. You would need to create a custom plugin for that.
We do have "Workflows/BPMN" on the roadmap, but I don't have any other news besides that on this subject.


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

#3 2024-03-28 16:57:12

tobrein
Member
Registered: 2024-03-27
Posts: 5

Re: rules actions external command or url

hello,

here is my quick and realy dirty solution for that.

#1 create an extra column in the glpi_tickets table for the state that the extra command if it is started
#2 filter all granted ticktes and some extra information from the ticket text e.g. hostname and operation system
#3 than start the external command e.g. an Ansible Automation Platform Workflow with the filtered parameter from the ticket (hostname and operating system)
#4 set the state in the extra colum to true if the command is finished

here the bash script for example

#!/bin/bash
#set -x
#SQL command to create an extra column in the glpi_tickets table
#ALTER TABLE glpi.glpi_tickets ADD ansible_workflow_started INT DEFAULT 0 NULL;
#Filter OS and hostname form granetd tickets
operating_system=$(/usr/local/mariadb/bin/mariadb -u root -p123 -e "use glpi; select * from glpi_tickets where name='vm_order' and global_validation='3' and ansible_workflow_started='0' limit 1;"  | awk -F ";"  '{print $15}' | awk -F "&#60" '{print $1 }' )
hostname=$(/usr/local/mariadb/bin/mariadb -u root -p123 -e "use glpi; select * from glpi_tickets where name='vm_order' and global_validation='3' and ansible_workflow_started='0' limit 1;"  | awk -F ";"  '{print $23}' | awk -F "&#60" '{print $1 }')
#echo $operating_system
#echo $hostname
#Start Ansible Automation Platform Workflow after approval is given in glpi
curl -X POST --user root:123 -k -H 'Content-Type: application/json' https://<aap-server>/api/v2/workflow_job_templates/22/launch/ -d '{"extra_vars":{"aap_host_fqdn":"$hostname","aap_os":"$operating_system"}}' | jq .
#Set ansible_workflow_started to 1
/usr/local/mariadb/bin/mariadb -u root -p123 -e "use glpi; update glpi_tickets SET ansible_workflow_started='1' where name='vm_order' and global_validation='3' and ansible_workflow_started='0' limit 1;"

than let the script run every 10 seconds in the systemd timer.

this is a very static solution but it works for me. Maby some other can adopt this soltion to make a more flexible and nicer solution.

Best regards
TobRein

Offline

Board footer

Powered by FluxBB