Filter/Throtle tickets created via SOAP

English! place to talk about development, programming and coding
Post Reply
blueCat1301
Znuny newbie
Posts: 4
Joined: 28 Jun 2013, 15:43
Znuny Version: 3.1.8

Filter/Throtle tickets created via SOAP

Post by blueCat1301 »

Hi,

What would be be best way to create a filter for ticket creation via SOAP?

My goal is to limit the creation rate for tickets via SOAP: if creation a of a duplicate (same user, same subject) ticket is attempted faster than - let's say - 5 per minute, this filter should deny the creation of ticket.

I am looking for a solution that is maintainable and does not break the upgrade process.

I know I can just edit Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm or probably better create a new operation MyTicketCreate.pm and configure accordingly a new web services.

Any suggestion welcomed.

Best,
BC
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Filter/Throtle tickets created via SOAP

Post by crythias »

Create a ticket event module that handles this request.
(basically, you'll close/move/delete/merge the subsequent entries after they're created...)

It doesn't appear that the overall code is that hard to accomplish:

Is this a TicketCreate Event?
Get the ticketId for this event
TicketGet the Ticket Title for the current ticket
TicketSearch for the same Title TicketCreateTimeNewerMinutes => 5
TicketGet the oldest ticket in that result
check Created vs now

Apply disposition of the ticket.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
blueCat1301
Znuny newbie
Posts: 4
Joined: 28 Jun 2013, 15:43
Znuny Version: 3.1.8

Re: Filter/Throtle tickets created via SOAP

Post by blueCat1301 »

Thank you for your suggestion. Event mechanism looks very promising.

I still have an issue: TicketCreate event fires for all ticket creations, no matter the method of creation. I need to filter only those tickets created via SOAP.

How can I find out how a ticket was created? How can I filter only TicketCreate events generated after a SOAP ticket creation?

Thank you,
BC.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Filter/Throtle tickets created via SOAP

Post by crythias »

blueCat1301 wrote:How can I find out how a ticket was created?
Any number of ways you want, really, including Sender, Queue, DynamicField, Subject (known SOAP event subject pieces) or (possibly) don't bother, because what would be the likelihood of multiple tickets with the same subject within 5 minutes from any other source?
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
blueCat1301
Znuny newbie
Posts: 4
Joined: 28 Jun 2013, 15:43
Znuny Version: 3.1.8

Re: Filter/Throtle tickets created via SOAP

Post by blueCat1301 »

Hi,

Thank you for your suggestion. My intention is to not allow tickets to be created if certain conditions are meet. The idea with filter looks great.

One more question: how do I prevent ticket creation? Or delete it?

Returning 0 does not work, and deleting the ticket is horribly wrong :-(.

Any help appreciated.
BC.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Filter/Throtle tickets created via SOAP

Post by crythias »

blueCat1301 wrote:One more question: how do I prevent ticket creation?

PostMaster Filter, roughly same concept.
Or delete it?
TicketDelete.

See dev.otrs.org
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
blueCat1301
Znuny newbie
Posts: 4
Joined: 28 Jun 2013, 15:43
Znuny Version: 3.1.8

Re: Filter/Throtle tickets created via SOAP

Post by blueCat1301 »

Hi,

I tried TicketDelete, but probably am doing something wrong. I used the code bellow, but the system log filled with errors like "Column 'queue_id' cannot be null, SQL: 'INSERT INTO ticket_history (name, history_type_id, ticket_id, article_id, queue_id, owner_id, priority_id, state_id, type_id, valid_id, create_time, create_by, change_time, change_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,".

Thank you,
BC

Code: Select all

sub Run {
    my ( $Self, %Param ) = @_;
	
    # check needed stuff
    for (qw(Data Event Config)) {
        if ( !$Param{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
            return;
        }
    }
    for (qw(TicketID)) {
        if ( !$Param{Data}->{$_} ) {
            $Self->{LogObject}->Log( Priority => 'error', Message => "Need $_ in Data!" );
            return;
        }
    }
    return 1 if ( $Param{Event} ne 'TicketCreate' );

	# Get ticket info
	my %Ticket = $Self->{TicketObject}->TicketGet(
		TicketID      => $Param{Data}->{TicketID},
		UserID        => $Param{UserID},
		DynamicFields => 1,
	);
	
	# Current check is title must begin with [SOAP]
	return 1 if ( $Ticket{Title} !~ /^\[SOAP\]/);
	
	$Self->{LogObject}->Log( Priority => 'notice', Message => "SOAPTicketCreateFilter: SOAP ticket creation event - $Ticket{Title}" );

	#
	# Check for duplicates: Same Title and same CustomerUserID 
	my @TicketIDs = $Self->{TicketObject}->TicketSearch(
				Result => 'ARRAY', 
				Title => "$Ticket{Title}",
				CustomerUserLogin => "$Ticket{CustomerUserID}",
				UserID        => $Param{UserID},
			);
	return 1 if (  scalar (@TicketIDs) == 1); # only one ticket
	
	# Debug only		
	$Self->{LogObject}->Log( Priority => 'notice', Message => "SOAPTicketCreateFilter: Similar tickets $_ " ) for (@TicketIDs) ;
	
	
	my $success = $Self->{TicketObject}->TicketDelete(
				TicketID      => $Param{Data}->{TicketID},
				UserID        => $Param{UserID},
			);

	if ( $success )	{
		$Self->{LogObject}->Log( Priority => 'notice', Message => "SOAPTicketCreateFilter: Deleted ticket $Param{Data}->{TicketID} " );
	} else {
		$Self->{LogObject}->Log( Priority => 'notice', Message => "SOAPTicketCreateFilter: Unable to delete ticket $Param{Data}->{TicketID} " );
	}
			
    return 0;
}
Post Reply