Added path for rt-perl-modules for some scripts
[usit-rt.git] / sbin / rt-email-dashboards
CommitLineData
84fb5b46
MKG
1#!/usr/bin/perl
2# BEGIN BPS TAGGED BLOCK {{{
3#
4# COPYRIGHT:
5#
6# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
7# <sales@bestpractical.com>
8#
9# (Except where explicitly superseded by other copyright notices)
10#
11#
12# LICENSE:
13#
14# This work is made available to you under the terms of Version 2 of
15# the GNU General Public License. A copy of that license should have
16# been provided with this software, but in any event can be snarfed
17# from www.gnu.org.
18#
19# This work is distributed in the hope that it will be useful, but
20# WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22# General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27# 02110-1301 or visit their web page on the internet at
28# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
29#
30#
31# CONTRIBUTION SUBMISSION POLICY:
32#
33# (The following paragraph is not intended to limit the rights granted
34# to you to modify and distribute this software under the terms of
35# the GNU General Public License and is only of importance to you if
36# you choose to contribute your changes and enhancements to the
37# community by submitting them to Best Practical Solutions, LLC.)
38#
39# By intentionally submitting any modifications, corrections or
40# derivatives to this work, or any other work intended for use with
41# Request Tracker, to Best Practical Solutions, LLC, you confirm that
42# you are the copyright holder for those contributions and you grant
43# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44# royalty-free, perpetual, license to use, copy, create derivative
45# works based on those contributions, and sublicense and distribute
46# those contributions and any derivatives thereof.
47#
48# END BPS TAGGED BLOCK }}}
49use strict;
50use warnings;
51
78afc2cf
MKG
52use lib '/www/data/rt/rt-perl/current-perl10/share/perl5';
53use lib '/www/data/rt/rt-perl/current-perl10/lib/perl5';
54use lib '/www/data/rt/rt-perl/current-perl10/lib64/perl5';
55
84fb5b46
MKG
56# fix lib paths, some may be relative
57BEGIN {
58 require File::Spec;
59 my @libs = ("lib", "local/lib");
60 my $bin_path;
61
62 for my $lib (@libs) {
63 unless ( File::Spec->file_name_is_absolute($lib) ) {
64 unless ($bin_path) {
65 if ( File::Spec->file_name_is_absolute(__FILE__) ) {
66 $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
67 }
68 else {
69 require FindBin;
70 no warnings "once";
71 $bin_path = $FindBin::Bin;
72 }
73 }
74 $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
75 }
76 unshift @INC, $lib;
77 }
78
79}
80
81# Read in the options
82my %opts;
83use Getopt::Long;
84GetOptions( \%opts,
85 "help|h", "dryrun", "time=i", "epoch=i", "all"
86);
87
88if ($opts{'help'}) {
89 require Pod::Usage;
90 print Pod::Usage::pod2usage(-verbose => 2);
91 exit;
92}
93
94require RT;
95require RT::Interface::CLI;
96RT::Interface::CLI->import(qw{ CleanEnv loc });
97
98# Clean out all the nasties from the environment
99CleanEnv();
100
101# Load the config file
102RT::LoadConfig();
103
104# Connect to the database and get RT::SystemUser and RT::Nobody loaded
105RT::Init();
106
107require RT::Dashboard::Mailer;
108RT::Dashboard::Mailer->MailDashboards(
109 All => $opts{all},
110 DryRun => $opts{dryrun},
111 Time => ($opts{time} || $opts{epoch} || time), # epoch is the old-style
112 Opts => \%opts,
113);
114
115=head1 NAME
116
117rt-email-dashboards - Send email dashboards
118
119=head1 SYNOPSIS
120
121 rt-email-dashboards [options]
122
123=head1 DESCRIPTION
124
125This tool will send users email based on how they have subscribed to
126dashboards. A dashboard is a set of saved searches, the subscription controls
127how often that dashboard is sent and how it's displayed.
128
129Each subscription has an hour, and possibly day of week or day of month. These
130are taken to be in the user's timezone if available, UTC otherwise.
131
132=head1 SETUP
133
134You'll need to have cron run this script every hour. Here's an example crontab
135entry to do this.
136
137 0 * * * * /usr/bin/perl /opt/rt4/local/sbin/rt-email-dashboards
138
139This will run the script every hour on the hour. This may need some further
140tweaking to be run as the correct user.
141
142=head1 OPTIONS
143
144This tool supports a few options. Most are for debugging.
145
146=over 8
147
148=item -h
149
150=item --help
151
152Display this documentation
153
154=item --dryrun
155
156Figure out which dashboards would be sent, but don't actually generate or email
157any of them
158
159=item --time SECONDS
160
161Instead of using the current time to figure out which dashboards should be
162sent, use SECONDS (usually since midnight Jan 1st, 1970, so C<1192216018> would
163be Oct 12 19:06:58 GMT 2007).
164
165=item --epoch SECONDS
166
167Back-compat for --time SECONDS.
168
169=item --all
170
171Ignore subscription frequency when considering each dashboard (should only be
172used with --dryrun for testing and debugging)
173
174=back
175
176=cut
177