Ok, I tested the scrip. Here it is pasted from RT:
Custom condition:
{ ### Testing Subject trigger
my $Transaction = $self->TransactionObj;
my $MyName = “Scrip General:52:Condition (Test)”;
my $val = $Transaction->Type eq “Correspond”;
$RT::Logger->debug(“$MyName: (” . $Transaction->Id . ") condition is " .
($val ? “True” : “False”));
return $val;
}
Custom prep code:
Dump Subject into log file
my $MyName = “Scrip General:52:Prep (Test)”;
my $Transaction = $self->TransactionObj;
$RT::Logger->debug(“$MyName: (” . $Transaction->Id . ") subject is " .
$Transaction->Subject() );
return $Transaction->Subject =~ /trigger/i;
Custom cleanup code:
Dump Subject into log file
my $MyName = “Scrip General:52:Cleanup (Test)”;
my $Transaction = $self->TransactionObj;
$RT::Logger->debug(“$MyName: (” . $Transaction->Id . ") caught subject: " .
$Transaction->Subject() );
return 1;
And from my rt.log (showing that this scrip does trigger on the word
“trigger” in the subject line of an e-mail:
[Thu Jul 12 16:29:42 2007] [debug]: Converting ‘us-ascii’ to ‘utf-8’ for
text/plain - [itso #487] Trigger phrase (/opt/local/lib/RT/I18N.pm:223)
[Thu Jul 12 16:29:42 2007] [debug]: Found a ticket ID. It’s 487
(/opt/local/lib/RT/Interface/Email.pm:475)
[Thu Jul 12 16:29:42 2007] [debug]: About to think about scrips for
transaction #6298 (/opt/local/lib/RT/Transaction_Overlay.pm:165)
[Thu Jul 12 16:29:42 2007] [debug]: About to prepare scrips for transaction
#6298 (/opt/local/lib/RT/Transaction_Overlay.pm:169)
[Thu Jul 12 16:29:42 2007] [debug]: Found 1 scrips
(/opt/local/lib/RT/Scrips_Overlay.pm:363)
[Thu Jul 12 16:29:42 2007] [debug]: Scrip General:52:Condition (Test):
(6298) condition is True ((eval 1188):8)
The line above is from the custom condition code and shows that that the
scrip got triggered by an e-mail and what the subject of the e-mail is
[Thu Jul 12 16:29:43 2007] [debug]: Scrip General:52:Prep (Test): (6298)
subject is [itso #487] Trigger phrase ((eval 1190):4)
The line above shows that the custom prep code ran, testing for “trigger”
in subject
[Thu Jul 12 16:29:43 2007] [debug]: About to commit scrips for transaction
#6298 (/opt/local/lib/RT/Transaction_Overlay.pm:178)
[Thu Jul 12 16:29:43 2007] [debug]: Scrip General:52:Cleanup (Test): (6298)
caught subject: [itso #487] Trigger phrase ((eval 1191):4)
The line above shows that the custom cleanup code ran, only runs if the
subject line contains “trigger”
You can move the prep condition into the custom condition code and replace
the prep code with:
return 1;
That would make the custom condition:
{ ### Testing Subject trigger
my $Transaction = $self->TransactionObj;
my $MyName = “Scrip General:52:Condition (Test)”;
my $val = $Transaction->Type eq “Correspond” && $Transaction->Subject =~
/trigger/i;
$RT::Logger->debug(“$MyName: (” . $Transaction->Id . ") condition is " .
($val ? “True” : “False”));
return $val;
}
Your custom cleanup would just set the priority of the ticket to “resolved”
as in my previous post. There are some typos in your e-mail, try copying
from this e-mail rather than retyping into RT to avoid the typos. You’ll
need to change the /trigger/ condition to your trigger string.
Leave all of the logging stuff in until it works. Add more logging stuff
if it doesn’t work. Add look at your rt.log file to see what is (or isn’t)
happening.
Regarding the curly braces: RT seems to need them in the condition code
but doesn’t need them in the action code. I don’t know why this is, but it
works.
Regards,
Gene
At 05:03 AM 7/12/2007, Thomas Hecker wrote:
Hi,
thanks for your support so far.
I did a lot of tests, but it still dont work. I added a screenshot of my
script as a created it in the web gui. You can see it here:
http://www.asymmetry.de/scrip.jpg
But it still does not work. Here is what i did:
Custom condition:
my $Transaction = $self->TransactionObj;
return $Transaction->$Transaction->Subject =‘HMPF’;
Custom action preparation
return 1;
Custom action cleanup
my $Ticket = $self->TicketObj;
$Ticket->SetStatus(‘resolved’);
return 1;
I’m not really shure about the brackets ({}). in the last mail there where
brackets in the custom condition field but not in the cleanup, so i’m not
shure about that. Also if i have to return 1; or return 1; (writing the word
return inside the scripbt or not).
So maybe sombody has the final answer 
Again thanks a lot for the support so far!
Best regards
Thomas
Hi Thomas,
You create scrips like this using the RT web GUI. Go into Configuration,
select Queues, then the queue that you want this scrip to apply to, then
Scrips, then New Scrip. I don’t think you really want to do this with perl
modules.
For condition, select “User Defined”
For action, select “User Defined”
For template, select “Global template: Blank” (actually, I don’t think it
matters what you select for a template if the action is user-defined, but
you have to select something).
For stage, select “TransactionCreate”
In the Custom condition area you want to trap transactions that are
Type:Correspond (e-mail) and that have “HMPF” in the subject. Your custom
condition could look something like this:
{ my $Transaction = $self->TransactionObj;
return $Transaction->Type eq ‘Correspond’ && $Transaction->Subject =~
/HMPF/;
}
This will cause the scrip to fire when a transaction occurs that is an
e-mail that has HMPF in the subject, otherwise the scrip will not fire.
In the Custom action preparation code area you can just put:
return 1;
This does nothing except allow the cleanup action to run. If you leave it
out then the cleanup action won’t run.
In the Custom action cleanup code area you could have something like this:
my $Ticket = $self->TicketObj;
$Ticket->SetStatus(‘resolved’);
return 1;
This will change the status of the ticket to resolved. It will also create
another transaction that will trigger any “On Resolve” scrips you might
have.
All of this is done within the RT web GUI.
Good luck with this,
Gene
At 09:20 AM 7/11/2007, Thomas Hecker wrote:
Hi,
well i changed the scrip this way:
my $problem_desc = undef;
my $Transaction = $self->TransactionObj;
my $subject = $Transaction->Attachments->First->GetHeader(‘Subject’);
if ( $subject =~ /^HMPF (\w+) - (\S*) (\S*)/ ) {
# Auto-close/resolve this whole thing
$self->TicketObj->SetStatus( “resolved” );
} else {
return 1;
}
1;
So it should set a ticket to solved when the subject contains HMPF -
right?
The next problem i have is, how do i implement this scrip to rt? I
saved it
as an .pm file and put it into the lib to all the other scrips. than i
wrote
a perl script described in the o’reilly book page 81, to make the scrip
available to the RTR database:
#!usr/bin/perl
use strict;
use lib “/usr/share/request-tracker3.6/lib”;
use RT;
use RT::Interface::CLI qw( CleanEnv GetCurrentUser );
use RT::ScripCondition;
CleanEnv();
RT::LoadConfig();
RT::Init();
my $user = GetCurrentUser();
unless( $user->Id ) {
print “No RT user found. Please consult your GOD\n”;
exit 1;
}
my $sc = RT::ScripCondition->new($user);
$sc->Create( Name => ‘HMPF-Betreff’,
Beschreibung => ‘Wenn Betreff enthaelt HMPF dann schliesse
sofort’,
ExecModule => ‘OnCreate’,
ApplicableTransTypes => ‘Status’,
);
When i run this scrip i get no error, but the scrip is not available
in the
webinterface of rt.
what’s wrong?
Thanks for help
Thomas
Am 05.07.2007 15:12 Uhr schrieb “Drew Barnes” unter
barnesaw@ucrwcu.rwc.uc.edu:
I think this should be correct, but I haven’t used this particular scrip
lately.
If the subject of the ticket matches a pattern suggesting
that this is a Nagios RECOVERY message AND there is
an existing ticket (open or new) in the “zNagios” queue with a matching
“problem description”, (that is not this ticket)
merge this ticket into that ticket
Based on
http://marc.free.net.ph/message/20040319.180325.27528377.en.html
my $problem_desc = undef;
my $Transaction = $self->TransactionObj;
my $subject = $Transaction->Attachments->First->GetHeader(‘Subject’);
if ( $subject =~ /^RECOVERY (\w+) - (\S*) (\S*)/ ) {
# This looks like a nagios recovery message
$problem_desc = $2;
$RT::Logger->debug("Found a recovery msg: $problem_desc");
} else {
return 1;
}
Ok, now let’s merge this ticket with it’s PROBLEM msg.
my $search = RT::Tickets->new($RT::SystemUser);
$search->LimitQueue(VALUE => ‘zNagios’);
$search->LimitStatus(VALUE => ‘new’, OPERATOR => ‘=’, ENTRYAGGREGATOR =>
‘or’);
$search->LimitStatus(VALUE => ‘open’, OPERATOR => ‘=’);
if ($search->Count == 0) { return 1; }
my $id = undef;
while (my $ticket = $search->Next) {
# Ignore the ticket that opened this transation (the recovery one…)
next if $self->TicketObj->Id == $ticket->Id;
# Look for nagios PROBLEM warning messages…
if ( $ticket->Subject =~ /^PROBLEM (\w+) - (\S*) (\S*)/ ) {
if ($2 eq $problem_desc){
# Aha! Found the Problem TICKET corresponding to this
RECOVERY
# ticket
$id = $ticket->Id;
# Nagios may send more then one PROBLEM message, right?
$RT::Logger->debug(“Merging ticket " . $self->TicketObj->Id
. " into $id because of Nagios Subject match.”);
$self->TicketObj->MergeInto($id);
# Keep looking for more PROBLEM tickets…
}
}
}
$id || return 1;
Auto-close/resolve this whole thing
$self->TicketObj->SetStatus( “resolved” );
1;
Thomas Hecker wrote:
i Thanks for the hint, i’ll try my best, but i have problems finding the
right line breaks. can anybody help? All modifications i’ll try then by
myself 
Thanks again
Thomas
Am 03.07.2007 15:15 Uhr schrieb “Drew Barnes” unter
barnesaw@ucrwcu.rwc.uc.edu:
I would look at modifying this to suit your needs.
AutoCloseOnNagiosRecoveryMessages - Request Tracker Wiki
Thomas Hecker wrote:
Hi all,
i use RT 3.6.1 and look for a scrip that automatically closes new
ticktes
that have subjects that contain special words.
an example:
i have some UPS from APC wich send emails after performing
selftesting. The
subject is somehing like “HOMER passes internal self test” where
HOMER is
the name of the UPS. This email should be sent to rt. RT then opens
a new
ticket. Now i want a scrip that closes the ticket automatically
when the
subject of an email contains specail words. So status mails will still
generate tickets but are closed immediately (fpt statistic purpose).
Status
mails with an error like “Error 123 while HOMER performing self
test” then
correctly will open a ticket that stays open.
My problem here is, that i know nothing about perl coding, so i
can’t code
this scrip by myself. Maybe sombody has allready a scrip wich works
similar,
or maybe somebody could code it?
Thanks for help
Thomas
The rt-users Archives
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
The rt-users Archives
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
The rt-users Archives
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
Gene LeDuc, GSEC
Security Analyst
San Diego State University