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

Thomas Hecker thomas.hecker at ffpr.de
Thu Jul 12 08:03:59 EDT 2007


Hi,

thanks for your support so far.

I did a lot of tests, but it still dont work. I added a screenshot of my
script as a created it in the web gui. You can see it here:
http://www.asymmetry.de/scrip.jpg

But it still does not work. Here is what i did:

Custom condition:
my $Transaction = $self->TransactionObj;
return $Transaction->$Transaction->Subject ='HMPF';

Custom action preparation
return 1;

Custom action cleanup
my $Ticket = $self->TicketObj;
$Ticket->SetStatus('resolved');
return 1;

I'm not really shure about the brackets ({}). in the last mail there where
brackets in the custom condition field but not in the cleanup, so i'm not
shure about that. Also if i have to return 1; or return 1; (writing the word
return inside the scripbt or not).

So maybe sombody has the final answer :)

Again thanks a lot for the support so far!

Best regards
Thomas


Am 11.07.2007 19:12 Uhr schrieb "Gene  LeDuc" unter <gleduc at mail.sdsu.edu>:

> Hi Thomas,
> 
> You create scrips like this using the RT web GUI.  Go into Configuration,
> select Queues, then the queue that you want this scrip to apply to, then
> Scrips, then New Scrip.  I don't think you really want to do this with perl
> modules.
> 
> For condition, select "User Defined"
> For action, select "User Defined"
> For template, select "Global template: Blank" (actually, I don't think it
> matters what you select for a template if the action is user-defined, but
> you have to select something).
> For stage, select "TransactionCreate"
> 
> In the Custom condition area you want to trap transactions that are
> Type:Correspond (e-mail) and that have "HMPF" in the subject.  Your custom
> condition could look something like this:
>    { my $Transaction = $self->TransactionObj;
>      return $Transaction->Type eq 'Correspond' && $Transaction->Subject =~
> /HMPF/;
>    }
> 
> This will cause the scrip to fire when a transaction occurs that is an
> e-mail that has HMPF in the subject, otherwise the scrip will not fire.
> 
> In the Custom action preparation code area you can just put:
>    return 1;
> 
> This does nothing except allow the cleanup action to run.  If you leave it
> out then the cleanup action won't run.
> 
> In the Custom action cleanup code area you could have something like this:
>    my $Ticket = $self->TicketObj;
>    $Ticket->SetStatus('resolved');
>    return 1;
> 
> This will change the status of the ticket to resolved.  It will also create
> another transaction that will trigger any "On Resolve" scrips you might have.
> 
> All of this is done within the RT web GUI.
> 
> Good luck with this,
> Gene
> 
> 
> At 09:20 AM 7/11/2007, Thomas Hecker wrote:
>> 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
>>>>>> 
>>>>>> 
>>>> 
>>>> 
>>>> 
>> 
>> 
>> _______________________________________________
>> 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