2 # Copyright (c) 2008, 2009, 2010 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@';
25 package Amanda::Script::Script_email;
26 use base qw(Amanda::Script);
27 use Amanda::Config qw( :getconf :init );
28 use Amanda::Debug qw( :logging );
29 use Amanda::Util qw( :constants );
31 use Amanda::Constants;
36 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $mailto) = @_;
37 my $self = $class->SUPER::new($execute_where, $config);
39 $self->{execute_where} = $execute_where;
40 $self->{config} = $config;
41 $self->{host} = $host;
42 $self->{disk} = $disk;
43 $self->{device} = $device;
44 $self->{level} = [ @{$level} ]; # Copy the array
45 $self->{index} = $index;
46 $self->{message} = $message;
47 $self->{collection} = $collection;
48 $self->{record} = $record;
49 $self->{mailto} = [ @{$mailto} ]; # Copy the array
60 print "MESSAGE-LINE YES\n";
61 print "MESSAGE-XML NO\n";
62 print "EXECUTE-WHERE YES\n";
65 #define a execute_on_* function for every execute_on you want the script to do
67 sub command_pre_dle_amcheck {
70 $self->sendmail("pre-dle-amcheck");
73 sub command_pre_host_amcheck {
76 $self->sendmail("pre-host-amcheck");
79 sub command_post_dle_amcheck {
82 $self->sendmail("post-dle-amcheck");
85 sub command_post_host_amcheck {
88 $self->sendmail("post-host-amcheck");
91 sub command_pre_dle_estimate {
94 $self->sendmail("pre-dle-estimate");
97 sub command_pre_host_estimate {
100 $self->sendmail("pre-host-estimate");
103 sub command_post_dle_estimate {
106 $self->sendmail("post-dle-estimate");
109 sub command_post_host_estimate {
112 $self->sendmail("post-host-estimate");
115 sub command_pre_dle_backup {
118 $self->sendmail("pre-dle-backup");
121 sub command_pre_host_backup {
124 $self->sendmail("pre-host-backup");
127 sub command_post_dle_backup {
130 $self->sendmail("post-dle-backup");
133 sub command_post_host_backup {
136 $self->sendmail("post-host-backup");
139 sub command_pre_recover {
142 $self->sendmail("pre-recover");
145 sub command_post_recover {
148 $self->sendmail("post-recover");
151 sub command_pre_level_recover {
154 $self->sendmail("pre-level-recover");
157 sub command_post_level_recover {
160 $self->sendmail("post-level-recover");
163 sub command_inter_level_recover {
166 $self->sendmail("inter-level-recover");
173 if ($self->{mailto}) {
174 my $destcheck = join ',', @{$self->{mailto}};
175 $destcheck =~ /^([a-zA-Z,]*)$/;
180 my @args = ( "-s", "$self->{config} $function $self->{host} $self->{disk} $self->{device} " . join (" ", @{$self->{level}}), $dest );
181 my $args = join(" ", @args);
182 debug("cmd: $Amanda::Constants::MAILER $args\n");
184 open $mail, '|-', $Amanda::Constants::MAILER, @args;
185 print $mail "$self->{action} $self->{config} $function $self->{host} $self->{disk} $self->{device} ", join (" ", @{$self->{level}}), "\n";
193 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>.
198 my $opt_execute_where;
210 Getopt::Long::Configure(qw{bundling});
212 'execute-where=s' => \$opt_execute_where,
213 'config=s' => \$opt_config,
214 'host=s' => \$opt_host,
215 'disk=s' => \$opt_disk,
216 'device=s' => \$opt_device,
217 'level=s' => \@opt_level,
218 'index=s' => \$opt_index,
219 'message=s' => \$opt_message,
220 'collection=s' => \$opt_collection,
221 'record=s' => \$opt_record,
222 'mailto=s' => \@opt_mailto
225 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);
227 $script->do($ARGV[0]);