2 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 use lib '@amperldir@';
26 package Amanda::Script::Script_email;
27 use base qw(Amanda::Script);
28 use Amanda::Config qw( :getconf :init );
29 use Amanda::Debug qw( :logging );
30 use Amanda::Util qw( :constants );
32 use Amanda::Constants;
37 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $mailto) = @_;
38 my $self = $class->SUPER::new($execute_where, $config);
40 $self->{execute_where} = $execute_where;
41 $self->{config} = $config;
42 $self->{host} = $host;
43 $self->{disk} = $disk;
44 $self->{device} = $device;
45 $self->{level} = [ @{$level} ]; # Copy the array
46 $self->{index} = $index;
47 $self->{message} = $message;
48 $self->{collection} = $collection;
49 $self->{record} = $record;
50 $self->{mailto} = [ @{$mailto} ]; # Copy the array
61 print "MESSAGE-LINE YES\n";
62 print "MESSAGE-XML NO\n";
63 print "EXECUTE-WHERE YES\n";
66 #define a execute_on_* function for every execute_on you want the script to do
68 sub command_pre_dle_amcheck {
71 $self->sendmail("pre-dle-amcheck");
74 sub command_pre_host_amcheck {
77 $self->sendmail("pre-host-amcheck");
80 sub command_post_dle_amcheck {
83 $self->sendmail("post-dle-amcheck");
86 sub command_post_host_amcheck {
89 $self->sendmail("post-host-amcheck");
92 sub command_pre_dle_estimate {
95 $self->sendmail("pre-dle-estimate");
98 sub command_pre_host_estimate {
101 $self->sendmail("pre-host-estimate");
104 sub command_post_dle_estimate {
107 $self->sendmail("post-dle-estimate");
110 sub command_post_host_estimate {
113 $self->sendmail("post-host-estimate");
116 sub command_pre_dle_backup {
119 $self->sendmail("pre-dle-backup");
122 sub command_pre_host_backup {
125 $self->sendmail("pre-host-backup");
128 sub command_post_dle_backup {
131 $self->sendmail("post-dle-backup");
134 sub command_post_host_backup {
137 $self->sendmail("post-host-backup");
140 sub command_pre_recover {
143 $self->sendmail("pre-recover");
146 sub command_post_recover {
149 $self->sendmail("post-recover");
152 sub command_pre_level_recover {
155 $self->sendmail("pre-level-recover");
158 sub command_post_level_recover {
161 $self->sendmail("post-level-recover");
164 sub command_inter_level_recover {
167 $self->sendmail("inter-level-recover");
174 if ($self->{mailto}) {
175 my $destcheck = join ',', @{$self->{mailto}};
176 $destcheck =~ /^([a-zA-Z,]*)$/;
181 my @args = ( "-s", "$self->{config} $function $self->{host} $self->{disk} $self->{device} " . join (" ", @{$self->{level}}), $dest );
182 my $args = join(" ", @args);
183 debug("cmd: $Amanda::Constants::MAILER $args\n");
185 open $mail, '|-', $Amanda::Constants::MAILER, @args;
186 print $mail "$self->{action} $self->{config} $function $self->{host} $self->{disk} $self->{device} ", join (" ", @{$self->{level}}), "\n";
194 Usage: script-email <command> --execute-where=<client|server> --config=<config> --host=<host> --disk=<disk> --device=<device> --level=<level> --index=<yes|no> --message=<text> --collection=<no> --record=<yes|no> --mailto=<email>.
199 my $opt_execute_where;
211 Getopt::Long::Configure(qw{bundling});
213 'execute-where=s' => \$opt_execute_where,
214 'config=s' => \$opt_config,
215 'host=s' => \$opt_host,
216 'disk=s' => \$opt_disk,
217 'device=s' => \$opt_device,
218 'level=s' => \@opt_level,
219 'index=s' => \$opt_index,
220 'message=s' => \$opt_message,
221 'collection=s' => \$opt_collection,
222 'record=s' => \$opt_record,
223 'mailto=s' => \@opt_mailto
226 my $script = Amanda::Script::Script_email->new($opt_execute_where, $opt_config, $opt_host, $opt_disk, $opt_device, \@opt_level, $opt_index, $opt_message, $opt_collection, $opt_record, \@opt_mailto);
228 $script->do($ARGV[0]);