Scrip Action (Long)

Hello All,

Ruslan helped get me through my last question - btw, the error I was
seeing indicated that the Prepare/Commit action was returning 0 (false).

My perl (not)skills are leaving me feeling wowfully inadequate, and I
need some help.

Now I’m trying to do something a little more complex, namely I’m trying
to set the priority to a value indicated in the body of the email. This
a precursor to an automated email parser that will let me set the values
of the ticket via the body of the email. I need to get through the
basics before I try to tackle the more significant tasks, and figured
dealing with the priority would be a simpler way to do that.

My Scrip is designed to parse an email finding the string “Priority:XX”,
where “XX” is some value, pull that value and set the priority to that
value.

Description :Set Priority

Condition :On Create

Action :User Defined

Custom action preparation code:
my $MatchString = “iority:\s*(\w+)”;
my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;
my $found = 0;

$RT::Logger->info(“entering ‘Set Priority’ Scrip for Support Queue.”);
$RT::Logger->info("Message Content: " .
$Transaction->Attachments->First->Content);

$found = ($Transaction->Attachments->First->Content =~ /$MatchString/m);
if ($1) {
$_ = $1;
} else {
$_ = $&;
}

be sure the match is in $_

if ($found) {
$RT::Logger->info(“matched Priority value: $");
} else {
$RT::Logger->info("failed to match Priority value: $
”);
$_ = “”;
}
if ($) {
$Ticket->SetPriority($
);
} else {
return(0);
}
return(1);

Custom action cleanup code:
return(1);

Template :Global template: Blank

When the incoming mail is HTML, the error log reads thus:

Nov 10 21:35:02 support RT: entering ‘Set Priority’ Scrip for Support
Queue. ((eval 5042):6)
Nov 10 21:35:02 support RT: Message Content: ((eval 5042):7)
Nov 10 21:35:02 support RT: failed to match Priority value: correspond
((eval 5042):19)
Nov 10 21:35:02 support RT: RT::Scrip=HASH(0xba58518): Couldn’t prepare
User Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:338)
Nov 10 21:35:02 support RT: Ticket 465 created in queue ‘Support’ by
rbellamy (/opt/rt3/lib/RT/Ticket_Overlay.pm:635)

When the ticket is plain text, it reads like so:

Nov 10 21:35:38 support RT: entering ‘Set Priority’ Scrip for Support
Queue. ((eval 5069):6)
Nov 10 21:35:38 support RT: Message Content: Priority:50 G. Richard
Bellamy Enterprise Solution Architect Pteradigm - Evolutionary
mailto:rbellamy@pteradigm.com V:707-869-3665 ((eval 5069):7)
Nov 10 21:35:38 support RT: failed to match Priority value: correspond
((eval 5069):19)
Nov 10 21:35:38 support RT: RT::Scrip=HASH(0xb91ac2c): Couldn’t prepare
User Defined (/opt/rt3/lib/RT/Scrip_Overlay.pm:338)
Nov 10 21:35:38 support RT: Ticket 466 created in queue ‘Support’ by
rbellamy (/opt/rt3/lib/RT/Ticket_Overlay.pm:635)

Any help would be greatly appreciated.

-rb

-----Original Message-----
From: G. Richard Bellamy
Sent: Monday, November 10, 2003 9:40 PM
To: rt-devel@fsck.com
Subject: [rt-devel] Scrip Action (Long)

$RT::Logger->info(“entering ‘Set Priority’ Scrip for Support
Queue.”); $RT::Logger->info("Message Content: " .
$Transaction->Attachments->First->Content);

