The easiest way that I’ve found to create RT tickets from cron is to make a small universal perl script that takes parameters. The perl script uses the RT perl interface.
A sample call to the perl script from cron would be something like this.
/home/scheduler/rt_custom.pl -subject=‘Diary for Early this week’ -owner=‘Nobody’ -requestor=‘joe@blow.com’ -queue=‘Morning Tasks’ -priority=‘99’ -work_type=‘Task’ -department=‘Unix Systems’
And the code for rt_custom.pl would be something like this. Note, I use some custom fields which will differ from your RT installation.
#!/usr/bin/perl -w
use lib (“/opt/rt3/local/lib”,“/opt/rt3/lib”);
use RT::Interface::CLI;
use RT;
use RT::Ticket;
use RT::CurrentUser;
use Getopt::Long;
$queue = ‘’;
$body = ‘’;
GetOptions (“queue=s” => $queue,
“subject=s” => $subject,
“owner=s” => $owner,
“requestor=s” => $requestor,
“priority=s” => $priority,
“body=s” => $body,
“AdminCc=s” => $AdminCc,
“cc=s” => $cc,
“site=s” => $site,
“work_type=s” => $work_type,
“department=s” => $department,
“group=s” => $group,
“RefersTo=s” => $RefersTo,
“ReferredToBy=s” => $ReferredToBy,
“DependsOn=s” => $DependsOn,
“Parents=s” => $Parents
);
setting some defaults
if ($queue eq ‘’)
{
print_usage();
exit (0);
}
if ($body eq ‘’)
{
$body=’ ';
}
RT::LoadConfig();
RT::Init();
if ($owner eq ‘’) {$owner = ‘Nobody’;}
my $CurrentUser = RT::Interface::CLI::GetCurrentUser();
use MIME::Entity;
my $ticket = new RT::Ticket($CurrentUser);
my $ticket_body = MIME::Entity->build(Data => $body,
Type => ‘text/plain’);
my %ticket_vals = ( Queue => $queue,
Subject => $subject,
Owner => $owner,
Requestor => $requestor,
InitialPriority => $priority,
# FinalPriority => ‘0’,
MIMEObj => $ticket_body,
AdminCc => $AdminCc,
Cc => $cc,
‘CustomField-1’ => $site,
‘CustomField-2’ => $work_type,
‘CustomField-9’ => $department,
‘CustomField-14’ => $group,
‘RefersTo’ => $RefersTo,
‘ReferredToBy’ => $ReferredToBy,
‘DependsOn’ => $DependsOn,
‘MemberOf’ => $Parents
);
my ($id, $transaction_object, $err) = $ticket->Create(%ticket_vals); print $err . “\n” if $err;
sub print_usage
{
print “\nusage: rt_custom.pl -queue
On Thu, 26 Jan 2006, Paulo Matos wrote:
pm> RTx-WebCronTool - web interface for the built-in “rt-crontool”
pm> utility, allowing scheduled processes to be launched remotely.
pm> RTx-WebCronTool-0.01 - Display RT API documentation online - metacpan.org
Please ignore this last part… this is not the answer!!
rt-crontool, is used to act on existent tickets… but it can run arbitry code from RT, so in theory it is possible (but might be the hard way to do what you want).
Paulo Matos
|Sys & Net Admin | Centro de Informática |
|Faculdade de Ciências e Tecnologia | Tel: +351-21-2948596 |
|Universidade Nova de Lisboa | Fax: +351-21-2948548 |
|P-2829-516 Caparica | e-Mail: pjsm@fct.unl.pt |
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
Be sure to check out the RT Wiki at http://wiki.bestpractical.com
Download a free sample chapter of RT Essentials from O’Reilly Media at http://rtbook.bestpractical.com
WE’RE COMING TO YOUR TOWN SOON - RT Training in Amsterdam, Boston and San Francisco - Find out more at http://bestpractical.com/services/training.html