This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::GenericAgent::AutoPriorityIncrease;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::DateTime',
'Kernel::System::Log',
'Kernel::System::Priority',
'Kernel::System::Ticket',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# 0=off; 1=on;
$Self->{Debug} = $Param{Debug} || 0;
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
my $Update = 0;
my $LatestAutoIncrease = 0;
# check needed param
if ( !$Param{New}->{'TimeInterval'} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need TimeInterval param for GenericAgent module!',
);
return;
}
$Param{New}->{TimeInterval} = $Param{New}->{TimeInterval} * 60;
# get ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# get ticket data
my %Ticket = $TicketObject->TicketGet(
%Param,
DynamicFields => 0,
);
my @HistoryLines = $TicketObject->HistoryGet( %Param, UserID => 1 );
# find latest auto priority update
for my $History (@HistoryLines) {
if ( $History->{Name} =~ /^AutoPriorityIncrease/ ) {
$LatestAutoIncrease = $History->{CreateTime};
}
}
if ( !$LatestAutoIncrease ) {
$LatestAutoIncrease = $Ticket{Created};
}
# get time object
my $DateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
my $SystemTime = $DateTimeObject->ToEpoch();
$LatestAutoIncrease = $DateTimeObject->Set(
String => $LatestAutoIncrease,
);
$LatestAutoIncrease = $LatestAutoIncrease ? $DateTimeObject->ToEpoch() : undef;
if (
( $SystemTime - $LatestAutoIncrease )
> $Param{New}->{TimeInterval}
)
{
$Update = 1;
}
# check if priority needs to be increased
if ( !$Update ) {
# do nothing
if ( $Self->{Debug} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"Nothing to do on (Ticket=$Ticket{TicketNumber}/TicketID=$Ticket{TicketID})!",
);
}
return 1;
}
# increase priority
my $Priority = $Kernel::OM->Get('Kernel::System::Priority')->PriorityLookup(
PriorityID => ( $Ticket{PriorityID} + 1 ),
);
# do nothing if already highest priority
if ( !$Priority ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'notice',
Message =>
"Ticket=$Ticket{TicketNumber}/TicketID=$Ticket{TicketID} already set to higest priority! Can't increase priority!",
);
return 1;
}
# increase priority
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'notice',
Message =>
"Increase priority of (Ticket=$Ticket{TicketNumber}/TicketID=$Ticket{TicketID}) to $Priority!",
);
$TicketObject->TicketPrioritySet(
TicketID => $Param{TicketID},
PriorityID => ( $Ticket{PriorityID} + 1 ),
UserID => 1,
);
$TicketObject->HistoryAdd(
Name => "AutoPriorityIncrease (Priority=$Priority/PriorityID="
. ( $Ticket{PriorityID} + 1 ) . ")",
HistoryType => 'Misc',
TicketID => $Param{TicketID},
UserID => 1,
CreateUserID => 1,
);
return 1;
}
1;

View File

