[rt-users] round-robin auto assignment?

Asif Iqbal vadud3 at gmail.com
Thu Oct 22 16:21:07 EDT 2015


On Thu, Oct 22, 2015 at 11:12 AM, Asif Iqbal <vadud3 at gmail.com> wrote:

>
>
> On Fri, Apr 12, 2013 at 2:22 PM, Thomas Sibley <trs at bestpractical.com>
> wrote:
>
>> On 04/12/2013 11:06 AM, Doug Eubanks wrote:
>> > I apologize, but Perl isn't my strong suit.  :D
>> >
>> > Changing those three lines still compiles and updates the scrip, but it
>> > doesn't do anything and never assigns the ticket to anyone now.
>>
>> Oh, I see, the previous code was trying to set the owner as the next
>> user in the array (but may have set an undef owner if the current owner
>> was the last one in the array).
>>
>> I think you'll need to update the code to set $new_owner to the next
>> owner instead of a random one.  I haven't fully read the scrip though,
>> so there may be an underlying more fundamental problem.
>>
>
>
> I were able to get it working with modulo. Here is the complete scrip we
> are running since today and so far looks good. Any suggestion is welcome to
> improve it.
>
> I used modulo to pick the next owner. Besides that rest of the code is
> from http://requesttracker.wikia.com/wiki/AutoSetOwner
>
> Description: Auto assign ticket on create
> Condition: On Create
> Action: User Defined
> Template: Global template: Blank
> Stage: TransactionCreate
>
> Custom condition: return 1;
> Custom action preparation code: return 1;
> Custom action cleanup code:
> # get out if ticket has a owner
> return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;
>
> # gather the list of owners
> my @owners = qw(
> foo
> bar
> qaz
> );
>
> # get a count for the owners
> my $totmembers = scalar( @owners );
>
> # get this ticket id
> my $ticket_id = $self->TicketObj->id;
>
> # ticket_id modulo totmembers to pick the next owner
> my $x =  $ticket_id % $totmembers;
> my $owner = $owners[$x];
>
> # set the owner
> $RT::Logger->info("Auto assign ticket ". $self->TicketObj->id ." to user
> ". $owner );
> my ($status, $msg) = $self->TicketObj->SetOwner( $owner );
> unless( $status ) {
>     $RT::Logger->error( "Impossible to assign the ticket to $owner: $msg"
> );
>     return undef;
> }
> return 1;
>
>

some change in the cleanup code

# if you want to disable it, just uncomment the following line
# return 1;

# get out if ticket has a owner
return 1 unless $self->TicketObj->Owner == $RT::Nobody->id;

# get the user list from the file
# this file has the list of users who will be assigned as owner in
round-robin
# you could have another logic external that could update this file to get
the
# generate the list of owners
my $file = "/var/tmp/ownerlist";

return 1 unless open(my $fh, '<', $file);
my @owners = <$fh>;
return 1 unless close $fh;

# sanitizing the entries - accounts should be all alphanumerics
foreach my $line (@owners) {
 $line =~ tr/A-Za-z0-9//cd;
}


# get a count for the owners
my $totmembers = scalar( @owners );

# get this ticket id
my $ticket_id = $self->TicketObj->id;

# ticket_id modulo totmembers to pick the next owner
my $x =  $ticket_id % $totmembers;
my $owner = $owners[$x];

## Some debug option when uncommented
## $RT::Logger->info("AUTOASSIGN: DEBUG ". $self->TicketObj->id ." to user
". $owner );
## $RT::Logger->info("AUTOASSIGN: DEBUG Total number of owners ".
scalar(@owners) );
## uncomment this if you want to run in dry run mode
## return 1;

# set the owner
$RT::Logger->info("AUTOASSIGN: ". $self->TicketObj->id ." to user ". $owner
);
my ($status, $msg) = $self->TicketObj->SetOwner( $owner );
unless( $status ) {
    $RT::Logger->error( "Impossible to assign the ticket to $owner: $msg" );
    return undef;
}

return 1;



> --
> Asif Iqbal
> PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
>
>


-- 
Asif Iqbal
PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20151022/7a666689/attachment.htm>


More information about the rt-users mailing list