Re: [rt-users] Using RT::Template with MIMEObj to create a new ticket using -Create()

2013-09-16 Thread Landon Stewart
On 14 September 2013 13:19, Ruslan Zakirov r...@bestpractical.com wrote:

 I don't understand your problem here. You have an incident and want to
 create an investigation with a scrip using a template. Templates are used
 here so you don't have to change code every time you to change a word or
 add a new particular text for such investigations.

 Here what you do:

 1) scrip is executed when something happens with an Incident, so
 $self-TicketObj is an Incident
 2) You take Incident's props and use them to generate template name
 3) You load template and Parse it, providing as much context as possible
 to the template

 Here is fun part - RT doesn't care what you pass into template. You can
 probably even skip all arguments and if your template is capable to work
 without arguments then it will work.

 4) Template can have code embedded, so it can use provided context (in
 your case Incident) to fill in dynamic details.
 5) Template should not change anything, but format some result
 6) After parsing you get MIMEObj based on existing Incident, IRs, watchers
 of these tickets, CFs, transactions...
 7) You complete this MIMEObj with additional data and these actions can be
 controlled from templates, for example whether IRs's replies should be
 attached to the Investigation or not can be controlled by 'RTIR-Attach-IRs:
 yes' header (this is exactly what RT does in notification scrips)
 8) Once MIMEObj is complete you create your investigation ticket


Thank you very much for this breakdown of the process.  I've re-worked
things and I'm relying on the Scrip for the Investigations queue that
applies the template to apply it now.  I was trying to do it before hand
thinking that the Scrips would not fire when creating the ticket using a
Scrip/Action module.  Nevertheless it does and a lot of things were cleaned
up and made much easier than I thought they'd be.

Thanks again

-- 
Landon Stewart :: lstew...@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932

-- 
RT Training in New York, October 8th and 9th: http://bestpractical.com/training

Re: [rt-users] Using RT::Template with MIMEObj to create a new ticket using -Create()

2013-09-14 Thread Ruslan Zakirov
On Fri, Sep 13, 2013 at 9:16 PM, Landon Stewart lstew...@iweb.com wrote:

 This was originally posted to the RTIR list but I'm x-posting it here
 because it's not specific to RTIR and I'm still having difficulties.

 I've been unable to figure out how to call an action module from another
 action module but instead I've been working on an action module that
 basically:
 - gets called on an Incident (and uses the create and correspond
 transactions to open a new Investigations ticket)
 - attaches the Incident Reports linked to that Incident to the
 Investigation…

 I have it creating a ticket although I haven't filled in much of the
 CustomFields I'll need to I cannot get it to use a template for some
 reason.

 Specifically the LoadQueueTemplate() and Parse() a bit of a mystery to me.


 Example:
 $templateObj-LoadQueueTemplate( Queue = Investigations, Name =
 $classification. (en) );
 my($ret, $msg) = $templateObj-Parse( TicketObj = $new_ticket,
 TransactionObj = $self-TransactionObj );

 I am building a MIME::Entity above this called $MIMEObj including all the
 attachments etc but I don't understand how to get Parse() to to do
 something to the MIMEObj to get the MIME::Entity-build( Data = … ) to
 use the template.  Also the attachments are coming out in-line in the
 message instead of attachments but that's probably because the
 RT-Attach-Message: yes header is in the template that's not being used if
 I'm understanding the use of that header correctly.


You should go other way around. After calling $template-Parse you call
$template-MIMEObj and get MIME::Entity representing result of the
template. You then can update this entity with attachments, more headers
and so on.

RT-Attach-Message: yes header is checked by notification scrip, so it
should be in notification template, not in template which you use to
generate content.


 A more full representation of the code is here:
 http://pastebin.com/QF2tbZqH

 Thanks to anyone who has an idea of what I'm missing or doing wrong here
 and might have some ideas for me.

 --
 Landon Stewart :: lstew...@iweb.com
 Lead Specialist, Abuse and Security Management
 Spécialiste principal, gestion des abus et sécurité
 http://iweb.com :: +1 (888) 909-4932




 --
 RT Training in New York, October 8th and 9th:
 http://bestpractical.com/training




-- 
Best regards, Ruslan.

-- 
RT Training in New York, October 8th and 9th: http://bestpractical.com/training

Re: [rt-users] Using RT::Template with MIMEObj to create a new ticket using -Create()

2013-09-14 Thread Landon Stewart
On 14 September 2013 00:19, Ruslan Zakirov r...@bestpractical.com wrote:

 You should go other way around. After calling $template-Parse you call
 $template-MIMEObj and get MIME::Entity representing result of the
 template. You then can update this entity with attachments, more headers
 and so on.


Hi Ruslan,

Thanks for your reply.  I've just tried this but now I'm wondering where I
get the TicketObj and TransactionObj arguments for $template-Parse.  If I
use the Incident's TicketObj and TransactionObj it actually modifies the
Incident's subject.

