Creating a Link to a Ticket via a Perl Script

Hi Everyone,

Does anyone have a code snippet that depicts the method for linking one
ticket to another using a perl script? It would be even better if the
snippet was part of code that was used to create a new ticket and link
to either existing ticket or a URI.

Take care!

Nick

Nick Metrowsky

Consulting System Administrator

303-684-4785 Office

303-684-4100 Fax

nmetrowsky@digitalglobe.com mailto:nmetrowsky@digitalglobe.com

DigitalGlobe (r), An Imaging and Information Company

http://www.digitalglobe.com http://www.digitalglobe.com

This is what I use. It does everything, creates tickets, does
parent-child relationships, and fills in some custom fields. You’d have
to change the custom fields and library locations to suit your
installation (or just don’t use those options). I find this easier to
use than the rt CLI which has limited options.

#!/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 STDERR $err . “\n” if $err;
sub print_usage
{
print “\nusage: rt_custom.pl -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 \n”;
print “-owner \n”;
print “-requestor \n”;
print “-priority \n”;
print “-AdminCc \n”;
print “-cc \n”;
print “-site \n”;
print “-work_type \n”;
print “-department \n”;
print “-group \n”;
print “-subject \n”;
print “-body \n”;
print “-RefersTo \n”;
print “-ReferredToBy \n”;
print “-DependsOn \n”;
print “-Parents \n”;
print “\nExample: ./rt_custom.pl -queue="Development"
-subject="This is a test subject for test script" -owner=‘bob’
-requestor=‘bob@bob.com’ -priority=99 -body="This is the body of the
ticket" -AdminCc="bobsboss@bob.com" -cc="bobswife@bob.com"
-site="secure.bob.com" -work_type="Task" -department="bob business
unit"\n\n”;
}From: rt-users-bounces@lists.bestpractical.com
[mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Nick
Metrowsky
Sent: Tuesday, March 14, 2006 11:36 AM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] Creating a Link to a Ticket via a Perl Script

Hi Everyone,

Does anyone have a code snippet that depicts the method for linking one
ticket to another using a perl script? It would be even better if the
snippet was part of code that was used to create a new ticket and link
to either existing ticket or a URI.

Take care!

Nick

Nick Metrowsky

Consulting System Administrator

303-684-4785 Office

303-684-4100 Fax

nmetrowsky@digitalglobe.com mailto:nmetrowsky@digitalglobe.com

DigitalGlobe (r), An Imaging and Information Company

http://www.digitalglobe.com http://www.digitalglobe.com


From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users->bounces@lists.bestpractical.com] On Behalf Of Rappaport, Evan
Sent: Tuesday, March 14, 2006 11:00 AM
To: Nick Metrowsky; rt-users@lists.bestpractical.com
Subject: RE: [rt-users] Creating a Link to a Ticket via a Perl Script>

This is what I use. It does everything, creates tickets, does parent-child >relationships, and fills in some custom fields. You’d have to change the >custom fields and library locations to suit your installation (or >just don’t use those options). I find this easier to use than the rt CLI >which has limited options.

Hi Evan-

Can you share some examples of how you use this script?

duncan

There is an example of a command line call to that script in the usage print statement. I put the script on a UNIX server and I use the script in multiple ways.

  1. Running it from cron for creating periodic tickets for various departments. Things like weekly reminders to check overnight backups or official timestamping of work shifts. Something like, shift turnovers for operations workers to signal that they are now taking over operations.

Example: of a daily ticket created from cron.

./rt_custom.pl -queue=“Storage” -subject=“Check overnight backups” -owner=‘nobody’ -requestor=‘bob@bob.com’ -priority=30 -body=“Check status of overnight backups and rotate backup tapes as necessasary.” -AdminCc=“bobsboss@bob.com” -work_type=“Task” -department=“Infrastructure” -requestor=“cronjob@rt.bob.com”

  1. Automatically generating tickets from server alarms. Basically using Nagios to generate tickets automatically so it saves people who are responding to alarms from opening tickets for problems. The ticket is generated when someone acknowleges the alarm and adds their comment. The ticket would go into an alarm queue and be owned by the person who acknowleged the alarm so they can come back with an update and close the ticket later.

Nagios might do a call to the script that looks like this.

./rt_custom.pl -queue=“Alarms” -subject=“Diskspace at %5 on live-production-server-1” -owner=‘bob’ -body=“Going to delete old log files” -priority=99 -AdminCc=“bobsboss@bob.com” -requestor=“bob@bob.com”

  1. As part of a CGI to automatically generate tickets from custom web pages. It might be used as the stand alone script though escape to the shell or I might just use the Perl code directly in the CGI. Basically this would be web pages to create custom tickets through HTML forms for frequently requested things like DNS requests.

Example

./rt_custom.pl -queue=“Networking” -subject=“DNS Request” -body=“Please set up a new DNS entry for welovebob.bob.com to point to 208.182.91.44.” -requestor=“sally@bob.com” -department=“Ad Sales”

These are the basic things I use it for but since it’s a fairly generic ticket generator you can do whatever you want. For example, you can set up something like a script that calls this and creates a parent ticket which has three children each of which have two dependent tickets of their own etc.

I use either “site” or “department” as the business unit making the request for work and use the queue as the department which is getting the request to perform work. People from each department would be watching their respective queues and dealing with requests from there or reassigning requests to other queues.-----Original Message-----
From: Duncan Shannon [mailto:dshannon@techfluent.com]
Sent: Tuesday, March 14, 2006 1:22 PM
To: Rappaport, Evan; Nick Metrowsky; rt-users@lists.bestpractical.com
Subject: RE: [rt-users] Creating a Link to a Ticket via a Perl Script


From: rt-users-bounces@lists.bestpractical.com
[mailto:rt-users->bounces@lists.bestpractical.com] On Behalf Of
Rappaport, Evan
Sent: Tuesday, March 14, 2006 11:00 AM
To: Nick Metrowsky; rt-users@lists.bestpractical.com
Subject: RE: [rt-users] Creating a Link to a Ticket via a Perl Script>

This is what I use. It does everything, creates tickets, does parent-child >relationships, and fills in some custom fields. You’d have to change the >custom fields and library locations to suit your installation (or >just don’t use those options). I find this easier to use than the rt CLI >which has limited options.

Hi Evan-

Can you share some examples of how you use this script?

duncan