Ticket Requestors returned as hash ref

I’m rewriting a script which will look in our SPAM queue (to which all tickets
deemed to be spam are banished) and run each of the spam “requestors” through
rtx-shredder. I have it set up to do everything the way I want except it
doesn’t work because when asking for $ticket->Requestors I get
RT::Group=HASH(refNumber)

Here’s my script:
#!/usr/bin/perl

File: delete_spam.pl

Version: 2.0

Author: Mathew Snyder

Date: August 5, 2007

Comments: A script to gather up the spam

sent to the Security queue and

eliminate the “users” that

created it. It then marks those

tickets as deleted for the purpose

of further housecleaning by the

rtx-shredder cronjob.

#Set up our environment
use warnings;
use strict;
use lib ‘/usr/local/rt-3.6.1/lib’;
use lib ‘/usr/local/rt-3.6.1/local/lib’;
use lib ‘/usr/local/lib’;
use RT;
use RT::Users;
use RT::Tickets;
use MIME::Lite;
use Reports::Emails;

RT::LoadConfig();
RT::Init();

my @usrID;
my %userID;
my @emails;

my %skipEmails = (
“ids-tripwire” => undef,
“tripwire” => undef,
“security” => undef
);

my $users = new RT::Users(RT::SystemUser);
$users->LimitToPrivileged;

while ( my $user = $users->Next ) {
next if $user->Name eq ‘root’;
$skipEmails{$user->EmailAddress} = undef;
}

foreach my $key (@usrID) {
$skipEmails{$key} = undef;
}

my $tix = new RT::Tickets(RT::SystemUser);
$tix->FromSQL(‘Queue = “SPAM”’);

while (my $ticket = $tix->Next) {
print $ticket->Requestors . “\n”;
if (exists($skipEmails{$ticket->Requestors}) or $ticket->Requestors == “”) {
next;
}
else {
push @emails, $ticket->Requestors;
}

$ticket->SetStatus(“deleted”);

}

#my $count = 0;
#foreach my $email (@emails) {
system("/usr/local/rt-3.6.1/local/sbin/rtx-shredder","–force","–plugin",“Users=status,any;email,$email;replace_relations,Nobody”);

$count++;

#}

#my $emailTo = "msnyder@servervault.com";
#my $emailFrom = “RT”;
#my $emailSubj = “RT Spam Removal”;
#my $emailMsg = “The spam removal script has completed and has removed
$count spam created users”;

#my $fullEmail = new MIME::Lite(From => $emailFrom,

To => $emailTo,

Subject => $emailSubj,

Data => $emailMsg,

#);

#$fullEmail->send(“sendmail”, “/usr/sbin/sendmail -t”);
#unlink glob “*.sql”;

exit;

Where am I going wrong with this? How do I set it up to get those actual email
addresses instead of an RT::Group hash ref?

Thanks,
Mathew
Keep up with me and what I’m up to: http://theillien.blogspot.com

I’ve been trying to figure out how to dereference the hash but I haven’t been
successful.

Any thoughts?

Keep up with me and what I’m up to: http://theillien.blogspot.com

Mathew Snyder wrote:

The first thought is, try to use Data::Dumper and to output Dumper( $ticket->Requestors ) in the right place.
Thus you could see key/value pairs.
Either key or value in each pair is probably an object, i.e. a blessed reference, so the output might be quite bulky…-----Original Message-----
From: Mathew Snyder theillien@yahoo.com
To: RT Users rt-users@lists.bestpractical.com
Date: Sun, 05 Aug 2007 15:10:49 -0400
Subject: Re: [rt-users] Ticket Requestors returned as hash ref

I’ve been trying to figure out how to dereference the hash but I haven’t been
successful.

Any thoughts?

Keep up with me and what I’m up to: http://theillien.blogspot.com

Mathew Snyder wrote:

I’m rewriting a script which will look in our SPAM queue (to which all tickets
deemed to be spam are banished) and run each of the spam “requestors” through
rtx-shredder. I have it set up to do everything the way I want except it
doesn’t work because when asking for $ticket->Requestors I get
RT::Group=HASH(refNumber)

Here’s my script:
#!/usr/bin/perl

