<div>Thank you very Matthew for that concise response. Appreciate it! </div>
<div> </div>
<div>Follow-up though or anyone who understand scrips, kindly help. </div>
<div> </div>
<div>Please teach me what is OPERATOR => '=', ENTRYAGGREGATOR, </div>
<div> OPERATOR value is expecting from status. </div>
<div> </div>
<div>This is the line from the scrip: </div>
<div> </div>
<div>$search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR => 'or');<br>$search->LimitStatus(VALUE => 'open', OPERATOR => '=');<br></div>
<div> </div>
<div>The entire script is below. </div>
<div> </div>
<div>Thank you very much!</div>
<div>Roehl</div>
<div> </div>
<div><pre># 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 "General" queue with a matching
# "problem description", (that is not this ticket)
# merge this ticket into that ticket
#
# Based on <a href="http://marc.free.net.ph/message/20040319.180325.27528377.en.html">http://marc.free.net.ph/message/20040319.180325.27528377.en.html</a>
my $problem_desc = undef;
my $Transaction = $self->TransactionObj;
my $subject = $Transaction->Attachments->First->GetHeader('Subject');
if ($subject =~ /\*\* RECOVERY (\w+) - (.*) OK \*\*/) {
# 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 => 'General');
$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+) - (.*) (\w+) \*\*/ ) {
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 OA number 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;
</pre><br><br></div>
<div class="gmail_quote">On Thu, Jun 11, 2009 at 3:37 AM, Matthew Seaman <span dir="ltr"><<a href="mailto:matthew.seaman@thebunker.net">matthew.seaman@thebunker.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="im">rmp dmd wrote:<br>> Thank you very much Drew. Your link definitely is a big help.<br>><br>> The syntax are quite different with the programming applications that I am<br>> familiar (very few though). It's very hard modifying it for our specific<br>
> use. Is there a guide about this?<br><br></div>These are perl regular expressions. See<br><a href="http://perldoc.perl.org/perlre.html" target="_blank">http://perldoc.perl.org/perlre.html</a> for details, but the following means...<br>
<div class="im"><br>> For starters, someone kindly teach me the meaning of \w+) - (.*) (\w+) on<br><br>> Subject =~ /\*\* PROBLEM (\w+) - (.*) (\w+) \*\*/ )<br><br></div> / <-- start of matching operator<br>
\*\* <-- match two * characters literally. Without<br> the \ escape, * is an operator that means<br> 'zero or more times'<br> PROBLEM <-- match literal text<br>
( <-- start of capture group<br> \w+ <-- one or more 'word' characters<br> ) <-- close capture group<br> - <-- match literal text<br>
(.*) <-- capture group of zero or<br> more of any sequence of<br> characters. '.' is the<br>
wildcard character<br> <-- match literal ' ' char<br> (\w+) <-- capture group of one<br>
or more word chars.<br> <-- another space<br> \*\* <-- two more stars<br>
/ <-- end of match<br> expression<br><br> Note that all the white space in the expression also has to match<br>
literally. In summary this captures 3 strings out of the matched<br> text: the first word after '** PROBLEM ', Everything in the middle<br> and then the last word at the end before ' **'.<br>
<div class="im"><br>><br>> and *(\d\d\d\d\d\d?) on<br>><br>> $subject =~ /\D*(\d\d\d\d\d\d?)\D*/)<br><br></div> \D is a non-digit character. \d is a digit, so this matches any<br> number of non-digit characters \D*, then it captures 5 digits<br>
\d\d\d\d\d and possibly also a 6th digit \d? (? is an operator<br> meaning 0 or 1 times) followed by any number of non-digit characters<br> \D* again. You could write the capture expression bit as (\d{5,6})<br> meaning 'from 5 to 6 digits'<br>
<br> Cheers,<br><br> Matthew<br><font color="#888888"><br>--<br>Dr Matthew Seaman The Bunker, Ash Radar Station<br>PGP: 0x60AE908C on servers Marshborough Rd<br>Tel: +44 1304 814890 Sandwich<br>
Fax: +44 1304 814899 Kent, CT13 0PL, UK<br><br></font></blockquote></div><br>