Hi Mathew,
Start by printing out the applicable elements ([0] - [5] and [8]) from
localtime(str2time($ticket->Created)) and comparing them to what you see in
RT, then print the same elements from localtime(time) and see what you
get. If it's a timezone or DST issue you can compensate for it. Once you
get time values you can trust you work on the next issue.
Gene
At 10:25 AM 11/28/2007, Mathew Snyder wrote:
This is the script I came up with:
#!/usr/bin/perl
use warnings;
use strict;
use lib '/usr/local/rt3/lib';
use lib '/usr/local/rt3/local/lib';
use RT;
use RT::Tickets;
use RT::Users;
use MIME::Lite;
use Date::Parse;
RT::LoadConfig();
RT::Init();
my $tix = new RT::Tickets(RT::SystemUser);
$tix->FromSQL('Queue = "CustomerCare" AND Status = "new" AND Owner =
"Nobody"');
while (my $ticket = $tix->Next) {
my $diff = time - str2time($ticket->Created);
print $ticket->id . ": " . str2time($ticket->Created) . "\n";
print time . "\n";
print "diff: " . $diff . "\n";
if (($diff/60) >= 5) {
print "diff adjusted: " . ($diff/60) . "\n";
&email();
exit;
}
}
sub email {
my $emailTo = '[EMAIL PROTECTED]';
my $emailFrom = 'RT-devel';
my $emailSubj = 'Tickets In CustomerCare Need Your Attention
**TEST-DISREGARD**';
#my $emailMsg = 'There are tickets in CustomerCare that are 5 or
more minutes old. These tickets require action even if it is placing them in
the appropriate queue. Please attend to these tickets.\n\nThank You';
my $emailMsg = 'This is a test message for a script I am
working on.';
my $fullEmail = new MIME::Lite(From => $emailFrom,
To => $emailTo,
Subject => $emailSubj,
Type => "multipart/mixed"
);
$fullEmail->attach(Type => "TEXT",
Data => $emailMsg
);
$fullEmail->send("sendmail", "/usr/sbin/sendmail -t");
}
This refuses to work though. If I leave it as is I get a negative number for
$diff/60 because $ticket->Created indicates a number greater than
time(). I can
only guess it has something to do with timezones but I don't know. If I
reverse
the operands and subtract time from the ticket creation I get a number in the
200s but which is always shrinking and will end up in the negatives because I
shouldn't be subtracting time from teh created time anyway.
This is sampler output when subtracting ticket created time from time():
Ticket Created Time: 1196291034
time(): 1196273826
diff: -17208
and when subtracting time() from the ticket creation time:
Ticket Created Time: 1196291034
time(): 1196273872
diff: 17162
On top of all this, even when the number comes out positive, dividing by 60
(which I'm assuming I have to do as time and str2time output time since the
epoch as seconds) spits out a number that doesn't even correlate.
Can someone take a look at this and help me out. Thanks.
Keep up with me and what I'm up to: http://theillien.blogspot.com
Gene LeDuc wrote:
> I do it using days, not minutes, but the concept is the same. Try using
> a cron job that runs every 2 minutes. The perl API makes it easy to
> read ticket values, so it would be pretty straightforward to compare
> Updated to now() and send an e-mail if the difference is > 5min. It's
> possible this way to have a ticket languish for up to 6 minutes, but you
> could run the cron every minute if it's that critical.
>
> Regards,
> Gene
>
> At 01:33 PM 11/27/2007, Mathew Snyder wrote:
>> I'm considering implementing a method of telling those that need to
>> know when a
>> ticket has been in our triage queue untouched for a predetermined
>> amount of time
>> (say, five minutes). I'd like to poll this queue and, if a ticket
>> which meets
>> these requirements exists, send an email out telling people to act on it.
>>
>> Has anyone done this before and if so, which method did you use?
>
>
--
Gene LeDuc, GSEC
Security Analyst
San Diego State University
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:
If you sign up for a new RT support contract before December 31, we'll take
up to 20 percent off the price. This sale won't last long, so get in touch today.
Email us at [EMAIL PROTECTED] or call us at +1 617 812 0745.
Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]
Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com