[rt-users] help in creating Scrips

rmp dmd rmp.dmd1229 at gmail.com
Thu Jun 11 12:20:16 EDT 2009


Thank you very Matthew for that concise response. Appreciate it!

Follow-up though or anyone who understand scrips, kindly help.

Please teach me what is OPERATOR => '=', ENTRYAGGREGATOR,
   OPERATOR value is expecting from status.

This is the line from the scrip:

$search->LimitStatus(VALUE => 'new', OPERATOR => '=', ENTRYAGGREGATOR =>
'or');
$search->LimitStatus(VALUE => 'open', OPERATOR => '=');

The entire script is below.

Thank you very much!
Roehl


# 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 $Transaction = $self->TransactionObj;
my $subject = $Transaction->Attachments->First->GetHeader('Subject');
if ($subject =~ /\*\* RECOVERY (\w+) - (.*) OK \*\*/) {
    # 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 => '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) {
    # 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+) - (.*) (\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...
        }
    }
}

$id || return 1;
# Auto-close/resolve this whole thing
$self->TicketObj->SetStatus( "resolved" );
1;



On Thu, Jun 11, 2009 at 3:37 AM, Matthew Seaman <
matthew.seaman at thebunker.net> wrote:

> rmp dmd wrote:
> > Thank you very much Drew. Your link definitely is a big help.
> >
> > The syntax are quite different with the programming applications that I
> am
> > familiar (very few though).  It's very hard modifying it for our specific
> > use. Is there a guide about this?
>
> These are perl regular expressions.  See
> http://perldoc.perl.org/perlre.html for details, but the following
> means...
>
> > For starters, someone kindly teach me the meaning of \w+) - (.*) (\w+) on
>
> > Subject =~ /\*\* PROBLEM (\w+) - (.*) (\w+) \*\*/ )
>
>             /   <-- start of matching operator
>               \*\*    <-- match two * characters literally.  Without
>                           the \ escape, * is an operator that means
>                           'zero or more times'
>                   PROBLEM <-- match literal text
>                           (  <-- start of capture group
>                             \w+  <-- one or more 'word' characters
>                                ) <-- close capture group
>                                  -  <-- match literal text
>                                     (.*)   <-- capture group of zero or
>                                                more of any sequence of
>                                                characters. '.' is the
>                                                wildcard character
>                                            <-- match literal ' ' char
>                                         (\w+) <-- capture group of one
>                                                   or more word chars.
>                                                 <-- another space
>                                                \*\*  <-- two more stars
>                                                    / <-- end of match
>                                                          expression
>
>  Note that all the white space in the expression also has to match
>  literally.  In summary this captures 3 strings out of the matched
>  text: the first word after '**  PROBLEM ', Everything in the middle
>  and then the last word at the end before ' **'.
>
> >
> > and *(\d\d\d\d\d\d?) on
> >
> > $subject =~ /\D*(\d\d\d\d\d\d?)\D*/)
>
>   \D is a non-digit character.  \d is a digit, so this matches any
>   number of non-digit characters \D*, then it captures 5 digits
>   \d\d\d\d\d and possibly also a 6th digit \d? (? is an operator
>   meaning 0 or 1 times) followed by any number of non-digit characters
>   \D* again.  You could write the capture expression bit as (\d{5,6})
>   meaning 'from 5 to 6 digits'
>
>        Cheers,
>
>        Matthew
>
> --
> Dr Matthew Seaman                        The Bunker, Ash Radar Station
> PGP: 0x60AE908C on servers               Marshborough Rd
> Tel: +44 1304 814890                     Sandwich
> Fax: +44 1304 814899                     Kent, CT13 0PL, UK
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20090611/369ab9d0/attachment.htm>


More information about the rt-users mailing list