Linking CMDB CI to new Ticket - the dirty way...

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Forum rules
Dont create your support topics here! No new topics with questions allowed!
Post Reply
ElectricDreams
Znuny newbie
Posts: 36
Joined: 07 Sep 2016, 16:15
Znuny Version: 5.0.13
Real Name: Christian Moeller
Company: Prüfinstitut Hansecontrol
Location: Hamburg
Contact:

Linking CMDB CI to new Ticket - the dirty way...

Post by ElectricDreams »

Hey folks,
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:
Image

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

My Scripts
I placed my php scripts in the /opt/otrs/phpscripts/ directory:
link_ticket_rid_to_computer_ci.php
functions.php
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:
get_ticket_dynamic_field_value(in_ticket_id, in_dynamic_field_name)
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 Log
The php creates a nice log
Image

The Result
After creating a Ticket by our form, the CI Computer is linked by the script
Image

Okay folks, now you learned how NOT to do it. Maybe it helps someone of you for own projects...
have fun
Ein Dosenfisch stürzt sich lachend ins offene Meer
gecelann
Znuny expert
Posts: 164
Joined: 12 Feb 2016, 08:05
Znuny Version: 5.0.0
Real Name: ann
Company: rghdinc

Re: Linking CMDB CI to new Ticket - the dirty way...

Post by gecelann »

ElectricDreams wrote:Hey folks,
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:
Image

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

My Scripts
I placed my php scripts in the /opt/otrs/phpscripts/ directory:
link_ticket_rid_to_computer_ci.php
functions.php
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:
get_ticket_dynamic_field_value(in_ticket_id, in_dynamic_field_name)
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 Log
The php creates a nice log
Image

The Result
After creating a Ticket by our form, the CI Computer is linked by the script
Image

Okay folks, now you learned how NOT to do it. Maybe it helps someone of you for own projects...
have fun
Hi!

Can it be possible call the php file on the [ Link ticket ] ?
just like replacing the a href? sample. /otrs/HelloWorld.php
I'm currently testing it and it is not working tho in var/www/HelloWorld.php is working.

another question is did you create dynamicfield in ticketcreation?
is it just a textfield? or dropdown? please give me some advice.
It is more easy to call it in php rather making another module on perl program :(
I don't know how to code in perl, but if it is a new link do i really need to publish it on a sopm? :(
Post Reply