NotificationsTuning

From Request Tracker Wiki
Revision as of 08:53, 18 July 2018 by Phanousk (talk | contribs) (→‎Patch to send less notifications)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

NotificationsTuning

This page describes a team organization example, and how we send notifications. We talk about an IT team, managing servers and applications.

Introduction

We have in our RT many queues, and from 2 to 4 adminccs per queue. The incoming tickets arrive in an INCOMING queue and are dispatched by some people to the appropriate queue. When a ticket enters a queue, it belongs to nobody and one of the adminccs takes the ticket (depending on the workload of each others, holidays etc...). Then the ticket lives and is resolved. I describe here the notifications we use, hoping it will help people. Any comments/optimizations/etc are welcome at the end of the file.

Summary

When a new ticket is created :

  • notify requestor with an autoreply
  • notify owner he has a new ticket (if the ticket was created and assigned at the same time)
  • notify adminccs of the queue that a new ticket is available in their queue

When there is an owner change :

  • notify (new) owner
  • notify other adminccs that the ticket is taken by one of them (so they don't have to take care of it)

When there is a queue change :

  • notify adminccs of the new queue there is a new ticket

When there is a correspondance on a ticket (reply):

  • notify requestors, ccs
  • notify other recipients
  • notify owner
  • notify adminccs

When there is a comment on a ticket :

  • notify owner
  • notify admincc

When a ticket is resolved :

  • notify requestor
  • notify adminccs someone (one of them) resolved the ticket

I created new templates starting with "MY" and associated them to scrips. I put in these templates what makes sense to me, and I added a line explaining the reason why you receive this mail.

Patch to send less notifications

But with this configuration (and with the default one), we had a problem : we received too many emails for the same thing : For example :

  • a (privilieged) user sends a request to RT for a task he has to do.
  • people managing tickets assign it to him, and put it in a queue he is admincc for

So this user is requestor, owner, and admincc : he gets 3 emails on each correspondence. The issue was consulted with Best Practical support and they have produced a patch for this case. There is no option here to upload a .pm file so the code is here. Put it in Notify_Vendor.pm and this file to appropriate folder. More information in CustomizingWithOverlays.

<pre>
package RT::Action::Notify;

use strict;
use warnings;


=head2 RemoveInappropriateRecipients

Remove transaction creator as appropriate for the NotifyActor setting.

To send email to the selected receipients regardless of RT's NotifyActor
configuration, include AlwaysNotifyActor in the list of arguments.

=cut

sub RemoveInappropriateRecipients {
    my $self = shift;

    my $creatorObj = $self->TransactionObj->CreatorObj;
    my $creator = $creatorObj->EmailAddress() || '';
    my $TransactionCurrentUser = RT::CurrentUser->new;
    $TransactionCurrentUser->LoadByName($creatorObj->Name);

    $self->RecipientFilter(
        Callback => sub {
            return unless lc $_[0] eq lc $creator;
            return "not sending to $creator, creator of the transaction, due to NotifyActor setting";
        },
    ) unless RT->Config->Get('NotifyActor',$TransactionCurrentUser)
             || $self->Argument =~ /\bAlwaysNotifyActor\b/;

    # Custom code to block email to Requestor if a recipient is both Requestor and AdminCc

    # Only run on Requestor scrips
    if ( $self->Argument =~ /\bRequestor\b/ ) {

        my @req_and_admincc;
        my @requestors = $self->TicketObj->Requestors->MemberEmailAddresses();

        # Get ticket and queue adminccs, both individual users and groups
        my %adminccs;
        foreach my $groups ( $self->TicketObj->AdminCc->GroupMembersObj(),
            $self->TicketObj->QueueObj->AdminCc->GroupMembersObj() ){

            while ( my $group = $groups->Next ){
                foreach my $email ( $group->MemberEmailAddresses() ){
                    $adminccs{$email} = 1;
                }
            }
        }

        foreach my $req_email ( @requestors ){
            push @req_and_admincc, grep { $_ eq $req_email } keys %adminccs;
        }

        $self->RecipientFilter(
            Callback => sub {
                return unless grep { $_[0] eq $_ } @req_and_admincc;
                return "Not sending to $_[0], because they are both Requestor and AdminCc on this ticket";
            },
        ) if @req_and_admincc;
    }

    # End custom code

    $self->SUPER::RemoveInappropriateRecipients();
}

1;
</pre>


Original but ugly patch

This is the patch (ugly patch but it works) I applied to lib/RT/Action/Notify.pm (well, I created a new file local/lib/RT/Action/Notify.pm) . It has been tested on RT 3.8.2 and 3.8.7. It's not dealing with for example ticket disabled users. But here it is for the historical purposes and inspiration.

<pre>

   # cat Notify.patch
 --- /Notify.pm.orig   2010-01-06 16:03:20.000000000 +0100
 +++ Notify.pm 2010-02-01 16:36:00.000000000 +0100
 @@ -85,6 +85,11 @@
      $arg =~ s/\bAll\b/Owner,Requestor,AdminCc,Cc/;
 
      my ( @To, @PseudoTo, @Cc, @Bcc );
 +    my $requestor_emails = join(' ',($ticket->Requestors->MemberEmailAddresses));
 +    my $admincc_emails = join(' ',($ticket->AdminCc->MemberEmailAddresses));
 +    my $owner_email = join(' ',($ticket->OwnerObj->EmailAddress));
 +    my $queueadmincc_emails = join(' ',($ticket->QueueObj->AdminCc->MemberEmailAddresses));
 +    my @requestor_emails_array = split(/ /,$requestor_emails);
 
 
      if ( $arg =~ /\bOtherRecipients\b/ ) {
 @@ -115,7 +120,7 @@
          }
      }
 
 -    if ( $arg =~ /\bOwner\b/ && $ticket->OwnerObj->id != $RT::Nobody->id ) {
 +    if ( $arg =~ /\bOwner\b/ && $ticket->OwnerObj->id != $RT::Nobody->id && $requestor_emails !~ $owner_email ){
          # If we're not sending to Ccs or requestors,
          # then the Owner can be the To.
          if (@To) {
 @@ -128,8 +133,18 @@
      }
 
      if ( $arg =~ /\bAdminCc\b/ ) {
 -        push ( @Bcc, $ticket->AdminCc->MemberEmailAddresses  );
 -        push ( @Bcc, $ticket->QueueObj->AdminCc->MemberEmailAddresses  );
 +     # Notification already sent for requestor
 +     foreach (@requestor_emails_array){
 +             $admincc_emails =~ s/$_//g;
 +             $queueadmincc_emails =~ s/$_//g;
 +     }
 +     # Notification already sent for owner
 +     $admincc_emails =~ s/$owner_email//g;
 +     $queueadmincc_emails =~ s/$owner_email//g;
 +
 +        push ( @Bcc, $admincc_emails );
 +        push ( @Bcc, $queueadmincc_emails );
 +
      }
 
      if ( RT->Config->Get('UseFriendlyToLine') ) {
</pre>


This is what the patch does :

  • always send an email to the requestor for a correspondance ("Reply")
  • if user is requestor and owner, do not send to the owner (an email has already been sent to the requestor)
  • if a user is requestor or owner and admincc, remove him from the list of admincc (as he has already been notified either because he's a requestor or a owner) and send the email to this list of admincc .

That also means the template received by the user depends on his role (sometimes he will receive the requestor template, sometimes the owner, sometimes the admincc). But as basically it's the same thing, we don't mind.

This is the test matrix :

ROA | S | P | T ------------------ 000 | x | x | x 001 | 1 | 1 | A 010 | 1 | 1 | O 011 | 2 | 1 | O 100 | 1 | 1 | R 101 | 2 | 1 | R 110 | 2 | 1 | R 111 | 3 | 1 | R

  • R : is requestor
  • O : is owner
  • A : is admincc
  • S : Number of emails sent with Standard notify.pm
  • P : Number of emails sent with Patched notify.pm
  • T : Template used (Requestor, Owner, AdminCc)

I've not managed the Cc part, and the comments because our main problem was the duplicate emails generated by correspondences.

And it works very well. No more useless notifications.

Details of the Global scrips :

Id Description                             Stage                    Condition       Action                     Template
 -------------------------------------------------------------------------------------------------------------------------------------------------
 1 Autoreply                                TransactionCreate        User Defined    Autoreply To Requestors    Autoreply
 2 On Create Notify Owner                   TransactionCreate        On Create       Notify Owner               MY Create Notify Owner template
 3 On Create Notify AdminCcs                TransactionCreate        On Create       Notify AdminCcs            MY Create Notify AdminCc template
 
 4 On Owner Change Notify Owner             TransactionCreate        On Owner Change Notify Owner               MY Owner Change Notify Owner template
 5 On Owner Change Notify AdminCc           TransactionCreate        On Owner Change Notify AdminCcs as Comment MY Comment ChangeOwner
 6 On Queue Change Notify AdminCcs          TransactionCreate        On Queue Change Notify AdminCcs            MY Queue Change Notify AdminCcs
 
 7 On Correspond Open Tickets               TransactionCreate        On Correspond   Open Tickets               Blank
 8 On Correspond Notify Requestors and Ccs  TransactionCreate        On Correspond   Notify Requestors and Ccs  MY Correspond Notify Requestor and Ccs
 9 On Correspond Notify Other Recipients    TransactionCreate        On Correspond   Notify Other Recipients    MY Correspond Notify Other recipients
 10 On Correspond Notify Owner              TransactionCreate        On Correspond   Notify Owner               MY Correspond Notify Owner
 11 On Correspond Notify AdminCcs           TransactionCreate        On Correspond   Notify AdminCcs            MY Correspond Notify AdminCc
 
 12 On Comment Notify AdminCcs as Comment   TransactionCreate        On Comment      Notify AdminCcs as Comment MY Comment AdminCc
 13 On Comment Notify Owner as Comment      TransactionCreate        On Comment      Notify Owner as Comment    MY Comment Owner
 
 14 On Resolve Notify Requestors            TransactionCreate        On Resolve      Notify Requestors          MY Ticket Resolved
 15 On Resolve Notify AdminCcs              TransactionCreate        On Resolve      Notify AdminCcs as Comment MY Comment AdminCc Resolved
 
 
 

Templates

Here are the templates :

1) Default

2) MY Create Notify Owner template

RT-Attach-Message: yes
 
 You receive this email because you are owner of a new ticket.
 
 This new ticket has been created and assigned to you:
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
     Owner: {$Ticket->OwnerObj->Name}
    Status: {$Ticket->Status}
   Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

3) MY Create Notify AdminCc template

RT-Attach-Message: yes
 
 You receive this email because you are AdminCc of {$Ticket->QueueObj->Name} queue.
 
 A new ticket has been created in this queue.
 
 Click here to take it :{$RT::WebURL}Ticket/Display.html?Action=Take&id={$Ticket->id}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

4) MY Owner Change Notify Owner template

