RT has fairly simple scriptable tools for batch ticket creation and edits.
RT has powerful scriptable tools for batch ticket creation and edits.
There are two methods to do batch edits on existing tickets. The first is within the RT web interface, once you have results from a search. See below for more details. The second method is from a linux/unix command-line and is documented on this page.
The rt command-line tool also makes it easy to create new tickets in a batch, which is not possible from the RT web interface.
All RT fields can be updated from the command-line tool, except for the Custom Roles we're no longer using ("Accountable" and "Supporters"). See below for specifics and a few caviats.
The command-line tool 'rt'
is installed on linux.cs.uwaterloo.ca
and linux.cscf.uwaterloo.ca
. It may be installed on any Ubuntu system with the following installation:
shell:~> sudo apt-get install rt4-clients
On a typical ubuntu server, it will also install libterm-readline-perl-perl
but doesn't install any more of the RT server/client dependency chain.
Once the package is installed, all that remains is configuring it for your user.
The rt command-line tool will operate as your userid; so you need your RT login information. Note that it stores the password as plaintext, so the first step below ensures the file is not readable by other users.
shell:~> touch ~/.rtrc && chmod 600 ~/.rtrc
~/.rtrc
to contain:
server https://rt.uwaterloo.ca user yourid passwd ***************
And that's all the necessary configuration.
shell:~> rt show user/drallen id: user/2742 Password: ******** Name: drallen EmailAddress: drallen@uwaterloo.ca RealName: Daniel Allen Gecos: drallen Organization: Computer Science (CSCF) Address1: DC 2621 WorkPhone: 519-888-4567 x35448 Comments: Autocreated on ticket submission daniel.allen@uwaterloo.ca (1491407) merged into this user drallen@connect.uwaterloo.ca (1491409) merged into this user drallen@connect.uwaterloo.ca (1491409) unmerged from this user Privileged: 1 Disabled: 0 shell:~>
Assuming this works, you're ready to modify a ticket from the command-line.
You can find context-specific help at any time with the command rt help
If you look at the docs or the
rt help
, there are often more than one way to do things. These instructions will keep things as simple as possible.
There are different formats for setting fields, adding a transaction such as a comment, and adding links such as See Also, Dependencies, and Children.
There is a different format for setting fields with one value or multiple values. If you're unsure whether a field can have multiple values, try editing it within RT. Most fields have one value. If there is a checkbox next to it (such as for requestors and admin-cc), it can have multiple values. If it's a custom field, the interface will prompt "Enter one value" or "Enter multiple values".
Setting one or many fields with one value follows the following format:
rt edit <ticket> set <fieldname='value'> [<fieldname='value'> <fieldname='value'>]
Sample:
rt edit 637182 set subject='[Fall2017] Install School Laptop for MMath Thesis student Abbas Abou Daya' owner='drallen'
Setting one or many fields with more than one value follows the following format:
rt edit <ticket> add <fieldname='value'> [<fieldname='value'> <fieldname='value'>]
Sample:
rt edit 637182 add admincc='drallen'
The above can be combined into a single command. Sample:
rt edit 637182 add admincc='drallen' set subject='whatever' owner='drallen'
Remember that Links are not multiple-value fields; see below for Adding and Removing Links.
rt comment <ticket> -m "<value>"
Sample:
rt comment 637182 -m "this text will be added as a comment to the ticket"
There are six named link types:
DependsOn / DependedOnBy
A depends upon B (or vice versa).
RefersTo / ReferredToBy
A refers to B (or vice versa).
MemberOf / HasMember
A is a child or a parent of B.
rt link <ticket> <typeOfLink> <otherTicket>
Sample:
rt link 637182 HasMember 636971
Deleting a link is done by specifying link -d
instead. Sample:
rt link -d 637182 HasMember 636971
Creating a ticket requires choosing a queue and optionally any other fields. The returned text will include the new ticket id.
rt create -t ticket set queue=<queue> [<fieldname='value'> <fieldname='value'> <fieldname='value'>]
Sample (with optional extra \ continuation-characters to split the command into shorter lines):
rt create -t ticket set queue=CSCF-RSG subject='[Fall2017] Install To be determined for MMath Thesis student Mohammed Alfatafta (maaalfat)'\ set 'CF-Summary (Wiki)'='Supervisor- Al Kiswany, Samer, Room -' 'CF-Subscription Code'='sc-alkiswan' Due='2017-09-05 17:00' priority=3 \ owner=rgarcia add AdminCC=lfolland,pbeldows
The output will be:
# Ticket 636971 created.
If there are warnings for any fields, they will appear before the creation message. To fix it, you'll need to do an edit on the ticket.
If there is no creation message, you'll have to fix the error and then re-run the create command.
Remarks on creating tickets:
'CF-'
and custom fields containing a space must be quoted
You cannot set links (dependencies/children/references) at the same time as you create the ticket. If you want to create a large number of tickets and then add dependencies, there are at least two options: a) two-step command-line; or b) use RT's built-in "Bulk Update"
link
command. For example:
shell:~> rt create -t ticket set queue=CSCF-RSG subject='RT Batch Creation: test subticket 2' set 'CF-Subscription Code'='sc-rt' Due='next wednesday' # Ticket 636974 created. shell:~> rt link 636974 DependsOn 777777 Ticket 636974 depends on Ticket 777777. Created link 636974 DependsOn 777777
A simple bash script could be created from spreadsheet data; repeating a one-line command to create a batch of tickets, running that script and capturing the output, and parsing that output to construct a script that would create Dependencies. (See directly above for "Two Step Command-line").
Due="next wednesday"
(which will set the time to now on next Wednesday).
rt help
for a large number of additional options. For example, in rt help create
we see the following chained unix command:
rt ls -t tickets -i 'Priority > 5' | rt edit - set status=resolved