Re: [rt-users] Call external script in scrip

2014-02-05 Thread Kevin Falcone
On Mon, Feb 03, 2014 at 12:33:17PM +0100, Anthony BRODARD wrote:
Feb 3 12:09:50 bob RT: [10535] DBD::mysql::st execute failed: Lock wait 
 timeout exceeded; try
restarting transaction at 
 /usr/local/share/perl/5.14.2/DBIx/SearchBuilder/Handle.pm line 589.
Feb 3 12:09:50 bob RT: [10535] RT::Handle=HASH(0x71041f8) couldn't execute 
 the query 'SELECT *
FROM Tickets WHERE id = ? FOR UPDATE' at

It appears that RT is holding a lock for updating your ticket while a
second script connects and then times out attempting to update the
same ticket.  I suggest that your main scrip become a Batch scrip so
that it runs after the initial transaction completes and the lock is
released.

-kevin


pgprVQQ4srdnK.pgp
Description: PGP signature


[rt-users] Call external script in scrip

2014-02-03 Thread Anthony BRODARD
Hi list !

I want to set up a process to create a LDAP account automatically after
admin validation.
Currently, to create an account, user open a ticket and we run an homemade
bash script with the username as argument. It create the account, set some
options, and return the password.
I want to automatize this task. The idea is to create three CF : Status,
Username and Password. When an user create a ticket for a new LDAP account
and if the admin agrees, he will set the CF-Username and valide the request
by setting the CF-Status to OK.
At this time, a scrip must be launched, call the bash script, set a random
password, and send the credentials to user and close the ticket.

Also, for test purpose, I've created this basic bash script
(/opt/rt4/bin/create_user.sh):

/opt/rt4/bin/rt edit $1 set CF.{PASS}=Passwd
/opt/rt4/bin/rt edit $1 set CF.{Validation}=Send
exit 0


And theses scrips :

CreateUser:
Custom condition :

my $Ticket = $self-TicketObj;
return 0 unless $self-TicketObj-FirstCustomFieldValue('Status') eq 'OK';
return 1;

Custom Action:

my $ticket = $self-TicketObj;
my $id = $ticket-Id;
system(/opt/rt4/bin/create_user.sh $id  /tmp/debug);
return 1;


SendCredentials:
Custom Condition :

my $Ticket = $self-TicketObj;
return 0 unless $self-TicketObj-FirstCustomFieldValue('Status') eq 'Send';
return 1;

Action : Notify requestor and Cc
Template : Custom with credentials

When I set a the CF Status to OK, the scrip is correctly launched, and I
see the first connection of the bash script is the system log :
Feb  3 12:08:58 bob RT: [10535] Successful login for Anthony from localhost

Then, apache did not respond during many seconds, and I see the second
connection :
Feb  3 12:09:31 bob RT: [10534] Successful login for Anthony from localhost

And then, few seconds after :
Feb  3 12:09:50 bob RT: [10535] DBD::mysql::st execute failed: Lock wait
timeout exceeded; try restarting transaction at
/usr/local/share/perl/5.14.2/DBIx/SearchBuilder/Handle.pm line 589.
Feb  3 12:09:50 bob RT: [10535] RT::Handle=HASH(0x71041f8) couldn't execute
the query 'SELECT * FROM Tickets WHERE id = ? FOR UPDATE' at
/usr/local/share/perl/5.14.2/DBIx/SearchBuilder/Handle.pm line
602.#012#011DBIx::SearchBuilder::Handle::SimpleQuery(RT::Handle=HASH(0x71041f8),
SELECT * FROM Tickets WHERE id = ? FOR UPDATE, 28) called at
/usr/local/share/perl/5.14.2/DBIx/SearchBuilder/Record.pm line
1234#012#011DBIx::SearchBuilder::Record::_LoadFromSQL(RT::Ticket=HASH(0x420fff0),
SELECT * FROM Tickets WHERE id = ? FOR UPDATE, 28) called at
/opt/rt4/sbin/../lib/RT/Record.pm line
1605#012#011RT::Record::LockForUpdate(RT::Ticket=HASH(0x420fff0)) called at
/opt/rt4/sbin/../lib/RT/Record.pm line
1641#012#011RT::Record::_NewTransaction(RT::Ticket=HASH(0x420fff0), Type,
CustomField, Field, 3, OldReference, undef, NewReference,
RT::ObjectCustomFieldValue=HASH(0x422c5b8), ...) called at
/opt/rt4/sbin/../lib/RT/Record.pm line
2034#012#011RT::Record::_AddCustomFieldValue(RT::Ticket=HASH(0x420fff0),
Field, RT::CustomField=HASH(0x4211c20), Value, waza) called at
/opt/rt4/sbin/../lib/RT/Record.pm line
1913#012#011RT::Record::AddCustomFieldValue(RT::Ticket=HASH(0x420fff0),
Field, RT::CustomField=HASH(0x4211c20), Value, waza) called at
/opt/rt4/share/html/REST/1.0/Forms/ticket/default line
403#012#011HTML::Mason::Commands::__ANON__(id, 28, args, undef,
format, undef, changes, HASH(0x41ed280)) called at
/usr/local/share/perl/5.14.2/HTML/Mason/Component.pm line
138#012#011HTML::Mason::Component::run(HTML::Mason::Component::FileBased=HASH(0x420f990),
id, 28, args, undef, format, undef, changes, HASH(0x41ed280), ...)
called at /usr/local/share/perl/5.14.2/HTML/Mason/Request.pm line
1300#012#011eval {...} called at
/usr/local/share/perl/5.14.2/HTML/Mason/Request.pm line
1295#012#011HTML::Mason::Request::comp(undef, undef, id, 28, args,
undef, format, undef, changes, ...) called at
/opt/rt4/share/html/REST/1.0/dhandler line
299#012#011HTML::Mason::Commands::__ANON__(pass
Feb  3 12:09:50 bob RT: [10535]
rt-4.2.2-10535-1391425790-954.28-1...@support.bob #28/633 - Scrip
18 SendCredentials
Feb  3 12:09:50 bob RT: [10535]
rt-4.2.2-10535-1391425790-954.28-1...@support.bob sent  To:
anthony@test.localhost
Feb  3 12:10:04 bob RT: [10534]
rt-4.2.2-10534-1391425804-931.28-1...@support.bob #28/635 - Scrip
18 SendCredentials
Feb  3 12:10:04 bob RT: [10534]
rt-4.2.2-10534-1391425804-931.28-1...@support.bob sent  To:
anthony@test.localhost
Feb  3 12:10:05 bob RT: [10529] Use of uninitialized value in string eq at
(eval 449) line 2.
Feb  3 12:10:05 bob RT: [10529] Use of uninitialized value in string eq at
(eval 451) line 2.
Feb  3 12:10:05 bob RT: [10529] Use of uninitialized value in string eq at
(eval 457) line 2.
Feb  3 12:10:05 bob RT: [10529] Use of uninitialized value in string eq at
(eval 459) line 2.
Feb  3 12:10:05 bob RT: [10538] Malformed UTF-8 character (unexpected end
of string) in string ne at /usr/share/perl/5.14/Locale/Maketext.pm line 538.

And in the ticket