You receive this email because you become owner of this ticket.
 
 You are now the owner of ticket #{$Ticket->id}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 =====================================================================
 
 
 
 

5) MY Comment ChangeOwner

RT-Attach-Message: yes
 
 You receive this email because you are AdminCc on {$Ticket->QueueObj->Name} queue.
 
 Ticket taken by {$Ticket->OwnerObj->Name}.
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 =====================================================================
 
 
 
 

6) MY Queue Change Notify AdminCcs

RT-Attach-Message: yes
 
 You receive this email because you are AdminCc of {$Ticket->QueueObj->Name} queue.
 
 {$Transaction->Description}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 =====================================================================
 
 
 
 

7) Default

8) MY Correspond Notify Requestor and Ccs

RT-Attach-Message: yes
 
 You receive this email because you are Requestor or Cc on this ticket.
 
 {$Transaction->Description}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

9) MY Correspond Notify Other recipients

RT-Attach-Message: yes
 
 You receive this email because you are in the list of recipients of this ticket.
 
 {$Transaction->Description}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

10) MY Correspond Notify Owner

RT-Attach-Message: yes
 
 You receive this email because you are owner of this ticket.
 
 {$Transaction->Description}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

11) MY Correspond Notify AdminCc

RT-Attach-Message: yes
 
 You receive this email because you are AdminCc on {$Ticket->QueueObj->Name} queue.
 
 {$Transaction->Description}
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

