# Ripped from the RT Wiki -- Originally designed for Nagios & refactored for InterMapper # If the subject of the ticket matches a pattern suggesting # that this is an OK (recovery) message and we have an exiting ticket # (open or new) with a matching subject merge this ticket into that ticket # and consider the case resolved. my $problem_desc = undef; my $msg_type = undef; my $Transaction = $self->TransactionObj; my $subject = $Transaction->Attachments->First->GetHeader('Subject'); my $from = $Transaction->Attachments->First->GetHeader('From'); if ($from =~ /monitor/ && $subject =~ /^(Warning|Alarm|Critical|OK): (.+)/) { # This looks like an InterMapper message $msg_type = $1; $problem_desc = $2; if ($msg_type eq 'OK') { $RT::Logger->debug("Found a recovery msg: $msg_type $problem_desc"); } else { $RT::Logger->debug("Found a problem msg: $msg_type $problem_desc"); } } else { # It's not an InterMapper message (or not a handled message type) $RT::Logger->debug("Not an InterMapper message."); return 1; } # We have an InterMapper message: Search for a ticket about this issue that # we can merge into... my $search = RT::Tickets->new($RT::SystemUser); $search->LimitQueue(VALUE => $self->TicketObj->Queue ); $search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR => 'or'); $search->LimitStatus(VALUE => 'open', OPERATOR => '='); # If there are no open tickets this is obviously the first we've heard of this incident! if ($search->Count == 0) { return 1; } my $id = undef; while (my $ticket = $search->Next) { # Ignore the ticket that invoked this request next if $self->TicketObj->Id == $ticket->Id; # Look for Warning/Alarm/Critical messages... if ( $ticket->Subject =~ /(Warning|Alarm|Critical): (.+)/ ) { if ($2 eq $problem_desc){ $id = $ticket->Id; $RT::Logger->debug("Merging ticket " . $self->TicketObj->Id . " into $id because of OA number match."); $self->TicketObj->MergeInto($id); # InterMapper may send more then one PROBLEM message, so # Keep looking for more PROBLEM tickets... } } } $id || return 1; if ($msg_type eq 'OK') { # If we got an "OK" message the issue is taken care of, so # resolve the ticket. $self->TicketObj->SetStatus( "resolved" ); } 1;