I cannot put the $new_ticket-Create(…) before the $template-Parse because
RT::Ticket-Create requires a MIMEObj produced by $template-Parse in
$template-MIMEObj.  It's a chicken vs. egg issue here I think.  I must be
missing something but I don't know what.  I also tried putting the my
$new_ticket = RT::Ticket-new($RT::SystemUser) above the template but
leave the Create below but I'm still left with no TransactionObj to use
because it's generated by RT::Ticket-Create(…).

I've pasted a new version of my code at http://pastebin.com/UvnUC221.  This
version modifies the subject of the Incident ($self).

-- 
Landon Stewart :: lstew...@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932

-- 
RT Training in New York, October 8th and 9th: http://bestpractical.com/training

Re: [rt-users] Using RT::Template with MIMEObj to create a new ticket using -Create()

2013-09-14 Thread Ruslan Zakirov
On Sat, Sep 14, 2013 at 11:58 PM, Landon Stewart lstew...@iweb.com wrote:

 On 14 September 2013 00:19, Ruslan Zakirov r...@bestpractical.com wrote:

 You should go other way around. After calling $template-Parse you call
 $template-MIMEObj and get MIME::Entity representing result of the
 template. You then can update this entity with attachments, more headers
 and so on.


 Hi Ruslan,

 Thanks for your reply.  I've just tried this but now I'm wondering where I
 get the TicketObj and TransactionObj arguments for $template-Parse.  If I
 use the Incident's TicketObj and TransactionObj it actually modifies the
 Incident's subject.

 I cannot put the $new_ticket-Create(…) before the $template-Parse
 because RT::Ticket-Create requires a MIMEObj produced by $template-Parse
 in $template-MIMEObj.  It's a chicken vs. egg issue here I think.  I must
 be missing something but I don't know what.  I also tried putting the my
 $new_ticket = RT::Ticket-new($RT::SystemUser) above the template but
 leave the Create below but I'm still left with no TransactionObj to use
 because it's generated by RT::Ticket-Create(…).



I don't understand your problem here. You have an incident and want to
create an investigation with a scrip using a template. Templates are used
here so you don't have to change code every time you to change a word or
add a new particular text for such investigations.

Here what you do:

1) scrip is executed when something happens with an Incident, so
$self-TicketObj is an Incident
2) You take Incident's props and use them to generate template name
3) You load template and Parse it, providing as much context as possible to
the template

Here is fun part - RT doesn't care what you pass into template. You can
probably even skip all arguments and if your template is capable to work
without arguments then it will work.

4) Template can have code embedded, so it can use provided context (in your
case Incident) to fill in dynamic details.
5) Template should not change anything, but format some result
6) After parsing you get MIMEObj based on existing Incident, IRs, watchers
of these tickets, CFs, transactions...
7) You complete this MIMEObj with additional data and these actions can be
controlled from templates, for example whether IRs's replies should be
attached to the Investigation or not can be controlled by 'RTIR-Attach-IRs:
yes' header (this is exactly what RT does in notification scrips)
8) Once MIMEObj is complete you create your investigation ticket

I don't see any chickenegg problem here. Do you?


 I've pasted a new version of my code at http://pastebin.com/UvnUC221.
  This version modifies the subject of the Incident ($self).

 --
 Landon Stewart :: lstew...@iweb.com
 Lead Specialist, Abuse and Security Management
 Spécialiste principal, gestion des abus et sécurité
 http://iweb.com :: +1 (888) 909-4932





-- 
Best regards, Ruslan.

-- 
RT Training in New York, October 8th and 9th: http://bestpractical.com/training

[rt-users] Using RT::Template with MIMEObj to create a new ticket using -Create()

2013-09-13 Thread Landon Stewart
This was originally posted to the RTIR list but I'm x-posting it here
because it's not specific to RTIR and I'm still having difficulties.

I've been unable to figure out how to call an action module from another
action module but instead I've been working on an action module that
basically:
- gets called on an Incident (and uses the create and correspond
transactions to open a new Investigations ticket)
- attaches the Incident Reports linked to that Incident to the
Investigation…

I have it creating a ticket although I haven't filled in much of the
CustomFields I'll need to I cannot get it to use a template for some
reason.

Specifically the LoadQueueTemplate() and Parse() a bit of a mystery to me.

Example:
$templateObj-LoadQueueTemplate( Queue = Investigations, Name =
$classification. (en) );
my($ret, $msg) = $templateObj-Parse( TicketObj = $new_ticket,
TransactionObj = $self-TransactionObj );

I am building a MIME::Entity above this called $MIMEObj including all the
attachments etc but I don't understand how to get Parse() to to do
something to the MIMEObj to get the MIME::Entity-build( Data = … ) to
use the template.  Also the attachments are coming out in-line in the
message instead of attachments but that's probably because the
RT-Attach-Message: yes header is in the template that's not being used if
I'm understanding the use of that header correctly.

A more full representation of the code is here:
http://pastebin.com/QF2tbZqH

Thanks to anyone who has an idea of what I'm missing or doing wrong here
and might have some ideas for me.

-- 
Landon Stewart :: lstew...@iweb.com
Lead Specialist, Abuse and Security Management
Spécialiste principal, gestion des abus et sécurité
http://iweb.com :: +1 (888) 909-4932

-- 
RT Training in New York, October 8th and 9th: http://bestpractical.com/training