Monday, January 31, 2011

RT Change Queue when Ticket Reaches Final Priority

Where I work, we use RT for our ticketing system.  Previously we had only about 12 or so queues that ran a priority from 1 to 100.  More recently we changed to a tiered or leveled approach.  That is each queue, now has three tiers such as Antivirus L1, L2, L3 or Networking L1, L2, L3.  However, I needed each ticket in a given queue to automatically move from L1 to L2 or L2 to L3 when the final priority for that level was reached.  I should not I am using rt-crontool to adjust the tickets priority, such as the following example illustrates:
/usr/local/bin/rt-crontool --verbose --search RT::Search::FromSQL --search-arg "Queue = 'Antivirus L1' AND (Status = 'new')" --action RT::Action::EscalatePriority --transaction last
So for each L1 and L2 Queue I have I made a scrip with the following conditions:
Description:
Condition:
Action:
Template:
Stage:

You will want to change the name-of-queue to whatever your queue is called.

Custom Action Preparation Code:
my $status = $self->;TicketObj->;Status;
my $final = $self->;TicketObj->;FinalPriority;
my $priority = $self->;TicketObj->;Priority;
return 0 unless $self->;TransactionObj->;Field eq 'Priority';
return 0 unless $status eq 'open' || $status eq 'new' || $status eq 'stalled';
return 0 unless $final >; 0;
return 0 unless $final == $priority;
return 1;

Custom Action Cleanup code:
my $newqueue = "#";
my $final = $self->;TicketObj->;FinalPriority;
my $priority = $self->;TicketObj->;Priority;
my $T_Obj = $self->;TicketObj;

$RT::Logger->;info("Auto assign ticket #". $T_Obj->;id ." to queue #". $newqueue );
my ($status, $msg) = $T_Obj->;SetQueue($newqueue);
unless ($status) {
$RT::Logger->;warning("unable to set new queue: $msg");
return undef;
}
$RT::Logger->;info("Change Ticket Priority ". $T_Obj->;id ." to ". "#" );
my ($status, $msg) = $T_Obj->;SetPriority("#");
unless ($status) {
$RT::Logger->;warning("unable to set new priority: $msg");
return undef;
}
$RT::Logger->;info("Change Final Priority ". $T_Obj->;id ." to ". "#" );
my ($status, $msg) = $T_Obj->;SetFinalPriority("#");
unless ($status) {
$RT::Logger->;warning("unable to set new final priority: $msg");
return undef;
}
return 1;

You will of course want to replace the Queue # and Priority # with the actual number of the new queue and new base and final priority settings.

This can be very tedious to setup for each and every queue, but it seems to work for me and I am sure it can work for you too!