Custom Condition to run script every X minintes

Hi there :slight_smile:

I was looking at the documentation over on

https://docs.bestpractical.com/rt/4.4.2/customizing/scrip_conditions_and_action.html#Custom-Conditions

I’m thinking on creating a condition (without rt-crontool) in /opt/rt4/lib/RT/Condition. Which would run a script using it’s id every X mins, is this possible ?

Why not use rt-crontool? That’s what its made for! It should be easy to create a custom condition ( Put it in local/lib/RT/Condition/ ) and provide some action to be performed if the condition is true

1 Like

Thanks for the feedback :slight_smile:

So i was playing around with this for a while. My thought is, to create a custom Condition which always returns true in order to do an action.
The action I am trying to do is to run a custom script in RT.

Starting with the Condition

package RT::Condition::RunCustomScriptCondition;
use strict;
use warnings;
use base 'RT::Condition';
sub IsApplicable {
    my $self = shift;

return 1; # So always returns true
}

1; # So always returns true

With the Action, I simply wish to run a custom script via ID

package RT::Action::RunCustomScriptAction;
use strict;
use warnings;
use base 'RT::Action';

sub Prepare {
my $self = shift;


return 1; 
}

sub Commit {
my $self = shift;

# run custom script 

return 1; 
}

1;
1 Like

Hi again :slight_smile:
I am using RT 4.4.0 and i can’t seem to find the ‘Action’ & ‘Condition’ section, to create a global action & condition. Was this implemented in 4.4.0?

Thank you for any feedback :slight_smile:

Are you performing this action via rt-crontool or wanting to create a new scrip in RT?

I am using RT 4.4.0 and i can’t seem to find the ‘Action’ & ‘Condition’ section, to create a global action & condition. Was this implemented in 4.4.0?

Off the top of my head I believe it is a relatively new feature, maybe added in 4.4.4.

1 Like

The idea was to create a custom condition and action and make rt-crontool run every x mins.
The way I was going about is it to then attach the custom condition and action to the custom script (in RT) and then make rt-crontool, 1. search for the queue, 2. custom condition, 3. custom action
So without a input of a global action & condition inserted in the RT web interface, this will all fall apart

Now I could also just use rt-crontool to run the custom scripts, i just need to find a way to run a Custom Script ID inside the custom action .pm .

also, the earliest documentation on these global action and condition web interface pages are RT 4.4.2

No but it is available as a plugin on CPAN:
RT::Extension::AdminConditionsAndActions

1 Like

You don’t want to create a new scrip for rt-crontool, instead you can just point to the new conditions and actions you created:

rt-crontool \
      --search RT::Search::FromSQL  --search-arg 'Queue="General"' \
      --condition RT::Condition::RunCustomScriptCondition \
      --action RT::Action::RunCustomScriptAction
1 Like

When I applied this to the RT_Config.pm,

Plugin(RT::Extension::AdminConditionsAndActions'); 

followed with

rm -rf /opt/rt4/var/mason_data/obj

i ended up getting an ’ Internal Server Error’. Good thing it wasn’t on the live system.

So for the RunCustomScriptAction, Can I tell it to run Custom Script (23) for example?, i wouldn’t want to run all the scripts in the queue, im not sure if im explaining myself correctly

For the above example,

  1. It searches for tickets in queue “General”
  2. Then it runs each ticket over the condition
  3. If the condition ruturns true then run the action for the single ticket
1 Like

Very nice, thank you once again :slight_smile:

So with you’re example, I am going to try

  1. Search tickets in queue “General”
  2. Custom Condition will always return true
  3. Custom Action would be to run script ( ID 23)

Now I realized how silly I was, it should be

  1. Search tickets in queue “General”
  2. Custom Condition will always return true
  3. Paste Script (ID 23) into a Custom Action
    :sweat_smile:

so easy at the end :slight_smile:

Hi sorry again,
I applied the new Condition & Action. When I run rt-crontool, I keep getting this error to load it up in rt-crontool line 187

Can't locate object method "new" via package "RT::Condition::CustomConidition" (perhaps you forgot to load "RT::Condition::CustomConidition"?) at /opt/rt4/bin/rt-crontool line 187. (/opt/rt4/bin/../lib/RT.pm:390)

I tried to load it up inside rt-crontool and found

 if ($condition) {
    my $condition_obj = $condition->new(
        TransactionObj => $transaction,
        TicketObj      => $ticket,
        ScripObj       => $void_scrip,
        TemplateObj    => $template_obj,
        Argument       => $condition_arg,
        CurrentUser    => $CurrentUser,
    );

Where did you place the action and condition files?
package RT::Action::RunCustomScriptAction;

1 Like

/opt/rt4/lib/RT/Condition/

however to be honest with you, it doesn’t really need a Condition to be run because I just tested it.

But it will be good knowledge to know why this happened, maybe I should put it in a different directory? I heard this would be better for upgrading RT in the future :slight_smile:

You can actually make a local version so that your custom stuff won’t be wiped away:

 /opt/rt4/local/lib/RT/Condition/
1 Like