12) MY Comment AdminCc

RT-Attach-Message: yes
 
 You receive this email because you are AdminCc on {$Ticket->QueueObj->Name} queue.
 
 {$Transaction->Description}. This message is not sent to the requestors.
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

13) MY Comment Owner

RT-Attach-Message: yes
 
 You receive this email because you are Owner of this ticket.
 
 {$Transaction->Description}. This message is not sent to the requestors.
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 
 {$Transaction->Content()}
 =====================================================================
 
 
 
 

14) MY Ticket Resolved

Subject: Resolved: {$Ticket->Subject}

Request {$Ticket->id} was acted upon.

Subject: {$Transaction->Subject || $Ticket->Subject || "(No subject given)"}


According to our tests, your request has been resolved. If you have any
further questions or concerns, please open a new ticket or reopen this one by replying to this email.

{$Transaction->CreatedAsString}: {$Transaction->Description}
Queue: {$Ticket->QueueObj->Name}
Owner: {$Ticket->OwnerObj->Name}
Requestors: {$Ticket->RequestorAddresses}

Ticket <URL: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id} >




15) MY Comment AdminCc Resolved

RT-Attach-Message: yes
 
 You receive this email because you are AdminCc on {$Ticket->QueueObj->Name} queue.
 
 Ticket resolved by {$Ticket->OwnerObj->Name}.
 
 =====================================================================
     Ticket: {$RT::WebURL}Ticket/Display.html?id={$Ticket->id}
      Queue: {$Ticket->QueueObj->Name}
 Requestors: {$Ticket->RequestorAddresses}
      Owner: {$Ticket->OwnerObj->Name}
     Status: {$Ticket->Status}
    Subject: "{$Transaction->Subject || $Ticket->Subject || "(No subject given)"}"
 =====================================================================
 

Discussions/remarks/etc...

Christophe {dot} Sahut {at} sgs {dot} com