<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi all<br>
<br>
I found it surprisingly hard to convert ticket dates like
Ticket->Due into relative friendly dates and times in templates
as part of my work on proper SLA monitoring and alerting in RT.
Having found the answer, I though I'd post it here for anyone else
searching for information on the problem.<br>
<br>
What I did is add a block to the very start of my alert email
template that defines a package variable, say $tdiff, with the time
difference. The time difference is obtained by constructing an
RT::Date with the system user, setting the date, and using
RT::Date::AgeAsString() . (For some reason RT::Date::DiffAsString
always produced an undef result). The variable can then be
referenced anywhere else in the template with {our $tdiff;} .
Tickets are defined as storing the Due date in ISO format in GMT, so
those parameters should be specified to RT::Date.<br>
<br>
Example:<br>
<br>
--- BEGIN TEMPLATE ---<br>
{<br>
my $d = RT::Date->new(RT::SystemUser);<br>
$d->Set(Format=>'ISO', Value=>$Ticket->Due,
Timezone=>"GMT");<br>
our $tdiff = $d->AgeAsString();<br>
'';<br>
}Subject: SLA Warning: Due in {our $tdiff}<br>
<br>
Action is required on this ticket within {our $tdiff} in order to
remain within SLA service levels.<br>
--- END TEMPLATE ---<br>
<br>
Since RT::Date::AgeAsString() appends "ago" automatically for
negative dates, it's also reasonable to write something like:<br>
<br>
Subject: SLA Failure: Due ${our $tdiff}, critical action required<br>
<br>
I've added this here:<br>
<br>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a
href="http://requesttracker.wikia.com/wiki/TemplateSnippets#Dates">http://requesttracker.wikia.com/wiki/TemplateSnippets#Dates</a><br>
<br>
... but it strikes me that this should really be a helper function
in RT::Date so you don't have to create and set and instance just to
call one method and discard it. OTOH, perhaps my Perl-ignorance is
biting me, and there is a simple and easy way to do it.<br>
<br>
<br>
Note that the template doesn't do anything by its self. To actually
get SLA alerting working, I landed up:<br>
<br>
* Installing RT::Extension::SLA, including the DB setup step to add
the CF<br>
* Configuring RT::Extension:SLA as per the docs to describe my SLAs
and the working hours of the various teams.<br>
* Reloading RT to get the SLA module activated<br>
* Following the rt-crontool docs to create a local user for
scheduled actions<br>
* Defining the following job as /etc/cron.d/requesttracker4-sla:<br>
<br>
*/5 * * * * requesttracker4 rt-crontool --search
RT::Search::FromSQL --search-arg "(Status='new' OR Status='open')
AND FinalPriority > 0 AND Due > 'Jan 1, 1970'" --action
RT::Action::EscalatePriority<br>
<br>
to, every five minutes, run RT::Action::EscalatePriority on open
tickets with due dates and final priorities set. The connection to
RT::Extension::SLA here is that RT::Extension::SLA auto-sets the due
date based on the SLA when the ticket is created or changed. This
crontool job isn't actually running any SLA code directly, but it's
using information provided by SLA.<br>
<br>
I also want email SLA warnings to go out. This is what the template
described at the start of this mail is for. I create that template
as (say) "SLA Due" in the global templates. Then I add another cron
job that runs something like this:<br>
<br>
*/5 * * * * requesttracker4 rt-crontool --verbose
--transaction last --search RT::Search::FromSQL --search-arg "Due
< '30 minutes'" --action RT::Action::RecordComment --template
'SLA Due'<br>
<br>
Again, you don't see any SLA specific code run here because it's
using the Due time set by the SLA module whenever the ticket
changes. This command will add a private (assuming your permissions
are set appropriately) comment on the ticket, the creation of which
will trigger the generation of email notifications as if the comment
had been added manually in the web ui. A comment will not be treated
as satisfying a Response SLA so the creation of the comment won't
resolve the SLA issue by its self.<br>
<br>
You need to be careful to make sure that the client accounts and the
requestor pseudo group don't have rights to read comments, or you'll
be sending these SLA warnings to the client too.<br>
<br>
The same approach can be used with a custom Action command to send
SMSes. I'm adapting my RedOxygen SMS gateway script to be callable
from an RT action right now, and will follow up with it when it's
ready so nobody else has to waste their time implementing the same
thing.<br>
<br>
There's more you're likely to want, including a dashboard entry
showing tickets in SLA priority order with severity highlighting, a
summary report of time left before resolution of all tickets across
a time period, etc. I haven't done those yet so I can't help there,
but will try to follow up when I have.<br>
<br>
Next problem: How to bind multiple accounts (addresses) together
into "customers" who can all see each others' tickets. It's amazing
that this doesn't seem to be built-in to RT. Ideas? I'll follow up
with solutions, either mine or others'.<br>
<br>
<pre class="moz-signature" cols="72">--
Craig Ringer <a class="moz-txt-link-freetext" href="http://www.2ndQuadrant.com/">http://www.2ndQuadrant.com/</a>
PostgreSQL Development, 24x7 Support, Training & Services</pre>
</body>
</html>