Scrip needed that automaticaly closes tickets with a special subject

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

I would look at modifying this to suit your needs.
http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages

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

Drew Barnes
Applications Analyst
Raymond Walters College
University of Cincinnati

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:

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 :slight_smile:

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

Gene LeDuc, GSEC
Security Analyst
San Diego State University

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 :slight_smile:

Again thanks a lot for the support so far!

Best regards
ThomasAm 11.07.2007 19:12 Uhr schrieb “Gene LeDuc” unter gleduc@mail.sdsu.edu:

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 :slight_smile:

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

You can start by breaking down your scrip to test it in different
working parts.

Only use your User Defined condition and see if one of the already built
scrip actions will fire. Then set that back to a basic scrip condition
and test it with your custom action code.

I think you’re going wrong in your custom condition. The Transactions
table doesn’t have a subject field…
I think what you want is more like:
return($self->TransactionObj->Field eq “Subject” &&
$self->TransactionObj->NewValue eq “HMPF”);

Also, this will only fire if the entire subject has been changed to
"HMPF," but I’m assuming you’re on top of that.

including “return 1;” in your custom action preparation scrip is good.

Re: your question about brackets-- I don’t know this but you should be
able to find examples of SetStatus on the RT wiki…

Best of luck,

Forrest

Thomas Hecker wrote:

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 :slight_smile:

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 :slight_smile:

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

Hi Forrest,

At 05:50 AM 7/12/2007, Forrest Blount wrote:

I think you’re going wrong in your custom condition. The Transactions
table doesn’t have a subject field…
I think what you want is more like:
return($self->TransactionObj->Field eq “Subject” &&
$self->TransactionObj->NewValue eq “HMPF”);

The Transaction table of the database does not have a Subject field, but
$self->TransactionObj->Subject() is a method that returns the subject from
the transaction. The conditions I gave in my original post will work if
the typos that were added are removed.

Thomas Hecker wrote:

But it still does not work. Here is what i did:

Custom condition:
my $Transaction = $self->TransactionObj;
return $Transaction->$Transaction->Subject =‘HMPF’;

Typo here. Should be:
return $Transaction->Type eq ‘Correspond’ && $Transaction->Subject =~ /HMPF/;

Regards,
Gene

Gene LeDuc, GSEC
Security Analyst
San Diego State University

Hi all,

ok so far, i got this scrip to work! Thanks everybody who helped.

The last question is, how can i change the scrip to avoid sending a “your
ticket has been closed” email?

Best regards ThomasAm 12.07.2007 19:50 Uhr schrieb “Gene LeDuc” unter gleduc@mail.sdsu.edu:

Hi Forrest,

At 05:50 AM 7/12/2007, Forrest Blount wrote:

I think you’re going wrong in your custom condition. The Transactions
table doesn’t have a subject field…
I think what you want is more like:
return($self->TransactionObj->Field eq “Subject” &&
$self->TransactionObj->NewValue eq “HMPF”);

The Transaction table of the database does not have a Subject field, but
$self->TransactionObj->Subject() is a method that returns the subject from
the transaction. The conditions I gave in my original post will work if
the typos that were added are removed.

Thomas Hecker wrote:

But it still does not work. Here is what i did:

Custom condition:
my $Transaction = $self->TransactionObj;
return $Transaction->$Transaction->Subject =‘HMPF’;

Typo here. Should be:
return $Transaction->Type eq ‘Correspond’ && $Transaction->Subject =~ /HMPF/;

Regards,
Gene

Hi Thomas,

Glad to hear your system is working the way you want.

Here are 2 ways to avoid the “your ticket has been resolved”
notification. Each affects a different group of tickets.

  1. This will turn it off for every resolved ticket in that queue: Create a
    new “On Resolve” scrip in the queue (use the same name as the Global scrip)
    and set the action to User Defined. Then for the first action box in the
    scrip, just put
    return 0;
    The scrip will trigger when a ticket gets resolved, but no action will ever
    be taken.

  2. This will affect just the tickets that are resolved by this particular
    scrip: Replace the “$Ticket->SetStatus(‘resolved’);” line in your scrip with
    $Ticket->_Set(Field => ‘Status’, Value => ‘resolved’, RecordTransaction
    => 0);
    This will prevent a transaction from being created when you change the
    status to ‘resolved’. No transaction, no notification.

Regards,
Gene

At 05:04 AM 7/16/2007, Thomas Hecker wrote:

Hi all,

ok so far, i got this scrip to work! Thanks everybody who helped.

The last question is, how can i change the scrip to avoid sending a “your
ticket has been closed” email?

Best regards Thomas

Hi Forrest,

At 05:50 AM 7/12/2007, Forrest Blount wrote:

I think you’re going wrong in your custom condition. The Transactions
table doesn’t have a subject field…
I think what you want is more like:
return($self->TransactionObj->Field eq “Subject” &&
$self->TransactionObj->NewValue eq “HMPF”);

The Transaction table of the database does not have a Subject field, but
$self->TransactionObj->Subject() is a method that returns the subject from
the transaction. The conditions I gave in my original post will work if
the typos that were added are removed.

Thomas Hecker wrote:

But it still does not work. Here is what i did:

Custom condition:
my $Transaction = $self->TransactionObj;
return $Transaction->$Transaction->Subject =‘HMPF’;

Typo here. Should be:
return $Transaction->Type eq ‘Correspond’ && $Transaction->Subject =~
/HMPF/;

Regards,
Gene


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