Reporting tickets from a script, getting ticket ID back?

I’m currently investigating how I can generate RT tickets from a
script, and let the script keep track of the ticket ID of already
reported issues.

I found a thread from 2001 giving an example, and have implemented
this.
URL:http://lists.bestpractical.com/pipermail/rt-devel/2001-April/001108.html.
Is this still the best way to do this?

The script I have at the moment work, but it seem rather crude to call
rt-mailgate in debug mode just to get the ticket-ID out. Is there no
simpler way? Perhaps rt-mailgate should get some extra functionality
to allow it to print the ticket-ID to stdout on request?

This is my current proof-of-concept script:

#!/usr/bin/perl

use strict;
use warnings;

use File::Temp qw(tempfile);

my $rturl = “https://rt-dev.uio.no/”;
my $mailgate = “/local/bin/rt-mailgate”;

sub new_ticket {
my ($queue, $from, $subject, $body) = @_;

my ($fh, $filename) = tempfile("rt-reportXXXXX", DIR => "/tmp");

print $fh "From: $from\n";
print $fh "Subject: $subject\n";
print $fh "\n";
print $fh "$body\n";

open(MAILGATE, "$mailgate --action correspond --queue $queue --url $rturl --debug < $filename 2>&1 |") || die "Unable to start $mailgate";
my $id;

okTicket: 1728Queue: generalOwner: NobodyStatus: newSubject: TestingRequestor: pere@hungry.com at /site/rt3/bin/rt-mailgate line 108, <> chunk 1.

while (<MAILGATE>) {
    chomp;
    $id = $1 if m/Ticket: (.+)Queue:/;
}
close MAILGATE;
close $fh;
unlink $filename;
return $id;

}

my $queue = “general”;
my $from = “pere@hungry.com”;
my $subject = “testing testing”;
my $body = “testing more”;
my $id = new_ticket($queue, $from, $subject, $body);
print “ID: $id\n”;
exit 0;

Petter Reinholdtsen wrote:

I found a thread from 2001 giving an example, and have implemented
this.
URL:http://lists.bestpractical.com/pipermail/rt-devel/2001-April/001108.html.
Is this still the best way to do this?

Jesse’s anwer to that post already hints at a better way to do this now.

The script I have at the moment work, but it seem rather crude to call
rt-mailgate in debug mode just to get the ticket-ID out. Is there no
simpler way? Perhaps rt-mailgate should get some extra functionality
to allow it to print the ticket-ID to stdout on request?

If you’re already calling a perl script, you don’t have to call
rt-mailgate from it. There are some examples in the wiki
(Request Tracker Wiki), but none is
creating a ticket. The simplest one is for creating a user, see
download.bestpractical.com/pub/rt/contrib/ gone
To create a ticket you basically replace RT::User with RT::Ticket and
use some different arguments with Create. If you need more help, just ask.

Rolf.