@@ -0,0 +1,126 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::GenericAgent::NotifyAgentGroupOfCustomQueue;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::DateTime',
'Kernel::System::Log',
'Kernel::System::Queue',
'Kernel::System::SLA',
'Kernel::System::Ticket',
'Kernel::System::User',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# 0=off; 1=on;
$Self->{Debug} = $Param{Debug} || 0;
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# get ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# get ticket data
my %Ticket = $TicketObject->TicketGet(
%Param,
DynamicFields => 0,
);
# get used calendar
my $Calendar = $TicketObject->TicketCalendarGet(
%Ticket,
);
# get time object
my $StopDateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
# check if it is during business hours, then send escalation info
my $StartDateTimeObject = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
Epoch => $StopDateTimeObject->ToEpoch() - ( 10 * 60 ),
}
);
my $CountedTime = StartDateTimeObject->Delta(
DateTimeObject => $StopDateTimeObject,
ForWorkingTime => 1,
Calendar => $Calendar,
);
if ( !$CountedTime ) {
if ( $Self->{Debug} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"Send no escalation for Ticket $Ticket{TicketNumber}/$Ticket{TicketID} because currently no working hours!",
);
}
return 1;
}
# check if it's a escalation of escalation notification
# check escalation times
my $EscalationType = '';
TYPE:
for my $Type (
qw(FirstResponseTimeEscalation UpdateTimeEscalation SolutionTimeEscalation
FirstResponseTimeNotification UpdateTimeNotification SolutionTimeNotification)
)
{
if ( defined $Ticket{$Type} ) {
if ( $Type =~ /TimeEscalation$/ ) {
$EscalationType = 'Escalation';
last TYPE;
}
elsif ( $Type =~ /TimeNotification$/ ) {
$EscalationType = 'EscalationNotifyBefore';
last TYPE;
}
}
}
# check
if ( !$EscalationType ) {
if ( $Self->{Debug} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"Can't send escalation for Ticket $Ticket{TicketNumber}/$Ticket{TicketID} because ticket is not escalated!",
);
}
return;
}
# trigger notification event
$TicketObject->EventHandler(
Event => 'Notification' . $EscalationType,
Data => {
TicketID => $Param{TicketID},
CustomerMessageParams => \%Param,
},
UserID => 1,
);
return 1;
}
1;

View File

@@ -0,0 +1,127 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::GenericAgent::NotifyAgentGroupWithWritePermission;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::DateTime',
'Kernel::System::Group',
'Kernel::System::Log',
'Kernel::System::Queue',
'Kernel::System::SLA',
'Kernel::System::Ticket',
'Kernel::System::User',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# 0=off; 1=on;
$Self->{Debug} = $Param{Debug} || 0;
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# get ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# get ticket data
my %Ticket = $TicketObject->TicketGet(
%Param,
DynamicFields => 0,
);
# get used calendar
my $Calendar = $TicketObject->TicketCalendarGet(
%Ticket,
);
# get time object
my $StopDateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
# check if it is during business hours, then send escalation info
my $StartDateTimeObject = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
Epoch => $StopDateTimeObject->ToEpoch() - ( 10 * 60 ),
}
);
my $CountedTime = StartDateTimeObject->Delta(
DateTimeObject => $StopDateTimeObject,
ForWorkingTime => 1,
Calendar => $Calendar,
);
if ( !$CountedTime ) {
if ( $Self->{Debug} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"Send no escalation for Ticket $Ticket{TicketNumber}/$Ticket{TicketID} because currently no working hours!",
);
}
return 1;
}
# check if it's a escalation or escalation notification
# check escalation times
my $EscalationType = '';
TYPE:
for my $Type (
qw(FirstResponseTimeEscalation UpdateTimeEscalation SolutionTimeEscalation
FirstResponseTimeNotification UpdateTimeNotification SolutionTimeNotification)
)
{
if ( defined $Ticket{$Type} ) {
if ( $Type =~ /TimeEscalation$/ ) {
$EscalationType = 'Escalation';
last TYPE;
}
elsif ( $Type =~ /TimeNotification$/ ) {
$EscalationType = 'EscalationNotifyBefore';
last TYPE;
}
}
}
# check
if ( !$EscalationType ) {
if ( $Self->{Debug} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"Can't send escalation for Ticket $Ticket{TicketNumber}/$Ticket{TicketID} because ticket is not escalated!",
);
}
return;
}
# trigger notification event
$TicketObject->EventHandler(
Event => 'Notification' . $EscalationType,
Data => {
TicketID => $Param{TicketID},
CustomerMessageParams => \%Param,
},
UserID => 1,
);
return 1;
}
1;

View File

