We use a custom web-form to create our tickets in otrs (the form sends them by mail to otrs). That works well but we still missed the automatic link between the users computer (CMDB CI) to the ticket. I solved this on a very, very dirty and inefficient way using PHP and linking directly in the database bypassing the api. I hate myself for that, but what i even hate more is, to code with perl.
This is not the best practive way...miles away from it. But i will anyway show it to you.
What we do is basicly this:
Where does the computer name come from?
Our custom web-form contains a hidden field called "Computer Name", this field is filled by another system (baramundi), every time a user loads the form on his/her client pc. The Names are mostly similar to the names of our CMDB Computer CIs in Otrs.
Setting up the generic agent and the script
- On the Linux Server I created a folder /opt/otrs/phpscripts/
- Then I created a simple Generic Agent that triggers on the "TicketCreate" event.
- The Script is called in the CMD field (section run ticket command) of the Generic agent: /usr/bin/php /opt/otrs/phpscripts/link_ticket_rid_to_computer_ci.php
I placed my php scripts in the /opt/otrs/phpscripts/ directory:
mysql stored procedure create script
What does the Database stored procedure do?
Stored procedures are encapsulated SQL commands that makes it more easy to handle SQL execution. I've made two of them:
This one reads and returns the value of a dynamic field attached to a ticket.
link_cmdb_ci_computer_to_ticket(in_ticket_id, in_rid_nr, in_user_name)
That one checks if the user exists (a link has to be assigned to a otrs user), tries to find the CI name, checks if the CI may be already linked to the ticket, and if all this is given, creates the link in the otrs table.
The php creates a nice log
After creating a Ticket by our form, the CI Computer is linked by the script
Okay folks, now you learned how NOT to do it. Maybe it helps someone of you for own projects...