My problem is solved.<br><br>I have used the soft : "Rad Software Regular Expression Designer" to find the good sentence for Regex.<br><br>The final Scrip for Nagios AutoClose is :<br><br>-----------<br><br># If the subject of the ticket matches a pattern suggesting<br>
# that this is a Nagios RECOVERY message AND there is<br># an existing ticket (open or new) in the "General" queue with a matching<br># "problem description", (that is not this ticket)<br># merge this ticket into that ticket<br>
#<br># 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><br><br>my $problem_desc = undef;<br>my $report_type = undef;<br>
my $report_value = undef;<br><br>$RT::Logger->debug("Message Lancement Scrip 14");<br><br>my $Transaction = $self->TransactionObj;<br>my $subject = $Transaction->Attachments->First->GetHeader('Subject');<br>
#if ($subject =~ /\*\* RECOVERY (.*) OK \*\*/) {<br>if ($subject =~ /\*\* RECOVERY (\w+(?:\s*\d+)?) (.*) is (\w+) \*\*/) {<br> # This looks like a nagios recovery message<br> #$report_type = $1;<br> #$problem_desc = $3;<br>
$report_type = $1;<br> $problem_desc = $2;<br> $report_value = $3;<br><br> $RT::Logger->debug("Found a recovery msg: $report_type - $problem_desc");<br>} else {<br> $RT::Logger->debug("Not a recovery msg: $report_type - $problem_desc");<br>
return 1;<br>}<br><br># Ok, now let's merge this ticket with it's PROBLEM msg.<br>my $search = RT::Tickets->new($RT::SystemUser);<br>$search->LimitQueue(VALUE => 'General');<br>$search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR => 'or');<br>
$search->LimitStatus(VALUE => 'open', OPERATOR => '=');<br><br>if ($search->Count == 0) { return 1; }<br>my $id = undef;<br>while (my $ticket = $search->Next) {<br> # Ignore the ticket that opened this transation (the recovery one...)<br>
next if $self->TicketObj->Id == $ticket->Id;<br> # Look for nagios PROBLEM warning messages...<br> if ( $ticket->Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) (.*) is (\w+) \*\*/ ) {<br> if ($2 eq $problem_desc){<br>
# Aha! Found the Problem TICKET corresponding to this RECOVERY<br> # ticket<br> $id = $ticket->Id;<br> # Nagios may send more then one PROBLEM message, right?<br> $RT::Logger->debug("Merging ticket " . $self->TicketObj->Id . " into $id because of OA number match.");<br>
$self->TicketObj->MergeInto($id);<br> # Keep looking for more PROBLEM tickets...<br> }<br> }<br>}<br><br>$id || return 1;<br><br>if ($subject =~ /\*\* RECOVERY (.*) OK \*\*/) {<br> # Auto-close/resolve this whole thing<br>
$self->TicketObj->SetStatus( "resolved" );<br>}<br>1;<br><br><br><br><br><br>-----------<br><br><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Rodolphe ALT</b> <span dir="ltr"><<a href="mailto:rodolphe.alt@gmail.com">rodolphe.alt@gmail.com</a>></span><br>
Date: 2009/11/2<br>Subject: Re: [rt-users] help in creating Scrips (Nagios autoclose)<br>To: <a href="mailto:RT-Users@lists.bestpractical.com">RT-Users@lists.bestpractical.com</a><br>Cc: <a href="mailto:Richard.Foley@rfi.net">Richard.Foley@rfi.net</a><br>
<br><br><div class="gmail_quote"><div class="im">Hi Richard,<br><br>I have try without dash. (thanks for that)<br><br>But it is always the same result (not detected)<br><br>Regex is :<div><br>Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) (.*) is (\w+) \*\*/<br>
<br></div>Subject Email is:<br></div>
Subject = <span>** PROBLEM Service Alert: srv08.athome.local/Portail is CRITICAL **</span><br><span><br><br><br><br>Regards,<br></span><div><div></div><div class="h5"><br>
<br>Rodolphe<br><br><div class="gmail_quote">
2009/11/2 Richard Foley <span dir="ltr"><<a href="mailto:Richard.Foley@rfi.net" target="_blank">Richard.Foley@rfi.net</a>></span><div><div></div><div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You've got a dash (-) character in your regex which doesn't appear in the<br>
subject line of the mail.<br>
<div><br>
Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) - (.*) is (\w+) \*\*/<br>
</div> ^<br>
Which might have something to do with it?<br>
<br>
--<br>
Richard Foley<br>
Ciao - shorter than aufwiedersehen<br>
<br>
<a href="http://www.rfi.net/" target="_blank">http://www.rfi.net/</a><br>
<div><br>
On Monday 02 November 2009 12:00:07 Rodolphe ALT wrote:<br>
> Hi all,<br>
><br>
> I am trying create a scrip in RT3 for close automaticly the tickets from<br>
> Nagios alert.<br>
><br>
> I am working from the scrips "AutoCloseOnNagiosRecoveryMessages - RT<br>
> Integration" from website<br>
><br>
><br>
<a href="http://exchange.nagios.org/directory/Addons/Helpdesk-and-Ticketing/RT/AutoCloseOnNagiosRecoveryMessages-%252D-RT-Integration/details" target="_blank">http://exchange.nagios.org/directory/Addons/Helpdesk-and-Ticketing/RT/AutoCloseOnNagiosRecoveryMessages-%252D-RT-Integration/details</a><br>
><br>
> <a href="http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages" target="_blank">http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages</a><br>
><br>
</div>> <goog_1257158193783><br>
<div><div></div><div>><br>
> <a href="https://wiki.koumbit.net/RequestTracker/NagiosBridge" target="_blank">https://wiki.koumbit.net/RequestTracker/NagiosBridge</a><br>
><br>
><br>
><br>
> But with RT3 3.8.6 and Nagios 3.2, The subject of the email is not analyzed<br>
> correctly.<br>
><br>
> I mean when I have enabled debug log and this is a log messages like :<br>
> [Mon Nov 2 10:30:33 2009] [debug]: Committing scrip #14 on txn #397 of<br>
> ticket #46 (/opt/rt3/bin/../lib/RT/Scrips_Overlay.pm:190)<br>
> [Mon Nov 2 10:30:33 2009] [debug]: Message Lancement Scrip 14 ((eval<br>
> 2528):12)<br>
> [Mon Nov 2 10:30:33 2009] [debug]: Found a recovery msg: ((eval 2528):21)<br>
> [Mon Nov 2 10:30:33 2009] [debug]: Boucle 14 : 45 ((eval 2528):36)<br>
> [Mon Nov 2 10:30:33 2009] [debug]: Boucle 14 : 46 ((eval 2528):36)<br>
> [Mon Nov 2 10:30:33 2009] [debug]: Boucle 14 : 27 ((eval 2528):36)<br>
><br>
> And that' all. not Merging ticket !<br>
><br>
><br>
> in scrip, I think this is the line who detect not the ticket :<br>
> if ( $ticket->Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) - (.*) is (\w+)<br>
> \*\*/ ) {<br>
><br>
> I have tested also without success :<br>
> if ( $ticket->Subject =~ /\*\* PROBLEM (\w+) - (.*) (\w+) \*\*/ ) {<br>
><br>
><br>
> And the email subject is like :<br>
> ** PROBLEM Service Alert: srv08.athome.local/Portail is CRITICAL **<br>
> ** RECOVERY Service Alert: srv08.athome.local/Portail is OK **<br>
><br>
><br>
> Can you help me to resolve this code ?<br>
><br>
><br>
> Thanks,<br>
><br>
> Regards,<br>
><br>
> Rodolphe<br>
><br>
><br>
> ----------------<br>
><br>
><br>
> ALL CODE of actual scrip is here :<br>
><br>
> # If the subject of the ticket matches a pattern suggesting<br>
> # that this is a Nagios RECOVERY message AND there is<br>
> # an existing ticket (open or new) in the "General" queue with a matching<br>
> # "problem description", (that is not this ticket)<br>
> # merge this ticket into that ticket<br>
> #<br>
> # Based on <a href="http://marc.free.net.ph/message/20040319.180325.27528377.en.html" target="_blank">http://marc.free.net.ph/message/20040319.180325.27528377.en.html</a><br>
><br>
> my $problem_desc = undef;<br>
> my $report_type = undef;<br>
><br>
> $RT::Logger->debug("Message Lancement Scrip 14");<br>
><br>
> my $Transaction = $self->TransactionObj;<br>
> my $subject = $Transaction->Attachments->First->GetHeader('Subject');<br>
> if ($subject =~ /\*\* RECOVERY (.*) OK \*\*/) {<br>
> # This looks like a nagios recovery message<br>
> $report_type = $1;<br>
> $problem_desc = $3;<br>
><br>
> $RT::Logger->debug("Found a recovery msg: $problem_desc");<br>
> } else {<br>
> $RT::Logger->debug("Not a recovery msg: $problem_desc");<br>
> return 1;<br>
> }<br>
><br>
> # Ok, now let's merge this ticket with it's PROBLEM msg.<br>
> my $search = RT::Tickets->new($RT::SystemUser);<br>
> $search->LimitQueue(VALUE => 'General');<br>
> $search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR =><br>
> 'or');<br>
> $search->LimitStatus(VALUE => 'open', OPERATOR => '=');<br>
><br>
> if ($search->Count == 0) { return 1; }<br>
> my $id = undef;<br>
> while (my $ticket = $search->Next) {<br>
> $RT::Logger->debug("Boucle 14 : ".($ticket->Id));<br>
> # Ignore the ticket that opened this transation (the recovery one...)<br>
> next if $self->TicketObj->Id == $ticket->Id;<br>
> # Look for nagios PROBLEM warning messages...<br>
> if ( $ticket->Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) - (.*) is (\w+)<br>
> \*\*/ ) {<br>
> if ($2 eq $problem_desc){<br>
> # Aha! Found the Problem TICKET corresponding to this RECOVERY<br>
> # ticket<br>
> $id = $ticket->Id;<br>
> # Nagios may send more then one PROBLEM message, right?<br>
> $RT::Logger->debug("Merging ticket " . $self->TicketObj->Id . "<br>
> into $id because of OA number match.");<br>
> $self->TicketObj->MergeInto($id);<br>
> # Keep looking for more PROBLEM tickets...<br>
> $RT::Logger->debug("Scrip 14 : 1 ticket trouvé $ticket->Id avec<br>
> la régle 1!");<br>
><br>
> }<br>
> }<br>
><br>
> if ( $ticket->Subject =~ /\*\* PROBLEM (\w+) - (.*) (\w+) \*\*/ ) {<br>
> $RT::Logger->debug("Scrip 14 : 1 ticket trouvé $ticket->Id avec la<br>
> régle 2!");<br>
> }<br>
> }<br>
><br>
> $id || return 1;<br>
><br>
> if ($report_type eq "RECOVERY") {<br>
> # Auto-close/resolve this whole thing<br>
> $self->TicketObj->SetStatus( "resolved" );<br>
> #$Ticket->_Set(Field => 'Status', Value => 'resolved', RecordTransaction =><br>
> 0);<br>
><br>
> }<br>
> 1;<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> ----------------<br>
><br>
<br>
<br>
</div></div></blockquote></div></div></div><br>
</div></div></div><br>
</div><br>