#!/usr/bin/perl =head1 NAME reminder.pl - find and =head1 DESCRIPTION This script makes a list of all tickets which are steel new or open and examines a date of creation last attachement (only for type 'Creation', 'Comment' or 'Correspond'). If this date is less than specified, script put remind message into ticket. We should define following constants and variables: - DURATION - define a number of days for filtering of number of not commented tickets a long time. - FROM - autoreminder email address. - SUBJECT - define a subscject of remind message. - message - define a body of remind message. - DEBUG - show debug messages. Use '--debug' option when script is executed, for choose debug mode. =cut #!!!PERL!! -w use strict; use Carp; use lib "/opt/rt2/lib"; use lib "/opt/rt2/etc"; use RT::Date; use RT::Tickets; use RT::Attachments; use RT::Transactions; use MIME::Entity; use RT::Interface::CLI qw( CleanEnv LoadConfig DBConnect GetCurrentUser GetMessageContent ); use constant DURATION => 30; use constant FROM => 'reminder@localhost'; use constant SUBJECT => 'Lost ticket!'; my $message = <LimitStatus(VALUE => 'open'); $tickets->LimitStatus(VALUE => 'new'); # Loop by tickets list while (my $ticket = $tickets->Next) { my $user = $ticket->OwnerObj; print "DEBUG>>> owner/ticket Id: ".$user->Name.' - '.$ticket->Id."\n" if $DEBUG; my $trans = $ticket->Transactions; # List of all ticket transactions # Limit list of transaction of including only # transaction of type 'Create', 'Correspond' or 'Comment'. $trans->Limit( FIELD => 'Type', VALUE => 'Create' ); $trans->Limit( FIELD => 'Type', VALUE => 'Correspond', ); $trans->Limit( FIELD => 'Type', VALUE => 'Comment' ); while(my $trnx = $trans->Next) { my $attachs = $trnx->Attachments; # List of all ticket attachments # Limit list of ticket's attachments by date of creation and $attachs->Limit(FIELD => 'Headers', VALUE => FROM, OPERATOR=> 'NOT LIKE'); while(my $attach = $attachs->Next) { if( (sprintf("%d", ($attach->CreatedObj->Diff(time))/ (3600*24*(-1))) > DURATION)) { if($DEBUG) { print "DEBUG>>> Transactions: "; print $trnx->Id.' ('.$trnx->Type.') ('; print $attach->Id.' - \''.$attach->Created.'\' - '. sprintf("%d", ($attach->CreatedObj->Diff(time))/(3600*24*(-1))). '; '.$attach->CreatedObj->AgeAsString.'; '; print ') '; } my $body = $message; $body =~ s/%%ID%%/$ticket->Id/e; $body =~ s/%%AGE%%/$attach->CreatedObj->AgeAsString/e; $body =~ s/%%DATE%%/$attach->Created/e; my $mime_obj = MIME::Entity->build( Subject => SUBJECT, From => FROM, Data => [$body] ); } } } print "\n" if $DEBUG; } $RT::Handle->Disconnect();