2 # Copyright (c) 2008,2009 Zmanda, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use lib '@amperldir@';
24 package Amanda::Script::Script_email;
25 use base qw(Amanda::Script);
26 use Amanda::Config qw( :getconf :init );
27 use Amanda::Debug qw( :logging );
28 use Amanda::Util qw( :constants );
30 use Amanda::Constants;
35 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $mailto) = @_;
36 my $self = $class->SUPER::new($execute_where, $config);
38 $self->{execute_where} = $execute_where;
39 $self->{config} = $config;
40 $self->{host} = $host;
41 $self->{disk} = $disk;
42 $self->{device} = $device;
43 $self->{level} = [ @{$level} ]; # Copy the array
44 $self->{index} = $index;
45 $self->{message} = $message;
46 $self->{collection} = $collection;
47 $self->{record} = $record;
48 $self->{mailto} = [ @{$mailto} ]; # Copy the array
59 print "MESSAGE-LINE YES\n";
60 print "MESSAGE-XML NO\n";
61 print "EXECUTE-WHERE YES\n";
64 #define a execute_on_* function for every execute_on you want the script to do
66 sub command_pre_dle_amcheck {
69 $self->sendmail("pre-dle-amcheck");
72 sub command_pre_host_amcheck {
75 $self->sendmail("pre-host-amcheck");
78 sub command_post_dle_amcheck {
81 $self->sendmail("post-dle-amcheck");
84 sub command_post_host_amcheck {
87 $self->sendmail("post-host-amcheck");
90 sub command_pre_dle_estimate {
93 $self->sendmail("pre-dle-estimate");
96 sub command_pre_host_estimate {
99 $self->sendmail("pre-host-estimate");
102 sub command_post_dle_estimate {
105 $self->sendmail("post-dle-estimate");
108 sub command_post_host_estimate {
111 $self->sendmail("post-host-estimate");
114 sub command_pre_dle_backup {
117 $self->sendmail("pre-dle-backup");
120 sub command_pre_host_backup {
123 $self->sendmail("pre-host-backup");
126 sub command_post_dle_backup {
129 $self->sendmail("post-dle-backup");
132 sub command_post_host_backup {
135 $self->sendmail("post-host-backup");
138 sub command_pre_recover {
141 $self->sendmail("pre-recover");
144 sub command_post_recover {
147 $self->sendmail("post-recover");
150 sub command_pre_level_recover {
153 $self->sendmail("pre-level-recover");
156 sub command_post_level_recover {
159 $self->sendmail("post-level-recover");
162 sub command_inter_level_recover {
165 $self->sendmail("inter-level-recover");
172 if ($self->{mailto}) {
173 my $destcheck = join ',', @{$self->{mailto}};
174 $destcheck =~ /^([a-zA-Z,]*)$/;
179 my @args = ( "-s", "$self->{config} $function $self->{host} $self->{disk} $self->{device} " . join (" ", @{$self->{level}}), $dest );
180 my $args = join(" ", @args);
181 debug("cmd: $Amanda::Constants::MAILER $args\n");
183 open $mail, '|-', $Amanda::Constants::MAILER, @args;
184 print $mail "$self->{action} $self->{config} $function $self->{host} $self->{disk} $self->{device} ", join (" ", @{$self->{level}}), "\n";
192 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>.
197 my $opt_execute_where;
209 Getopt::Long::Configure(qw{bundling});
211 'execute-where=s' => \$opt_execute_where,
212 'config=s' => \$opt_config,
213 'host=s' => \$opt_host,
214 'disk=s' => \$opt_disk,
215 'device=s' => \$opt_device,
216 'level=s' => \@opt_level,
217 'index=s' => \$opt_index,
218 'message=s' => \$opt_message,
219 'collection=s' => \$opt_collection,
220 'record=s' => \$opt_record,
221 'mailto=s' => \@opt_mailto
224 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);
226 $script->do($ARGV[0]);