From 388b2853b26444acf333efd0cc0a96736020da4d Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Wed, 8 Jul 2009 18:25:12 +0000 Subject: [PATCH] add a script to add watchers to queues, since this is not part of the included rt-setup-database command. add @Watchers data to conf.d/planetlab.pl --- addwatchers.pl | 143 ++++++++++++++++++++++++++++++++++++++++++++ conf.d/planetlab.pl | 21 +++++++ 2 files changed, 164 insertions(+) create mode 100755 addwatchers.pl diff --git a/addwatchers.pl b/addwatchers.pl new file mode 100755 index 0000000..d9ffa93 --- /dev/null +++ b/addwatchers.pl @@ -0,0 +1,143 @@ +#!/usr/bin/perl -w +use strict; +use vars qw($PROMPT $VERSION $Handle $Nobody $SystemUser $item); +use vars + qw(@Groups @Users @ACL @Queues @Watchers @ScripActions @ScripConditions @Templates @CustomFields @Scrips @Attributes); + +use lib "/usr/local/lib/rt3/lib"; +use lib "/usr/lib/perl5/vendor_perl/5.8.8"; + +#This drags in RT's config.pm +# We do it in a begin block because RT::Handle needs to know the type to do its +# inheritance +use RT; +use Carp; +use RT::User; +use RT::CurrentUser; +use RT::Template; +use RT::ScripAction; +use RT::ACE; +use RT::Group; +use RT::User; +use RT::Queue; +use RT::ScripCondition; +use RT::CustomField; +use RT::Scrip; + +RT::LoadConfig(); +use Term::ReadKey; +use Getopt::Long; + +my %args; + +GetOptions( + \%args, + 'prompt-for-dba-password', 'force', 'debug', + 'action=s', 'dba=s', 'dba-password=s', 'datafile=s', + 'datadir=s' +); + +unless ( $args{'action'} ) { + help(); + exit(-1); +} + +$| = 1; #unbuffer that output. + +require RT::Handle; +my $Handle = RT::Handle->new($RT::DatabaseType); +$Handle->BuildDSN; +my $dbh; + +if ( $args{'prompt-for-dba-password'} ) { + $args{'dba-password'} = get_dba_password(); + chomp( $args{'dba-password'} ); +} + +if ( $args{'action'} eq 'insert' ) { + insert_data( $args{'datafile'} || ($args{'datadir'}."/content") ); +} +else { + print STDERR "$0 called with an invalid --action parameter\n"; + exit(-1); +} + +sub insert_data { + my $datafile = shift; + + #Connect to the database and get RT::SystemUser and RT::Nobody loaded + RT::Init; + + my $CurrentUser = RT::CurrentUser->new(); + $CurrentUser->LoadByName('RT_System'); + + # Slurp in stuff to insert from the datafile. Possible things to go in here:- + # @groups, @users, @acl, @queues, @ScripActions, @ScripConditions, @templates + + print "LBLALDLJDLDKJ " . "\n"; + print $datafile . "\n"; + + require $datafile + || die "Couldn't find initial data for import\n" . $@; + + if ( @Watchers ) { + print "Creating Watchers..."; + for $item (@Watchers) { + my $queue_entry = new RT::Queue($CurrentUser); + my $watchers = $item->{'Watchers'}; + delete $item->{'Watchers'}; + my ( $return, $msg ) = $queue_entry->Load($item->{'Queue'}); + + print "TEST---\n"; + print $return. " ". $msg . "\n"; + foreach my $watcher ( @{$watchers} ) { + my ( $eval, $emsg ) = $queue_entry->AddWatcher(%$watcher); + print "(Error: $emsg)\n" unless $eval; + } + + print "(Error: $msg)" unless $return; + print $return. "."; + } + print "done.\n"; + } + $RT::Handle->Disconnect() unless $RT::DatabaseType eq 'SQLite'; + print "Done setting up database content.\n"; +} + +sub help { + + print < 'Support Watch List', + Gecos => 'support watch list', + RealName => 'supportwatchlist', + Password => '', + EmailAddress => 'PLC_RT_CC_ADDRESS', + Comments => '', + Privileged => '1', } ); + +# These addresses all use the same email but it can easily be changed within RT +@Watchers = ( + { Queue => 'support', + Watchers => [ {Email => 'PLC_RT_CC_ADDRESS', Type => 'AdminCC',} ] }, + { Queue => 'monitor', + Watchers => [ {Email => 'PLC_RT_CC_ADDRESS', Type => 'AdminCC',} ] }, + { Queue => 'legal', + Watchers => [ {Email => 'PLC_RT_CC_ADDRESS', Type => 'AdminCC',} ] }, + { Queue => 'security', + Watchers => [ {Email => 'PLC_RT_CC_ADDRESS', Type => 'AdminCC',} ] }, +); + @ACL = ( { GroupDomain => 'SystemInternal', GroupType => 'Everyone', -- 2.43.0