@@ -0,0 +1,163 @@
# --
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
# --
package Kernel::System::GenericAgent::TriggerEscalationStartEvents;
use strict;
use warnings;
use List::Util qw(first);
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::DateTime',
'Kernel::System::Log',
'Kernel::System::Queue',
'Kernel::System::SLA',
'Kernel::System::Ticket',
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless $Self, $Type;
# 0=off; 1=on;
$Self->{Debug} = $Param{Debug} || 0;
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# get ticket object
my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
# get ticket data
# the escalation properties are computed within TicketGet().
my %Ticket = $TicketObject->TicketGet(
%Param,
DynamicFields => 0,
);
# get used calendar
my $Calendar = $TicketObject->TicketCalendarGet(
%Ticket,
);
# get time object
my $StopDateTimeObject = $Kernel::OM->Create('Kernel::System::DateTime');
# check if it is during business hours, then send escalation info
my $StartDateTimeObject = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
Epoch => $StopDateTimeObject->ToEpoch() - ( 10 * 60 ),
}
);
my $CountedTime = $StartDateTimeObject->Delta(
DateTimeObject => $StopDateTimeObject,
ForWorkingTime => 1,
Calendar => $Calendar,
);
if ( !$CountedTime || !$CountedTime->{AbsoluteSeconds} ) {
if ( $Self->{Debug} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"Send not escalation for Ticket $Ticket{TicketNumber}/$Ticket{TicketID} because currently no working hours!",
);
}
return 1;
}
# needed for deciding whether events should be triggered
my @HistoryLines = $TicketObject->HistoryGet(
TicketID => $Ticket{TicketID},
UserID => 1,
);
# check if it's a escalation or escalation notification
# check escalation times
my %TicketAttr2Event = (
FirstResponseTimeEscalation => 'EscalationResponseTimeStart',
UpdateTimeEscalation => 'EscalationUpdateTimeStart',
SolutionTimeEscalation => 'EscalationSolutionTimeStart',
FirstResponseTimeNotification => 'EscalationResponseTimeNotifyBefore',
UpdateTimeNotification => 'EscalationUpdateTimeNotifyBefore',
SolutionTimeNotification => 'EscalationSolutionTimeNotifyBefore',
);
my @Events;
# triggering summary events is currently (2010-12-03) disabled
#my ( $FoundEscalation, $FoundNotifyBefore ) = ( 0, 0 );
ATTR:
for my $Attr ( grep { defined $Ticket{$_} } sort keys %TicketAttr2Event ) {
# the decay time is configured in minutes
my $DecayTimeInSeconds = $Kernel::OM->Get('Kernel::Config')->Get('OTRSEscalationEvents::DecayTime') || 0;
$DecayTimeInSeconds *= 60;
# get the last time this event was triggered
# search in reverse order, as @HistoryLines sorted ascendingly by CreateTime
if ($DecayTimeInSeconds) {
my $PrevEventLine = first { $_->{HistoryType} eq $TicketAttr2Event{$Attr} }
reverse @HistoryLines;
if ( $PrevEventLine && $PrevEventLine->{CreateTime} ) {
my $PrevEventTime = $Kernel::OM->Create(
'Kernel::System::DateTime',
ObjectParams => {
String => $PrevEventLine->{CreateTime},
},
);
$PrevEventTime = $PrevEventTime ? $PrevEventTime->ToEpoch() : 0;
my $TimeSincePrevEvent = $StopDateTimeObject->ToEpoch() - $PrevEventTime;
next ATTR if $TimeSincePrevEvent <= $DecayTimeInSeconds;
}
}
# emit the event
push @Events, $TicketAttr2Event{$Attr};
}
for my $Event (@Events) {
# trigger the event
$TicketObject->EventHandler(
Event => $Event,
UserID => 1,
Data => {
TicketID => $Param{TicketID},
},
UserID => 1,
);
# log the triggered event in the history
$TicketObject->HistoryAdd(
TicketID => $Param{TicketID},
HistoryType => $Event,
Name => "%%$Event%%triggered",
CreateUserID => 1,
);
}
return 1;
}
1;