[rt-users] help in creating Scrips (Nagios autoclose)

Richard Foley Richard.Foley at rfi.net
Mon Nov 2 06:06:28 EST 2009


You've got a dash (-) character in your regex which doesn't appear in the 
subject line of the mail.

    Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) - (.*) is (\w+) \*\*/
                                              ^
Which might have something to do with it?

--
Richard Foley
Ciao - shorter than aufwiedersehen

http://www.rfi.net/

On Monday 02 November 2009 12:00:07 Rodolphe ALT wrote:
> Hi all,
> 
> I am trying create a scrip in RT3 for close automaticly the tickets from
> Nagios alert.
> 
> I am working from the scrips "AutoCloseOnNagiosRecoveryMessages - RT
> Integration" from website
> 
> 
http://exchange.nagios.org/directory/Addons/Helpdesk-and-Ticketing/RT/AutoCloseOnNagiosRecoveryMessages-%252D-RT-Integration/details
> 
> http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages
> 
> <goog_1257158193783>
> 
> https://wiki.koumbit.net/RequestTracker/NagiosBridge
> 
> 
> 
> But with RT3 3.8.6 and Nagios 3.2, The subject of the email is not analyzed
> correctly.
> 
> I mean when I have enabled debug log and this is a log messages like :
> [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)
> [Mon Nov  2 10:30:33 2009] [debug]: Message Lancement Scrip 14 ((eval
> 2528):12)
> [Mon Nov  2 10:30:33 2009] [debug]: Found a recovery msg:  ((eval 2528):21)
> [Mon Nov  2 10:30:33 2009] [debug]: Boucle 14 : 45 ((eval 2528):36)
> [Mon Nov  2 10:30:33 2009] [debug]: Boucle 14 : 46 ((eval 2528):36)
> [Mon Nov  2 10:30:33 2009] [debug]: Boucle 14 : 27 ((eval 2528):36)
> 
> And that' all. not Merging ticket !
> 
> 
> in scrip, I think this is the line who detect not the ticket :
>     if ( $ticket->Subject =~ /\*\* PROBLEM (\w+(?:\s*\d+)?) - (.*) is (\w+)
> \*\*/ ) {
> 
> I have tested also without success :
> if ( $ticket->Subject =~ /\*\* PROBLEM (\w+) - (.*) (\w+) \*\*/ ) {
> 
> 
> And the email subject is like :
> ** PROBLEM Service Alert: srv08.athome.local/Portail is CRITICAL **
> ** RECOVERY Service Alert: srv08.athome.local/Portail is OK **
> 
> 
> Can you help me to resolve this code ?
> 
> 
> Thanks,
> 
> Regards,
> 
> Rodolphe
> 
> 
> ----------------
> 
> 
> ALL CODE of actual scrip is here :
> 
> # 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 http://marc.free.net.ph/message/20040319.180325.27528377.en.html
> 
> my $problem_desc = undef;
> my $report_type = undef;
> 
> $RT::Logger->debug("Message Lancement Scrip 14");
> 
> my $Transaction = $self->TransactionObj;
> my $subject = $Transaction->Attachments->First->GetHeader('Subject');
> if ($subject =~ /\*\* RECOVERY (.*) OK \*\*/) {
>     # This looks like a nagios recovery message
>     $report_type = $1;
>     $problem_desc = $3;
> 
>     $RT::Logger->debug("Found a recovery msg: $problem_desc");
> } else {
>     $RT::Logger->debug("Not a recovery msg: $problem_desc");
>     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) {
>     $RT::Logger->debug("Boucle 14 : ".($ticket->Id));
>     # 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+(?:\s*\d+)?) - (.*) is (\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...
>             $RT::Logger->debug("Scrip 14 : 1 ticket trouvé $ticket->Id  avec
> la régle 1!");
> 
>         }
>     }
> 
>    if ( $ticket->Subject =~ /\*\* PROBLEM (\w+) - (.*) (\w+) \*\*/ ) {
>     $RT::Logger->debug("Scrip 14 : 1 ticket trouvé $ticket->Id  avec la
> régle 2!");
>    }
> }
> 
> $id || return 1;
> 
> if ($report_type eq "RECOVERY") {
>   # Auto-close/resolve this whole thing
>   $self->TicketObj->SetStatus( "resolved" );
> #$Ticket->_Set(Field => 'Status', Value => 'resolved', RecordTransaction =>
> 0);
> 
> }
> 1;
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ----------------
> 





More information about the rt-users mailing list