$found = ($Transaction->Attachments->First->Content =~
/$MatchString/m); if ($1) {

I’ve changed it to $Transaction->Content and that isn’t working for me
either, though the logging now outputs the content regardless of the
encoding.

Quoting G. Richard Bellamy rbellamy@pteradigm.com (2003-11-11 05:39:47 GMT):

Hello All,

Ruslan helped get me through my last question - btw, the error I was
seeing indicated that the Prepare/Commit action was returning 0 (false).

My perl (not)skills are leaving me feeling wowfully inadequate, and I
need some help.

Only a little. Looks pretty slick to me.

Custom action preparation code:
my $MatchString = “iority:\s*(\w+)”;

You’re going wrong here. The escapes are being interpreted by Perl as
being just the plain characters, so $MatchString is actually
“iority:s*(w+)”. Use single-quotes or double-escapes :slight_smile:

FASTNET
SOUTHEAST VEERING WEST OR SOUTHWEST 5, INCREASING 6 TO GALE 8 FOR A
TIME. RAIN THEN SHOWERS. MODERATE OR GOOD

-----Original Message-----
From: Andrew Stribblehill [mailto:a.d.stribblehill@durham.ac.uk]
Sent: Tuesday, November 11, 2003 1:11 AM
To: G. Richard Bellamy
Cc: rt-devel@fsck.com
Subject: Re: [rt-devel] Scrip Action (Long)

Only a little. Looks pretty slick to me.

In the interest of full disclosure, I stole most of the code from the
ExtractCustomField custom action available in the contrib directory.
That nice little piece was done by Dirk Pape pape-rt@inf.fu-berlin.de,
the good stuff you saw was from him - the mistakes were mine.

G. Richard Bellamy wrote:

Hello All,

Ruslan helped get me through my last question - btw, the error I was
seeing indicated that the Prepare/Commit action was returning 0 (false).

My perl (not)skills are leaving me feeling wowfully inadequate, and I
need some help.

Now I’m trying to do something a little more complex, namely I’m trying
to set the priority to a value indicated in the body of the email. This
a precursor to an automated email parser that will let me set the values
of the ticket via the body of the email. I need to get through the
basics before I try to tackle the more significant tasks, and figured
dealing with the priority would be a simpler way to do that.

My Scrip is designed to parse an email finding the string “Priority:XX”,
where “XX” is some value, pull that value and set the priority to that
value.

===============================
Description :Set Priority

Condition :On Create

Action :User Defined

Custom action preparation code:
my $MatchString = “iority:\s*(\w+)”;
\w == [a-zA-Z](alphabetical chars no digits so you need \d)
my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;
my $found = 0;

$RT::Logger->info(“entering ‘Set Priority’ Scrip for Support Queue.”);
$RT::Logger->info("Message Content: " .
$Transaction->Attachments->First->Content);

$found = ($Transaction->Attachments->First->Content =~ /$MatchString/m);
if ($1) {
$_ = $1;
} else {
$_ = $&;
}

be sure the match is in $_

if ($found) {
$RT::Logger->info(“matched Priority value: $");
} else {
$RT::Logger->info("failed to match Priority value: $
”);
$_ = “”;
}
if ($) {
$Ticket->SetPriority($
);
} else {
return(0);
}
return(1);

Custom action cleanup code:
return(1);

My variant:

my $Ticket = $self->TicketObj;
my $Transaction = $self->TransactionObj;
my $p;

$RT::Logger->info(“entering ‘Set Priority’ Scrip for Support Queue.”);
$RT::Logger->info("Message Content: " .
$Transaction->Attachments->First->Content);

if(($p) = ($Transaction->Attachments->First->Content =~
/Priority:\s*(\d+)/im)) {
$RT::Logger->info(“matched Priority value: $p”);
$Ticket->SetPriority($p);
} else {
$RT::Logger->info(“failed to match Priority value: $_”);
return(0);
}
return(1);

-----Original Message-----
From: Ruslan U. Zakirov [mailto:cubic@acronis.ru]
Sent: Wednesday, November 12, 2003 10:38 AM
To: G. Richard Bellamy
Subject: Re: [rt-devel] Scrip Action (Long)

Is it working?

Actually, I got it working with my take on it… Your guidance was
critical in making that happen, and thank you.

I should have posted that I have it working. :slight_smile: