TicketSearch: UserID and disabling cache

Moderator: crythias

Post Reply
pwaring
Znuny newbie
Posts: 9
Joined: 02 Apr 2014, 13:45
Znuny Version: 3.2.10
Contact:

TicketSearch: UserID and disabling cache

Post by pwaring »

I'm trying to query an instance of OTRS from a separate script (code below, mostly comes from the example in Kernel::System::Ticket to create a ticket object which I can then use to search) to find tickets matching certain criteria and then acting upon them.

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper::Simple;

use lib '/var/lib/otrs/otrs-3.2.10';

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Time;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::Ticket;

my $ConfigObject = Kernel::Config->new();
my $EncodeObject = Kernel::System::Encode->new(
  ConfigObject => $ConfigObject,
);
my $LogObject = Kernel::System::Log->new(
  ConfigObject => $ConfigObject,
  EncodeObject => $EncodeObject,
);
my $TimeObject = Kernel::System::Time->new(
  ConfigObject => $ConfigObject,
  LogObject    => $LogObject,
);
my $MainObject = Kernel::System::Main->new(
  ConfigObject => $ConfigObject,
  EncodeObject => $EncodeObject,
  LogObject    => $LogObject,
);
my $DBObject = Kernel::System::DB->new(
  ConfigObject => $ConfigObject,
  EncodeObject => $EncodeObject,
  LogObject    => $LogObject,
  MainObject   => $MainObject,
);
my $TicketObject = Kernel::System::Ticket->new(
  ConfigObject       => $ConfigObject,
  LogObject          => $LogObject,
  DBObject           => $DBObject,
  MainObject         => $MainObject,
  TimeObject         => $TimeObject,
  EncodeObject       => $EncodeObject,
);

my $ticket_id = $ARGV[0];
print "Searching for ticket ID: $ticket_id\n";

my $user_id = $ARGV[1];

my %query = (
  Result => 'ARRAY',
  TicketNumber => "'%$ticket_id%'",
  UserID => $user_id,
);

my @results = $TicketObject->TicketSearch(%query);

warn Dumper(@results);
So far I'm having two problems. First of all, if I try a ticket search without specifying UserID in the query I get the following error:

Code: Select all

ERROR: ?LogPrefix?-10 Perl: 5.16.3 OS: linux Time: Thu Apr  3 12:50:02 2014

 Message: Need UserID or CustomerUserID params for permission check!

 Traceback (13867):
   Module: Kernel::System::TicketSearch::TicketSearch (OTRS 3.2.10) Line: 303
   Module: find-ticket.pl (unknown version) Line: 61
Is there any way to bypass this permission check? As far as I can tell from the documentation, passing UserID only returns tickets owned by that user, but I want to search across all tickets.

The other problem is that if I search for a ticket number and UserID where a match exists, I get the following error:

Code: Select all

ERROR: ?LogPrefix?-10 Perl: 5.16.3 OS: linux Time: Thu Apr  3 12:53:38 2014

 Message: Can't write '/var/lib/otrs/otrs-3.2.10/var/tmp/CacheFileStorable/CacheInternalGroup/e/1/e15d8cabb9ff6571e72982e334005aef': Permission denied

 Traceback (13952):
   Module: Kernel::System::Main::FileWrite (OTRS 3.2.10) Line: 446
   Module: Kernel::System::Cache::FileStorable::Set (OTRS 3.2.10) Line: 91
   Module: Kernel::System::Cache::Set (OTRS 3.2.10) Line: 132
   Module: Kernel::System::CacheInternal::Set (OTRS 3.2.10) Line: 134
   Module: Kernel::System::Group::GroupGroupMemberList (OTRS 3.2.10) Line: 882
   Module: Kernel::System::Group::GroupMemberList (OTRS 3.2.10) Line: 543
   Module: Kernel::System::TicketSearch::TicketSearch (OTRS 3.2.10) Line: 750
   Module: find-ticket.pl (unknown version) Line: 61

ERROR: ?LogPrefix?-10 Perl: 5.16.3 OS: linux Time: Thu Apr  3 12:53:38 2014

 Message: Can't write '/var/lib/otrs/otrs-3.2.10/var/tmp/CacheFileStorable/CacheInternalGroup/c/f/cf99d5189a554a526c03423cba336e49': Permission denied

 Traceback (13952):
   Module: Kernel::System::Main::FileWrite (OTRS 3.2.10) Line: 446
   Module: Kernel::System::Cache::FileStorable::Set (OTRS 3.2.10) Line: 91
   Module: Kernel::System::Cache::Set (OTRS 3.2.10) Line: 132
   Module: Kernel::System::CacheInternal::Set (OTRS 3.2.10) Line: 134
   Module: Kernel::System::Group::GroupMemberList (OTRS 3.2.10) Line: 574
   Module: Kernel::System::TicketSearch::TicketSearch (OTRS 3.2.10) Line: 750
   Module: find-ticket.pl (unknown version) Line: 61
I understand why I'm getting this error - the cache directory is owned by the apache user as I'm running this script as another user - but is there a way to disable the use of the cache when performing a ticket search in this way?
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: TicketSearch: UserID and disabling cache

Post by crythias »

UserID =1

make sure user running the script is a member of the group attached to the tmp (usermod -a -G groupname username) folder and the group has write access (chmod -R g+w tmp )
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
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: TicketSearch: UserID and disabling cache

Post by reneeb »

pwaring wrote: Is there any way to bypass this permission check? As far as I can tell from the documentation, passing UserID only returns tickets owned by that user, but I want to search across all tickets.
The search is done for all tickets but only ticket ids where the user has permission to are returned. You should add the super admin (user id 1) to all groups and pass user id 1.
pwaring wrote: I understand why I'm getting this error - the cache directory is owned by the apache user as I'm running this script as another user - but is there a way to disable the use of the cache when performing a ticket search in this way?
No. You could run the script as user apache

Code: Select all

sudo -u apache perl ...
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
pwaring
Znuny newbie
Posts: 9
Joined: 02 Apr 2014, 13:45
Znuny Version: 3.2.10
Contact:

Re: TicketSearch: UserID and disabling cache

Post by pwaring »

reneeb wrote:
pwaring wrote: Is there any way to bypass this permission check? As far as I can tell from the documentation, passing UserID only returns tickets owned by that user, but I want to search across all tickets.
The search is done for all tickets but only ticket ids where the user has permission to are returned. You should add the super admin (user id 1) to all groups and pass user id 1.
According to the Admin <-> Group page, UserID 1 already has all permissions for all groups (as do two other users whose IDs I've tried), but if I use UserID 1 for the ticket search I don't get any results. Does it make a difference if tickets are locked (as most of them seem to be)?
reneeb wrote:
pwaring wrote: I understand why I'm getting this error - the cache directory is owned by the apache user as I'm running this script as another user - but is there a way to disable the use of the cache when performing a ticket search in this way?
No. You could run the script as user apache

Code: Select all

sudo -u apache perl ...
Is there no other workaround for that? I'd have to install all the Perl module dependencies (e.g. IO::Interactive) globally or as the Apache user using local::lib, and I want to avoid changing the existing setup if at all possible.
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: TicketSearch: UserID and disabling cache

Post by crythias »

crythias wrote:my %query = (
  Result => 'ARRAY',
Do you want an array passed to a hash?
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
pwaring
Znuny newbie
Posts: 9
Joined: 02 Apr 2014, 13:45
Znuny Version: 3.2.10
Contact:

Re: TicketSearch: UserID and disabling cache

Post by pwaring »

crythias wrote:
crythias wrote:my %query = (
  Result => 'ARRAY',
Do you want an array passed to a hash?
I'm not sure what you mean by that. The result of TicketSearch goes into @result, which is an array, and the parameter to TicketSearch is a hash.
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: TicketSearch: UserID and disabling cache

Post by crythias »

sorry. I looked at it askew.
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
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: TicketSearch: UserID and disabling cache

Post by reneeb »

pwaring wrote: According to the Admin <-> Group page, UserID 1 already has all permissions for all groups (as do two other users whose IDs I've tried), but if I use UserID 1 for the ticket search I don't get any results. Does it make a difference if tickets are locked (as most of them seem to be)?
No, it doesn't make a difference. It is strange that there are no results. Have you checked the logs?
pwaring wrote:
reneeb wrote:
pwaring wrote: I understand why I'm getting this error - the cache directory is owned by the apache user as I'm running this script as another user - but is there a way to disable the use of the cache when performing a ticket search in this way?
No. You could run the script as user apache

Code: Select all

sudo -u apache perl ...
Is there no other workaround for that? I'd have to install all the Perl module dependencies (e.g. IO::Interactive) globally or as the Apache user using local::lib, and I want to avoid changing the existing setup if at all possible.
You could set the permissions of the cache dirs to world writable (the worst solution) or - the better solution - is to temporarily change the temp dir in the script...

Code: Select all

#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper::Simple;

use lib '/var/lib/otrs/otrs-3.2.10';

use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Time;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::Ticket;

my $ConfigObject = Kernel::Config->new();

# temporarily change temp dir to avoid permission issues with cache
$ConfigObject->Set( Key => 'TempDir', Value => '/tmp' );
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
pwaring
Znuny newbie
Posts: 9
Joined: 02 Apr 2014, 13:45
Znuny Version: 3.2.10
Contact:

Re: TicketSearch: UserID and disabling cache

Post by pwaring »

reneeb wrote:
pwaring wrote: According to the Admin <-> Group page, UserID 1 already has all permissions for all groups (as do two other users whose IDs I've tried), but if I use UserID 1 for the ticket search I don't get any results. Does it make a difference if tickets are locked (as most of them seem to be)?
No, it doesn't make a difference. It is strange that there are no results. Have you checked the logs?
There's nothing in the logs, but the searching seems to now be working with UserID 1. :)
reneeb wrote:You could set the permissions of the cache dirs to world writable (the worst solution) or - the better solution - is to temporarily change the temp dir in the script...
Thanks, the latter is a good workaround which fits what I want to do.
klopfa10
Znuny newbie
Posts: 20
Joined: 22 Jul 2015, 15:38
Znuny Version: OTRS 5.0.11
Real Name: Tobias

Re: TicketSearch: UserID and disabling cache

Post by klopfa10 »

Hi Guys,

maybe you can help me to solve my issue...
viewtopic.php?f=64&t=29893

There is something with the UserID=1 and Permission=ro - parameters i don't understand.
How do I need to use it along with the http-request?

Do I use something like this?

Code: Select all

<host>/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket?UserLogin=<agent>&Password=<Password>&QueueIDs=2,5&UserID=1&Permission=ro
I hope you can help me. I need to consume the ticketId's from more than 1 queue.

Best Regards!
OTRS 5.0.11 with KIX4OTRS 8.0.6
Post Reply