[Rt-devel] [script] Automatic removal of bounce-generating
addresses from ticket
Petter Reinholdtsen
pere at hungry.com
Wed Jan 18 07:23:15 EST 2006
[Ruslan Zakirov]
> I think this should speedup things
It did. The run time went from 1.5 hour to 10 minutes. Thank you for
the suggestion to turn the search strategy upside down. :)
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.
#!/site/perl-5.8.6/bin/perl
#
# Author: Petter Reinholdtsen
# Date: 2006-01-13
# License: GNU Public License v2 or later
#
# Look at all tickets, and remove all queue addresses from requestor,
# cc and admincc. This reduces the amount of bounce emails sent to
# the RT admins.
use warnings;
use strict;
use Getopt::Std;
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 %opts;
Getopt::Std::getopts("dn", \%opts);
my $debug = $opts{'d'} || 0;
my $dryrun = $opts{'n'} || 0;
$| = 1;
# Find all queue addresses of enabled queues
my @queueaddrs = qw(root at ourhost.uio.no);
my $ticketcount = 0;
my $starttime = time();
CleanEnv(); # Clean our the environment
RT::LoadConfig(); # Load the RT configuration
RT::Init(); # Initialise RT
my $user = RT::User->new( $RT::SystemUser );
# Merge static list with dynamic list
@queueaddrs = (load_queue_addresses(), @queueaddrs);
# Loop over all addresses, remove them from the tickets were they are
# registered as watchers
for my $address( sort @queueaddrs ) {
my $tickets = new RT::Tickets($RT::SystemUser);
$tickets->FromSQL( "Watcher.EmailAddress = '$address'" );
while( my $ticket = $tickets->Next ) {
$ticketcount++;
my $id = $ticket->Id;
if ($dryrun) {
print "Want to remove $address as watcher from ticket #$id\n";
} else {
$RT::Logger->info("Removed queue address $address as watcher ".
"from ticket #$id");
$ticket->DeleteWatcher(Email => $address, Type => $_ )
for( qw(Cc AdminCc Requestor) );
}
}
}
my $duration = time() - $starttime;
$RT::Logger->info("Processing of $ticketcount tickets took $duration seconds");
sub load_queue_addresses {
my $queues = new RT::Queues($RT::SystemUser);
$queues->LimitToEnabled();
my @queueaddrs;
foreach my $queue (@{$queues->ItemsArrayRef()}) {
for my $address ($queue->CorrespondAddress, $queue->CommentAddress) {
next unless $user->LoadByEmail( $address );
push @queueaddrs, $address;
print "Found queue address '$address'\n" if $debug;
}
}
return @queueaddrs;
}
More information about the Rt-devel
mailing list