<div class="gmail_quote">Hi all,<br><br>I am trying create a scrip in RT3 for close automaticly the tickets from Nagios alert.<br><br>I am working from the scrips "AutoCloseOnNagiosRecoveryMessages - RT Integration" from website<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>
<p class="MsoNormal"><span lang="EN-GB"><a href="http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages" target="_blank">http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages</a></span></p><p class="MsoNormal">
<a href="http://goog_1257158193783" target="_blank"></a></p><p class="MsoNormal">
</p><p class="MsoNormal"><span lang="EN-GB"><a href="https://wiki.koumbit.net/RequestTracker/NagiosBridge" target="_blank">https://wiki.koumbit.net/RequestTracker/NagiosBridge</a></span></p>
<span lang="EN-GB"></span><p></p>
<br><br>But with RT3 3.8.6 and Nagios 3.2, The subject of the email is not analyzed 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 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 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>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 => '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> 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> $RT::Logger->debug("Scrip 14 : 1 ticket trouvé $ticket->Id avec 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 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 => 0);<br>
<br>}<br>1;<br><br><br><br><br><br><br><br><br><br>----------------<br><br><br>
</div><br>