#############################################

File: delete_spam.pl

Version: 2.0

Author: Mathew Snyder

Date: August 5, 2007

Comments: A script to gather up the spam

sent to the Security queue and

eliminate the “users” that

created it. It then marks those

tickets as deleted for the purpose

of further housecleaning by the

rtx-shredder cronjob.

#############################################

#Set up our environment
use warnings;
use strict;
use lib ‘/usr/local/rt-3.6.1/lib’;
use lib ‘/usr/local/rt-3.6.1/local/lib’;
use lib ‘/usr/local/lib’;
use RT;
use RT::Users;
use RT::Tickets;
use MIME::Lite;
use Reports::Emails;

RT::LoadConfig();
RT::Init();

my @usrID;
my %userID;
my @emails;

my %skipEmails = (
“ids-tripwire” => undef,
“tripwire” => undef,
“security” => undef
);

my $users = new RT::Users(RT::SystemUser);
$users->LimitToPrivileged;

while ( my $user = $users->Next ) {
next if $user->Name eq ‘root’;
$skipEmails{$user->EmailAddress} = undef;
}

foreach my $key (@usrID) {
$skipEmails{$key} = undef;
}

my $tix = new RT::Tickets(RT::SystemUser);
$tix->FromSQL(‘Queue = “SPAM”’);

while (my $ticket = $tix->Next) {
print $ticket->Requestors . “\n”;
if (exists($skipEmails{$ticket->Requestors}) or $ticket->Requestors == “”) {
next;
}
else {
push @emails, $ticket->Requestors;
}

$ticket->SetStatus(“deleted”);

}

#my $count = 0;
#foreach my $email (@emails) {

system("/usr/local/rt-3.6.1/local/sbin/rtx-shredder","–force","–plugin",“Users=status,any;email,$email;replace_relations,Nobody”);

$count++;

#}

#my $emailTo = "msnyder@servervault.com";
#my $emailFrom = “RT”;
#my $emailSubj = “RT Spam Removal”;
#my $emailMsg = “The spam removal script has completed and has removed
$count spam created users”;

#my $fullEmail = new MIME::Lite(From => $emailFrom,

To => $emailTo,

Subject => $emailSubj,

Data => $emailMsg,

#);

#$fullEmail->send(“sendmail”, “/usr/sbin/sendmail -t”);
#unlink glob “*.sql”;

exit;

Where am I going wrong with this? How do I set it up to get those actual email
addresses instead of an RT::Group hash ref?

Thanks,
Mathew


http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I’ve been trying to figure out how to dereference the hash but I haven’t
been successful.

Mathew,

Don’t you want $ticket->RequestorAddresses, rather than
$ticket->Requestors? The latter returns the ticket’s requestors as an
RT::Group object, whereas the former returns all the Requestor email
addresses as a comma-delimited string.

Mike

while (my $ticket = $tix->Next) {
print $ticket->Requestors . “\n”;
if (exists($skipEmails{$ticket->Requestors}) or $ticket->Requestors == “”) {
next;
}
else {
push @emails, $ticket->Requestors;
}

$ticket->SetStatus(“deleted”);

}

Mike Friedman Information Services & Technology
mikef@ack.Berkeley.EDU 2484 Shattuck Avenue
1-510-642-1410 University of California at Berkeley
http://socrates.berkeley.edu/~mikef http://ist.berkeley.edu

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBRrZm7a0bf1iNr4mCEQIumgCg4kXsJm+v7CK2aQDESN6xASExbmgAnixm
Lid+57RUeunctOfc6f5ErXqu
=5UIb
-----END PGP SIGNATURE-----

Mike Friedman wrote:

I’ve been trying to figure out how to dereference the hash but I
haven’t been successful.

Mathew,

Don’t you want $ticket->RequestorAddresses, rather than
$ticket->Requestors? The latter returns the ticket’s requestors as an
RT::Group object, whereas the former returns all the Requestor email
addresses as a comma-delimited string.

Mike

ding ding ding ding

We have a winner. :smiley: Thanks. For some reason, that hadn’t even occurred to me
despite looking directly at it on more than one occassion.

Mathew