Hi,
I would like to know if there is a way to listen to events. Let's say I want to be notified whenever a ticket changes its queue and do something.
In another post here I saw that there is an event called "TicketQueueUpdate". It think it's the right event for this purpose but how do I make use of it?
I only saw examples in which events are fired, but I never saw one where a custom eventhandler is triggered whenever a specific event occurs..
Listening to events
Listening to events
OTRS 3.0.10 (produktiv)
-
- Znuny expert
- Posts: 241
- Joined: 06 Feb 2009, 11:15
- Znuny Version: 3.0.x
- Company: Perl-Services.de
- Contact:
Re: Listening to events
You have to write an EventHandler.
Kernel/System/Ticket/Event/SayHelloOnMove.pm
And you have to enable it in the Config. You can add this to Kernel/Config.pm:
That's it. No magic 
Kernel/System/Ticket/Event/SayHelloOnMove.pm
Code: Select all
# --
# Kernel/System/Ticket/Event/SayHelloOnMove.pm - a event module
# Copyright (C) 2010-2011 perl-services.de, http://perl-services.de/
# --
# $Id: SayHelloOnMove.pm,v 1.5 2011/05/31 13:28:21 rb Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::Ticket::Event::SayHelloOnMove;
use strict;
use warnings;
use vars qw($VERSION);
$VERSION = qw($Revision: 1.5 $) [1];
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# get needed objects
for my $Needed (
qw(DBObject ConfigObject TicketObject LogObject QueueObject MainObject EncodeObject TimeObject)
)
{
$Self->{$Needed} = $Param{$Needed} || die "Got no $Needed!";
}
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(Event Data Config UserID)) {
if ( !$Param{$_} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
return;
}
}
return 1 if $Param{Event} ne 'TicketQueueUpdate'; # we just want to act when the ticket is moved
for (qw(TicketID)) {
if ( !$Param{Data}->{$_} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_ in Data!" );
return;
}
}
# ===== Here you can do whatever you want ;-) =========
my $TicketID = $Param{Data}->{TicketID};
$Self->{LogObject}->Log( Priority => 'error', Message => "Hello Ticket $TicketID, you have changed the queue!" );
# =====
return 1;
}
1;
Code: Select all
$Self->{'Ticket::EventModulePost'}->{'110-SayHello'} = {
'Event' => '(TicketQueueUpdate)', # Here you register the events you want to listen to
'Module' => 'Kernel::System::Ticket::Event::SeyHelloOnMove', # the module that is called for those events
};

Need a Perl/OTRS developer? You can contact me at info@perl-services.de
-
- Znuny newbie
- Posts: 6
- Joined: 14 Nov 2014, 14:55
- Znuny Version: 3.3.9
- Real Name: Vijay Patil
- Company: NA
Re: Listening to events
I am also getting same error. Please help me
-
- Znuny guru
- Posts: 5018
- Joined: 13 Mar 2011, 09:54
- Znuny Version: 6.0.x
- Real Name: Renée Bäcker
- Company: Perl-Services.de
- Contact:
Re: Listening to events
Which error? Please provide more details! What do you want to achieve? What did you try? What did you get? Are there any log messages (OTRS and webserver log)? Which OS? What OTRS version?vijay wrote:I am also getting same error. Please help me
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
-
- Znuny newbie
- Posts: 6
- Joined: 14 Nov 2014, 14:55
- Znuny Version: 3.3.9
- Real Name: Vijay Patil
- Company: NA
Re: Listening to events
I was getting error as the Action is not registered in Kernel/Config.pm.
-
- Znuny guru
- Posts: 5018
- Joined: 13 Mar 2011, 09:54
- Znuny Version: 6.0.x
- Real Name: Renée Bäcker
- Company: Perl-Services.de
- Contact:
Re: Listening to events
There is no "Action" involved here. This thread is about event modules...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de