[Rt-devel] Re: [script] Automatic removal of bounce-generating addresses from ticket

Petter Reinholdtsen pere at hungry.com
Thu Jan 19 11:44:33 EST 2006


[Petter Reinholdtsen]
> Here is the script we now use in production.  I'll keep the copy on
> <URL:http://www.usit.uio.no/it/rt/modifications/> up to date.

The script do not work as I expected it to, and I fail to understand
why.  It is capable of removing lots of watchers from the tickets, but
not one specific watcher, 'root at ulrik.uio.no'.  When I remove the
problematic watcher using the web interface, I have no problems
getting rid of it.  I've tried to reduce the script to a small example
demonstrating the problem.

The script searches for all tickets with a watcher using a given email
address, and then loops over all the tickets to remove the watcher
with the given email from the tickets.  Works most of the time.  But
for one email address, if finds 202 tickets, but is unable to remove
the watcher because it "Could not find that principal".  How is this
possible?  I get this output.  Notice how it tries to remove the
watcher from the same ticket each time I run the script.

  % ./foo
  Found 202 tickets with 'root at ulrik.uio.no' as watcher
  Removing queue address root at ulrik.uio.no as watcher from ticket #141
    Failed to remove Cc: Could not find that principal
    Failed to remove AdminCc: Could not find that principal
    Failed to remove Requestor: Could not find that principal
  Processed 1 tickets
  % ./foo
  Found 202 tickets with 'root at ulrik.uio.no' as watcher
  Removing queue address root at ulrik.uio.no as watcher from ticket #141
    Failed to remove Cc: Could not find that principal
    Failed to remove AdminCc: Could not find that principal
    Failed to remove Requestor: Could not find that principal
  Processed 1 tickets
  %

This is the script.  I cut the loop short to limit the output of the
example run.  Any ideas?  There must be something obvious I fail to
see here.


#!/site/perl-5.8.6/bin/perl
#
# Author:  Petter Reinholdtsen
# Date:    2006-01-19
# License: GNU Public License v2 or later
#
# Demonstrate a strange feature in RT, where 'find tickets with
# watcher = root at ulrik.uio.no' return lots of tickets, but 'remove
# watcher root at ulrik.uio.no from ticket' fail because there is no such
# principal.


use warnings;
use strict;

use lib ("/site/rttest/local/lib", "/site/rttest/lib");

package RT;

use RT::Interface::CLI qw(CleanEnv);
use RT::Queue;
use RT::Queues;
use RT::Tickets;

my $debug = 1;

my $ticketcount = 0;

CleanEnv();       # Clean our the environment
RT::LoadConfig(); # Load the RT configuration
RT::Init();       # Initialise RT

my $user = RT::User->new( $RT::SystemUser );

# Loop over all addresses, remove them from the tickets were they are
# registered as watchers

my $address = "root\@ulrik.uio.no";
my $tickets = new RT::Tickets($RT::SystemUser);
$tickets->FromSQL( "Watcher.EmailAddress = '$address'" );

print "Found ".$tickets->Count." tickets with '$address' as watcher\n";

while( my $ticket = $tickets->Next ) {
    $ticketcount++;
    my $id = $ticket->Id;
    print "Removing queue address $address as watcher from ticket \#$id\n";
    for my $type ( qw(Cc AdminCc Requestor) ) {
        my ($ok, $msg) =
            $ticket->DeleteWatcher(Email => $address, Type => $type );
        print "  Failed to remove $type: $msg\n"
            unless $ok;
    }
    last;
}
print "Processed $ticketcount tickets\n";


More information about the Rt-devel mailing list