Autoresolve oncreate based upon multiple subject options


#1

Hi all, I’ve successfully got an autoresolve based upon a single queue & subject criteria working… but I’ve tried now to create subsequent ones in the same queue for different conditions, but they’re not matching.

Basically what I’m aiming for is a library of common terms that don’t need human attention and these get auto closed. e.g.

“Backups successful”
“[0 Errors to report]”
“[Backup success] esx-host (5 vms)”

I suspect the problem is either that the first scrip evaluates it and returns 1 which means it then doesn’t try to evaluate against the remaining scrips OR there’s a problem with my regex in the second two examples around the [] and ().

I’m not a perl guy so I’m doing this the hard way, as it were.

So scrip #1 looks like: (this one works fine btw)

Condition: oncreate
action: user defined
Template: blank
 Applies to: myqueue
custom condition: return 1;
custom action prep code:

my $match = “Backups successful”;
my $t_subject = $self->TicketObj->Subject;
if ( $t_subject !~ /$match/i ) {
return 0;
}
else {
return 1;
}
Custom action commit code:
$self->TicketObj->SetStatus( “resolved” );
return 1;

=============
scrip #2 which is not working:

Condition: oncreate
action: user defined
Template: blank
 Applies to: myqueue
custom condition: return 1;
custom action prep code:

my $match = “[0 Errors to report]”;
my $t_subject = $self->TicketObj->Subject;
if ( $t_subject !~ /$match/i ) {
return 0;
}
else {
return 1;
}
Custom action commit code:
$self->TicketObj->SetStatus( “resolved” );
return 1;

=============

script 3:
Condition: oncreate
action: user defined
Template: blank
Applies to: myqueue
custom condition: return 1;
custom action prep code:

my $match = “[Backup success] esx-host (5 vms”;
my $t_subject = $self->TicketObj->Subject;
if ( $t_subject !~ /$match/i ) {
return 0;
}
else {
return 1;
}
Custom action commit code:
$self->TicketObj->SetStatus( “resolved” );
return 1;

=============

I’ve also tried:
if ( $t_subject !~ /\b$match\b/i ) {

instead of:
if ( $t_subject !~ /$match/i ) {

but no difference.

So… is it problem with the regex expression… logic…? is there an easy way to get it to check
$match/$match2/$match3

rather than making separate scrips?

Thanks!

Chris


#2

Have you tried escaping the []() in the regexps?


#3

Yes I tried escaping using:

“\[Backup success\] esx-host \(5 vms\)”;

but that didn’t work.

the web interface has turned the straight quotes into curlys in Discourse but I’ve confirmed that they’re straight in the RT expression builder.


#4

Could you try it without any meta characters? For example make scrip 3:

my $t_subject = $self->TicketObj->Subject;
if ( $t_subject !~ /Backup success/i ) {
    warn "Not matching $t_subject\n";
    return 0;
}  else {
    warn "Matched $t_subject\n"; 
    return 1;
}

If this works, then slowly add in the other bits of the regexp until you find the bit that isn’t working. If this doesn’t trigger at all (neither warnings appearing in the logs) then your issue is elsewhere, not the regexp.


#5

Thankyou… some more info but not quite there yet…

Using additional non-funky text works…

e.g. scrip2/3/4 matching on:

scrip2 == “My test text 2”

and so forth.

I’ve also tried using the rt cli and can match tickets using either escaped or not escaped. E.g.:

 list -t ticket "Status = 'new' AND Subject LIKE '\[Success\] Replication-esxi01 \('";
 list -t ticket "Status = 'new' AND Subject LIKE '[Success] Replication-esxi01 ('";

both return the same (expected) list of tickets, as does a corresponding search in the GUI, but both these patterns fail to match in scrips.

OK I modifed the scrips to log:
warn “regexp v1 not matched - Subject $t_subject and MatchPattern $match\n”;

(v1/1.1/2 depending on the scrip)

So I could see the subject & match condition that it’s evaluated…

so the logs for those three scrips now show:
Case 1 - plain text - expect to match on scrip v2:
[19963] [Mon Apr 15 01:42:27 2019] [warning]: regex 2 SUPPORT EXPIRED TICKET matched ((eval 1370):8)

and it correct fires & resolves. So it’s not a problem with having multiple scrips per se. If I test case 2 with meta chars - trying to match a string with [] and () I get…
[19965] [Mon Apr 15 01:43:13 2019] [warning]: regexp 1 not matched - Subject [Success] Replication-esxi01 (3 VMs) and MatchPattern [Success] Replication-esxi01 (3 VMs) ((eval 1345):4)
[19965] [Mon Apr 15 01:43:13 2019] [warning]: regexp 1.1 not matched - Subject [Success] Replication-esxi01 (3 VMs) and MatchPattern [Success] Replication-esxi01 (3 VMs) ((eval 1346):4)
[19965] [Mon Apr 15 01:43:13 2019] [warning]: regex 2 SUPPORT EXPIRED TICKET not matched ((eval 1347):4)

Which I guess means the regexp isn’t handling the literal/meta character correctly? (i.e. these: [ ] ( )) or is it something else?

The scrip lines in question:
my $match = “[Success] Replication-esxi01 (3 VMs)”;

if ( $t_subject !~ /\b$match\b/i ) {

the lines “look” OK to me but I’m sure nothing that’s “looked OK” has ever had a problem before :slight_smile:

So I’m guessing it’s either a problem with how I’m escaping the meta chars OR it’s a problem with my regexp not handling the string correctly.

Hang on I’m going to try doing a regexp without the variable hop…
if ( $t_subject !~ /\b[Success] Replication-esxi01 (3 VMs)\b/i ) {

Nope same result :frowning:

Any suggestions?


#6

Try putting the regexp patterns directly inside the // rather than in the $match variable?


#7

Yep that was the last one I tested in the last post:

Is my structure ok?


#8

This example script seems to work okay for me:

use strict;
use warnings;
use Data::Printer;

my $match = "[0 Errors to report]";
my $t_subject = '[Backup success] esx-host (5 vms)';

# No Match
my $ret = $t_subject =~ /\Q$match/;
p($ret);

# Match
$t_subject = '[0 Errors to report]';
$ret = $t_subject =~ /\Q$match/;
p($ret);

output:

""
1

#9

Try escaping the meta characters:

if ( $t_subject !~ /\[Success\] Replication\-esxi01 \(3 VMs\)/i ) {

Also make sure that your white space count matches up. I had one regexp here where the user said it didn’t work but that was because the example subject line they gave me to set up the scrip had single spaces between words and the actual subject line had, for reasons that will never be clear, double spaces.