[rt-users] Scrip needed that automaticaly closes tickets with a special subject

Thomas Hecker thomas.hecker at ffpr.de
Wed Jul 11 12:20:39 EDT 2007


Hi,

well i changed the scrip this way:

my $problem_desc = undef;

my $Transaction = $self->TransactionObj;
my $subject = $Transaction->Attachments->First->GetHeader('Subject');
if ( $subject =~ /^HMPF (\w+) - (\S*) (\S*)/ ) {
    # Auto-close/resolve this whole thing
    $self->TicketObj->SetStatus( "resolved" );
} else {
    return 1;
}
1;

So it should set a ticket to solved when the subject contains HMPF - right?

The next problem i have is, how do i implement this scrip to rt? I saved it
as an .pm file and put it into the lib to all the other scrips. than i wrote
a perl script described in the o'reilly book page 81, to make the scrip
available to the RTR database:

#!usr/bin/perl

use strict;
use lib "/usr/share/request-tracker3.6/lib";

use RT;
use RT::Interface::CLI qw( CleanEnv GetCurrentUser );
use RT::ScripCondition;

CleanEnv();
RT::LoadConfig();
RT::Init();

my $user = GetCurrentUser();
unless( $user->Id ) {
        print "No RT user found. Please consult your GOD\n";
        exit 1;
}

my $sc = RT::ScripCondition->new($user);

$sc->Create( Name => 'HMPF-Betreff',
             Beschreibung => 'Wenn Betreff enthaelt HMPF dann schliesse
sofort',
             ExecModule => 'OnCreate',
             ApplicableTransTypes => 'Status',
             );

When i run this scrip i get no error, but the scrip is not available in the
webinterface of rt.

what's wrong?

Thanks for help
Thomas



Am 05.07.2007 15:12 Uhr schrieb "Drew Barnes" unter
<barnesaw at ucrwcu.rwc.uc.edu>:

> I think this should be correct, but I haven't used this particular scrip
> lately.
> 
> 
> # 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 "zNagios" 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 $Transaction = $self->TransactionObj;
> my $subject = $Transaction->Attachments->First->GetHeader('Subject');
> if ( $subject =~ /^RECOVERY (\w+) - (\S*) (\S*)/ ) {
>     # This looks like a nagios recovery message
>     $problem_desc = $2;
> 
>     $RT::Logger->debug("Found a recovery msg: $problem_desc");
> } else {
>     return 1;
> }
> 
> # Ok, now let's merge this ticket with it's PROBLEM msg.
> my $search = RT::Tickets->new($RT::SystemUser);
> $search->LimitQueue(VALUE => 'zNagios');
> $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) {
>     # 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*) (\S*)/ ) {
>         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 Nagios Subject match.");
>             $self->TicketObj->MergeInto($id);
>             # Keep looking for more PROBLEM tickets...
>         }
>     }
> }
> 
> $id || return 1;
> # Auto-close/resolve this whole thing
> $self->TicketObj->SetStatus( "resolved" );
> 1;
> 
> Thomas Hecker wrote:
>> i Thanks for the hint, i'll try my best, but i have problems finding the
>> right line breaks. can anybody help? All modifications i'll try then by
>> myself :)
>> 
>> Thanks again
>> Thomas
>> 
>> 
>> Am 03.07.2007 15:15 Uhr schrieb "Drew Barnes" unter
>> <barnesaw at ucrwcu.rwc.uc.edu>:
>> 
>>   
>>> I would look at modifying this to suit your needs.
>>> http://wiki.bestpractical.com/view/AutoCloseOnNagiosRecoveryMessages
>>> 
>>> Thomas Hecker wrote:
>>>     
>>>> Hi all,
>>>> 
>>>> i use RT 3.6.1 and look for a scrip that automatically closes new ticktes
>>>> that have subjects that contain special words.
>>>> 
>>>> an example:
>>>> 
>>>> i have some UPS from APC wich send emails after performing selftesting. The
>>>> subject is somehing like "HOMER passes internal self test" where HOMER is
>>>> the name of the UPS. This email should be sent to rt. RT then opens a new
>>>> ticket. Now i want a scrip that closes the ticket automatically when the
>>>> subject of an email contains specail words. So status mails will still
>>>> generate tickets but are closed immediately (fpt statistic purpose). Status
>>>> mails with an error like "Error 123 while HOMER performing self test" then
>>>> correctly will open a ticket that stays open.
>>>> 
>>>> My problem here is, that i know nothing about perl coding, so i can't code
>>>> this scrip by myself. Maybe sombody has allready a scrip wich works
>>>> similar,
>>>> or maybe somebody could code it?
>>>> 
>>>> Thanks for help
>>>> Thomas
>>>> 
>>>> 
>>>> _______________________________________________
>>>> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>>>> 
>>>> Community help: http://wiki.bestpractical.com
>>>> Commercial support: sales at bestpractical.com
>>>> 
>>>> 
>>>> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
>>>> Buy a copy at http://rtbook.bestpractical.com
>>>>   
>>>>       
>> 
>> 
>>   





More information about the rt-users mailing list