-----Original Message-----
From: Gary Rule [mailto:grule@bbn.com]
Sent: Monday, September 08, 2003 2:03 PM
To: rt-users@lists.fsck.com
Subject: [rt-users] Custom Scrip
Hello,
I’m looking for either a scrip to notify a particular
email address when a new ticket his the queue or a good place
with documentation on how to write custom scrips.
Basically I want an email to go to our department email list
when a new ticket is generated. I’m assuming to write this
myself I will need to whip up some perl but I’m not sure how
involved it will be. Are there any resources out there for
beginning scrip writers?
[…]
I recently asked a similar question (except I want to send a stipped
down template to a pager’s email address) and it was suggested that I
use AdminCC. For me, that won’t work, as I’m using both CC’s and
AdminCC’s for other purposes.
Hopefully someone can answer this question…I’m sure more than just
the two of us could use this information.
Daryl
I won’t directly answer it, but I’ll post some code that should do the
trick with some modifications.
Problem: I needed to autoassign tickets to individuals based on a
CustomField (eg: Server, Desktop, VPN, Phone System, etc…). So I wrote
this… it seems to work okay for us on 3 queues. RT 3.0.3
Description: AutoAssign
Condition: On Create
Custom Condition:
Action: User Defined
Custom action preparation code:
my $retval = undef;
if ( defined( $self->TicketObj->OwnerObj->id ) ){
# Only change tickets where ID is not already set - eg: New Tickets
if( $self->TicketObj->OwnerObj->Id == $RT::Nobody->Id ){
$RT::Logger->info(“AutoAssign: New Ticket with no owner - Autoassigning”);
$retval = 1;
}
}
return ($retval);
Custom action cleanup code:
use RT::Ticket;
use RT::User;
use RT::CustomField;
use RT::AutoAssign;
my $retval = undef;
my $handle = DBIx::SearchBuilder::Handle->new();
Change to your DB info. Should probably rewrite to pull from
RT_SiteConfig.pm - patches welcome.
$handle->Connect( ‘Driver’ => ‘mysql’,‘Database’ => ‘rt3’,
‘Host’ => ‘localhost’, ‘User’ => ‘rt_user’,‘Password’ => ‘rt_pass’);
my $s = new AutoAssign($handle);
Get the list of Custom Fields
my $CustomFields = $self->TicketObj->QueueObj->CustomFields();
Use the 1st field for our purposes
my $CustomField = $CustomFields->Next();
List of value of the custom field.
my $Values = $self->TicketObj->CustomFieldValues($CustomField->id);
List of valid values for this custom field
my $CustomFieldValues = $CustomField->Values();
my $assigned = 0;
Cycle through possible values…
while (my $value = $CustomFieldValues->Next) {
# If we match up…
if ($Values->HasEntry($value->Name)) {
# Do stuff
my $name = $value->Name;
my $id = $value->id;
$s->LoadByCol(‘SubQueueid’, $id);
$retval = $self->TicketObj->SetOwner($s->Userid());
$RT::Logger->info(“AutoAssign: Result code is $retval”);
$assigned = 1;
}
}
if ($assigned != 1) {
# AutoAssign to dlaskey (67) for no match
$retval = $self->TicketObj->SetOwner(67);
$RT::Logger->info(“AutoAssign: Result code is $retval”);
}
return ($retval);
Template: Global Template: Blank
I’ve got a module (AutoAssign.pm) defined to describe the table I used,
which is basically just Users.id → CustomFieldValues.id mapping. Email
me if you want/need a copy - it’s a bit uglier that I’d like to admit
For your needs, just change the CleanUp Code to like:
$retval = $self->TicketObj->AddWatcher(Type => ‘Cc’, Email => ‘user@host.com’)
Or if, as you indicated you can’t use the AdminCCm and just want a one-off
email, then:
use RT::Action::SendEmail;
and then run perldoc /opt/rt3/lib/RT/Actions/SendEmail.pm to see the
functions to set the To/CC/Subject/Content etc…
Ken