#!/usr/bin/perl -w # # getrttix - List RT tickets matching search criteria # # 2004-Apr-03 James A. Hickstein jxh@imap-partners.net # # $Id: getrttix,v 1.1 2004/12/14 04:01:41 jxh Exp $ # # $Log: getrttix,v $ # Revision 1.1 2004/12/14 04:01:41 jxh # Make rttix send URLs. Hats off to Henry for this idea. # # Synopsis: # # getrttix [-q queue] [-o owner] [-s status] [-c hours] # # Matching criteria: # in queue, or "support" if not specified; # given status, or "new" if not specified; # belonging to "owner", or all owners if not specified; # with creation "hours" or more in the past. # Based on: # $Header: /home/CVS/Scripts/getrttix,v 1.1 2004/12/14 04:01:41 jxh Exp $ # RT is (c) 1996-2001 Jesse Vincent use strict; use Carp; use Getopt::Std; use lib "/opt/rt2/lib"; use lib "/opt/rt2/etc"; use RT::Interface::CLI qw(CleanEnv LoadConfig DBConnect GetCurrentUser GetMessageContent); sub Usage { print STDERR "$0: [-q queue] [-o owner] [-s status] [-c hours]\n"; exit 1; } sub Url { my ( $ticketid ) = shift; return 'https://k.imap-partners.net/support/Ticket/Display.html?id=' . $ticketid; } my %opt; getopts("hq:o:s:c:", \%opt); # set defaults $opt{'q'} = 'support' unless $opt{'q'}; $opt{'s'} = 'new' unless $opt{'s'}; if ( $opt{'h'} or scalar @ARGV ) { Usage(); } #Clean out all the nasties from the environment CleanEnv(); #Load etc/config.pm and drop privs LoadConfig(); #Connect to the database and get RT::SystemUser and RT::Nobody loaded DBConnect(); use RT::Date; use RT::Queue; use RT::Tickets; my $queue = new RT::Queue($RT::SystemUser); $queue->Load($opt{'q'}); my $now = new RT::Date($RT::SystemUser); $now->SetToNow(); my $tickets = new RT::Tickets($RT::SystemUser); #$tickets->LimitStatus(VALUE => 'open'); $tickets->LimitStatus(VALUE => $opt{'s'}); $tickets->LimitQueue(VALUE => $queue->Id); $tickets->LimitOwner(VALUE => $opt{'o'}) if $opt{'o'}; $tickets->OrderBy(FIELD => 'Id'); while (my $Ticket = $tickets->Next) { my $age = ($^T - $Ticket->CreatedObj->Unix) / 3600; if ( $opt{'c'} ) { if ( $age < $opt{'c'} ) { next; } } printf("%s %d %s %s (%dh)\n%s\n%s\n\n", $Ticket->OwnerObj->Name, $Ticket->Id, $Ticket->Status, $Ticket->CreatedObj->AsString, $age, $Ticket->Subject, Url( $Ticket->Id ) ); } $RT::Handle->Disconnect();