<div>Hi,</div>
<div> </div>
<div>Thanks for the numerous response and I was able to have a scrip that merges RECOVERY alerts from nagios with PROBLEM tickets. </div>
<div>I need help again for minor modifications.I prefer to merge PROBLEM open tickets to the RECOVERY alert ID. </div>
<div> </div>
<div>Here's how the scrip goes: </div>
<div> </div>
<div>An alert, ** PROBLEM alert - TESTONLYE DC2/check_test is CRITICAL **. RT will assigned ID 2912</div>
<div>A new alert, ** PROBLEM alert - TESTONLYE DC2/check_test is CRITICAL **. RT will assigned new ID 2913.</div>
<div>A recovery alert, ** RECOVERY alert - TESTONLYE DC2/check_test is OK **. RT will assigned #2915.</div>
<div> </div>
<div>The scrip will merge </div>
<div>ticket 2915 into 2912 </div>
<div>ticket 2912 into 2913 </div>
<div> </div>
<div>I prefer to merge 2912 and 2913 into 2915. So when I lookup tickets, it'll be easier for us.</div>
<div> </div>
<div>I've been playing around with the scrips but nothing came out right. </div>
<div> </div>
<div>Need help. Thanks!</div>
<div> </div>
<div> </div>
<div>The working scrip is below.</div>
<div> </div>
<div># 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 "IT" 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></div>
<div>my $problem_desc = undef;</div>
<div>my $Transaction = $self->TransactionObj;<br>my $subject = $Transaction->Attachments->First->GetHeader('Subject');<br>if ($subject =~ /\*\* RECOVERY (\w+) - (.*) OK \*\*/) {<br> # This looks like a nagios recovery message<br>
$problem_desc = $2;</div>
<div> $RT::Logger->debug("Found a recovery msg: $problem_desc");<br>} else {<br> return 1;<br>}</div>
<div># Ok, now let's merge this ticket with it's PROBLEM msg.<br>my $search = RT::Tickets->new($RT::SystemUser);<br>$search->LimitQueue(VALUE => 'IT');<br>$search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR => 'or');<br>
$search->LimitStatus(VALUE => 'open', OPERATOR => '=');</div>
<div>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+) - (.*) (\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>}</div>
<div>$id || return 1;</div>
<div># Auto-close/resolve this whole thing<br>#$self->TicketObj->SetStatus( "resolved" );<br>1;</div>