[rt-users] Creating tickets via cron

Rappaport, Evan evan at mtvn.com
Fri Jan 27 09:38:53 EST 2006


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 at 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 <rt queue> [optional parameters]\n";
	print "\nThe queue name is manditory but all other parameters are optional.\n";
	print "The following options are supported:\n\n";
	print "-subject <subject> \n";
	print "-owner <owner> \n";
	print "-requestor <requestor e-mail> \n";
	print "-priority <Initial Priority> \n";
	print "-AdminCc <AdminCc> \n";
	print "-cc <Cc> \n";
	print "-site <site> \n";
	print "-work_type <Work Type> \n";
	print "-department <department> \n";
	print "-group <Group Performed By>\n";
	print "-subject <subject> \n";
	print "-body <ticket body> \n";
	print "-RefersTo <Refers To> \n";
	print "-ReferredToBy <Referred To By> \n";
	print "-DependsOn <Depends On>\n";
	print "-Parents <Parents>\n";
	print "\nExample: ./rt_custom.pl -queue=\"Development\" -subject=\"This is a test subject for test script\" -owner='bob' -requestor='joe\@blow.com' -priority=99 -body=\"This is the body of the ticket\" -AdminCc=\"supervisor\@blow.com\" -cc=\"manager\@blow.com\" -site=\"blow.com\" -work_type=\"Task\" -department=\"Unix Systems\"\n\n";
}


=====================================



 

-----Original Message-----
From: rt-users-bounces at lists.bestpractical.com [mailto:rt-users-bounces at lists.bestpractical.com] On Behalf Of Paulo Matos
Sent: Thursday, January 26, 2006 2:33 PM
To: Andy Moran
Cc: rt-users at lists.bestpractical.com
Subject: Re: [rt-users] Creating tickets via cron

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> http://search.cpan.org/~autrijus/RTx-WebCronTool/

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 at 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



More information about the rt-users mailing list