%perl>
# of new reports outstanding at month start
my $outstanding = RT::Tickets->new($session{'CurrentUser'});
$outstanding->LimitQueue(VALUE => 'Incident Reports');
$outstanding->LimitCreated(VALUE => $start, OPERATOR => "<");
my $date = ParseDateToISO("0");
$outstanding->LimitResolved(VALUE => $date, OPERATOR => "=");
# of new reports created during the month
my $tix_created = RT::Tickets->new($session{'CurrentUser'});
$tix_created->LimitQueue(VALUE => 'Incident Reports');
$tix_created->LimitCreated(VALUE => $start, OPERATOR => ">");
$tix_created->LimitCreated(VALUE => $end, OPERATOR => "<");
# of new reports resolved/closed/deleted during the month
# does this mean "number of reports closed during the month or number of
# reports created during the month that were also closed during the month?"
my $tix_resolved = RT::Tickets->new($session{'CurrentUser'});
$tix_resolved->LimitQueue(VALUE => 'Incident Reports');
$tix_resolved->LimitCreated(VALUE => $start, OPERATOR => ">");
$tix_resolved->LimitCreated(VALUE => $end, OPERATOR => "<");
$tix_resolved->LimitResolved(VALUE => $start, OPERATOR => ">");
$tix_resolved->LimitResolved(VALUE => $end, OPERATOR => "<");
# of new reports oustanding at month end
# same question: does this mean "number of reports closed during the month or
# number of reports created during the month that were also closed during the
# month?"
my $tix_unresolved = RT::Tickets->new($session{'CurrentUser'});
#$tix_unresolved->LimitQueue(VALUE => 'Incident Reports');
#$tix_unresolved->LimitCreated(VALUE => $start, OPERATOR => ">");
#$tix_unresolved->LimitCreated(VALUE => $end, OPERATOR => "<");
#$tix_unresolved->LimitResolved(VALUE => $end, OPERATOR => ">");
#$tix_unresolved->LimitResolved(VALUE => $date, OPERATOR => "=", ENTRYAGGREGATOR => "OR");
#$tix_unresolved->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND (Resolved<'1970-01-01 00:00:00' OR Resolved>'2003-06-18 21:58')");
$tix_unresolved->FromSQL("Queue = 'Incident Reports' AND Created > '$start' AND Created < '$end' AND (Resolved='1970-01-01 00:00:00' OR Resolved>'$end')");
# of new reports created during the month broken down by classification
my ($fid, $types, $classifications, $windows, $CustomFields);
my $Queue = new RT::Queue($session{'CurrentUser'});
$Queue->Load('Incidents');
$CustomFields = $Queue->CustomFields();
$CustomFields->{'find_disabled_rows'} = 1;
while (my $CustomField = $CustomFields->Next()) {
if ($CustomField->Name eq '_RTIR_Function') {
$fid = $CustomField->Id;
my $values = $CustomField->Values;
while (my $value = $values->Next) {
$types->{$value->Name} = $value->Description;
}
}
}
# of new reports created during the month broken down by classification
$Queue = new RT::Queue($session{'CurrentUser'});
$Queue->Load('Incidents');
$CustomFields = $Queue->CustomFields();
$CustomFields->{'find_disabled_rows'} = 1;
while (my $CustomField = $CustomFields->Next()) {
if ($CustomField->Name eq '_RTIR_Classification') {
$fid = $CustomField->Id;
my $values = $CustomField->Values;
while (my $value = $values->Next) {
$classifications->{$value->Name} = "";
}
}
}
%perl>
Monthly Report
Start date: |
<%$start%> |
End date: |
<%$end%> |
Incident Report Summary |
Outstanding reports at the beginning of this period |
<%$outstanding->Count%> |
Total new reports for the month |
<% $tix_created->Count%> |
Incident Reports resolved in the month |
<% $tix_resolved->Count%> |
Reports unresolved at the end of the month |
<% $tix_unresolved->Count%> |
Incident reports received |
<%perl>
foreach my $class (keys %$classifications) {
my $class_tix = RT::Tickets->new( $session{'CurrentUser'} );
$class_tix->LimitQueue(VALUE => 'Incident Reports');
$class_tix->LimitCreated(VALUE => $start, OPERATOR => ">");
$class_tix->LimitCreated(VALUE => $end, OPERATOR => "<");
my $class_count = 0;
while ( my $t = $class_tix->Next) {
# find the parent incident
my $incidents = $t->MemberOf;
my $parent;
while (my $link = $incidents->Next) {
my $incident = $link->TargetObj;
if ($incident->QueueObj->Name eq 'Incidents') {
$parent = $incident;
last;
}
}
if ( $parent &&
$parent->FirstCustomFieldValue('_RTIR_Classification') eq $class) {
$class_count++;
}
}
%perl>
<%$class%> |
<%$class_count%> |
<%perl>
}
%perl>
<%perl>
foreach my $incident_type (keys %$types) {
%perl>
<%$incident_type%>
<%perl>
# of new reports created during the month broken down by classification
$Queue->Load('Incident Reports');
$CustomFields = $Queue->CustomFields();
$CustomFields->{'find_disabled_rows'} = 1;
while (my $CustomField = $CustomFields->Next()) {
if ($CustomField->Name eq '_RTIR_SLA') {
$fid = $CustomField->Id;
my $values = $CustomField->Values;
while (my $value = $values->Next) {
$windows->{$value->Name} = $value->Description;
}
}
}
foreach my $service_level (keys %$windows) {
my $class_tix = RT::Tickets->new( $session{'CurrentUser'} );
$class_tix->LimitQueue(VALUE => 'Incident Reports');
$class_tix->LimitCreated(VALUE => $start, OPERATOR => ">");
$class_tix->LimitCreated(VALUE => $end, OPERATOR => "<");
$class_tix->LimitCustomField(CUSTOMFIELD => $fid, VALUE => $service_level);
my $class_sla_tix = RT::Tickets->new( $session{'CurrentUser'} );
$class_sla_tix->DEBUG(1);
$class_sla_tix->Limit( QUOTEVALUE => 1, ENTRYAGGREGATOR => 'AND', FIELD => 'Started', OPERATOR => '<', VALUE => '(Created + 7200)' );
my ($tix_count, $sla_count, $resolved_count, $unresolved_count);
$tix_count = 0;
$sla_count = 0;
$resolved_count = 0;
$unresolved_count = 0;
# get the number of seconds for the service level
my $sla = $RT::SLA->{$service_level} * 60;
while ( my $t = $class_tix->Next) {
# find the parent incident
my $incidents = $t->MemberOf;
my $parent;
while (my $link = $incidents->Next) {
my $incident = $link->TargetObj;
if ($incident->QueueObj->Name eq 'Incidents') {
$parent = $incident;
last;
}
}
if ( $parent &&
$parent->FirstCustomFieldValue('_RTIR_Function') eq $incident_type) {
if ( $t->ResolvedObj->Unix <= 0 ||
$t->ResolvedObj->Unix > $monthend->Unix) {
$tix_count++;
}
if ( $t->StartedObj->Unix > 0 &&
$t->StartedObj->Unix < ($t->CreatedObj->Unix + $sla)) {
$sla_count++;
}
if ( $t->ResolvedObj->Unix >= $monthstart->Unix &&
$t->ResolvedObj->Unix <= $monthend->Unix) {
$resolved_count++;
}
if ( $t->ResolvedObj->Unix <= 0 ||
$t->ResolvedObj->Unix > $monthend->Unix) {
$unresolved_count++;
}
}
}
%perl>
<%$service_level%>
At the start of the time period: |
Outstanding Incident Reports: |
<%$outstanding->Count%> |
|
During the time period: |
Total <%$service_level%> Incident Reports created: |
<% $tix_count %> |
Incident Reports for which response time was met:
|
<% $sla_count %> |
Resolved Incident Reports: |
<% $resolved_count%> |
Unresolved Incident Reports: |
<% $unresolved_count%> |
|
% }
% }
<%perl>
# All tickets created in queue IncidentReport created after
# monthstart and before monthend where
# there was outbound correspondence within $windows{$Classification};
#
# No need to break down incident type against response time.
# classification (eg response time) needs to be calculated somehow, and to
# take account of nwh. (eg the clock stops tickets at 1800 and starts
# again at 0800 and reports received at 8am on a Saturday are not measured
# until 0800 Monday ownwards...etc)
#
# eg
# All tickets created in queue IncidentReport created after monthstart and
# before monthend where there was outbound correspondence within
# $windows{$Classification};
#
my $sla_check = RT::Tickets->new( $session{'CurrentUser'} );
#$sla_check->FromSQL( "Created >= $monthstart AND Created <= $monthend AND Queue='Incident Reports'");
# Get a Business::Hours object for the period in question
use Business::Hours;
my $business_hours = Business::Hours->new();
#$business_hours->set_business_hours(%working_hours);
#$business_hours->for_timespan( Start => $monthstart->AsString, End => $monthend->AsString );
my %created;
while ( my $t = $sla_check->Next) {
my $sla = $t->FirstCustomFieldValue('SLA');
#my $time_on_clock = $business_hours->between( $t->CreatedObj->Unix, $t->ResolvedObj->Unix );
# of email messages created by CERT staff, broken down by Queue (incident, incident report, investigation)
# of email messages received by CERT, broken down by Queue (incident, incident report, investigation)
my $txns = RT::Transactions->new( $session{'CurrentUser'} );
$txns->Limit( FIELD => 'Created', OPERATOR => '>=', VALUE => $monthstart );
$txns->Limit( FIELD => 'Created', OPERATOR => '<=', VALUE => $monthstart );
while ( my $txn = $txns->Next ) {
my $q = $txn->TicketObj->QueueObj->Name;
my $inbound = ( $txn->IsInbound || 0 );
$created{$q}{$inbound}++;
}
# Average time from creation to close for incidents for all incidents
# closed within this time period
# This doesn't currently take into account "business hours"
my $avgtime = RT::Tickets->new( $session{'CurrentUser'} );
# $avgtime->FromSQL( "Queue = 'Incident Reports' AND Resolved >= '$monthstart' AND Resolved <= '$monthend'");
my $i;
my $total_diff;
while ( my $t = $avgtime->Next ) {
$i++;
my $ctime = $t->CreatedObj->Unix;
my $rtime = $t->ResolvedObj->Unix;
my $diff = $rtime - $ctime;
$total_diff += $diff;
}
my $average_secs;
if ($i) {
$average_secs = $total_diff / $i;
}
}
%perl>
<%init>
my $now = new RT::Date($RT::SystemUser);
$now->SetToNow();
my $monthstart = new RT::Date($RT::SystemUser);
$monthstart->Set(Format => 'ISO', Value => ParseDateToISO($mystart));
my $monthend = new RT::Date($RT::SystemUser);
$monthend->Set(Format => 'ISO', Value => ParseDateToISO($myend));
my $start = $monthstart->ISO;
my $end = $monthend->ISO;
%init>
<%args>
$mystart => undef
$myend => undef
%args>