[rt-devel] Nag script

Harshad R Joglekar harshad.joglekar at wipro.com
Mon Nov 12 09:16:14 EST 2001


Skipped content of type multipart/alternative-------------- next part --------------
#!/usr/bin/perl -w
#
# $Header: /raid/cvsroot/rt-addons/nag,v 1.1 2001/10/11 01:59:54 jesse Exp $
# RT is (c) 1996-2001 Jesse Vincent <jesse at fsck.com>

use strict;
use Carp;

use lib "/opt/rt2/lib";
use lib "/opt/rt2/etc";

use RT::Interface::CLI  qw(CleanEnv LoadConfig DBConnect 
			   GetCurrentUser GetMessageContent);

#Clean out all the nasties from the environment
CleanEnv();

#Load etc/config.pm and drop privs
LoadConfig();

#Connect to the database and get RT::SystemUser and RT::Nobody loaded
DBConnect();

use RT::Date;
use RT::Queue;
use RT::Tickets;
use RT::Users;
use Mail::Mailer;
use Mail::Send;

my $now = new RT::Date($RT::SystemUser);
$now->SetToNow();

my $users = new RT::Users($RT::SystemUser);
RT::Users::LimitToPrivileged($users);

while (my $owner = $users->Next) {

	my $tickets = new RT::Tickets($RT::SystemUser);
	$tickets->LimitStatus(VALUE => 'open');
	$tickets->LimitStatus(VALUE => 'new');
	$tickets->LimitOwner(VALUE => $owner->Id);

	if ($tickets->Count > 0) {
		my $message = $owner->Name . ",\n";

		$message = $message . "You have " . $tickets->Count;
		$message = $message . " open tickets:" . "\n\n";

		while (my $ticket = $tickets->Next) {
			$message .= $ticket->Id . ": " . $ticket->Subject;
			$message .= "\n\t(Age:" .  $ticket->AgeAsString . ")\n\n";
		}

		$message .= "\n-- \nRT/" . $RT::rtname . "\n";

		# Send the mail
		my $msg = new Mail::Send Subject=>"Your open tickets", To=>$owner->Name;
		$msg->to($owner->EmailAddress);
		my $fh = $msg->open;
		print $fh $message;
		$fh->close;
	}
}

$RT::Handle->Disconnect();

-------------- next part --------------
-------------------------------------------------------------------------------------------------------------------------
Information transmitted by this E-MAIL is proprietary to Wipro and/or its Customers and
is intended for use only by the individual or entity to which it is
addressed, and may contain information that is privileged, confidential or
exempt from disclosure under applicable law. If you are not the intended
recipient or it appears that this mail has been forwarded to you without
proper authority, you are notified that any use or dissemination of this
information in any manner is strictly prohibited. In such cases, please
notify us immediately at mailto:mailadmin at wipro.com and delete this mail
from your records.
----------------------------------------------------------------------------------------------------------------------


More information about the Rt-devel mailing list