Listening to events

English! place to talk about development, programming and coding
Post Reply
grisuu
Znuny newbie
Posts: 15
Joined: 29 Jun 2011, 20:36
Znuny Version: 3.0

Listening to events

Post by grisuu »

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..
OTRS 3.0.10 (produktiv)
renee
Znuny expert
Posts: 241
Joined: 06 Feb 2009, 11:15
Znuny Version: 3.0.x
Company: Perl-Services.de
Contact:

Re: Listening to events

Post by renee »

You have to write an EventHandler.

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;
And you have to enable it in the Config. You can add this to Kernel/Config.pm:

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
};
That's it. No magic ;-)
Need a Perl/OTRS developer? You can contact me at info@perl-services.de
vijay
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

Post by vijay »

I am also getting same error. Please help me
reneeb
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

Post by reneeb »

vijay wrote:I am also getting same error. Please help me
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?
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
vijay
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

Post by vijay »

I was getting error as the Action is not registered in Kernel/Config.pm.
reneeb
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

Post by reneeb »

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
Post Reply