2 # Copyright (c) 2005-2008 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 Mathlida 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);
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 {
68 $self->sendmail("pre-dle-amcheck");
71 sub command_pre_host_amcheck {
73 $self->sendmail("pre-host-amcheck");
76 sub command_post_dle_amcheck {
78 $self->sendmail("post-dle-amcheck");
81 sub command_post_host_amcheck {
83 $self->sendmail("post-host-amcheck");
86 sub command_pre_dle_estimate {
88 $self->sendmail("pre-dle-estimate");
91 sub command_pre_host_estimate {
93 $self->sendmail("pre-host-estimate");
96 sub command_post_dle_estimate {
98 $self->sendmail("post-dle-estimate");
101 sub command_post_host_estimate {
103 $self->sendmail("post-host-estimate");
106 sub command_pre_dle_backup {
108 $self->sendmail("pre-dle-backup");
111 sub command_pre_host_backup {
113 $self->sendmail("pre-host-backup");
116 sub command_post_dle_backup {
118 $self->sendmail("post-dle-backup");
121 sub command_post_host_backup {
123 $self->sendmail("post-host-backup");
126 sub command_pre_recover {
128 $self->sendmail("pre-recover");
131 sub command_post_recover {
133 $self->sendmail("post-recover");
136 sub command_pre_level_recover {
138 $self->sendmail("pre-level-recover");
141 sub command_post_level_recover {
143 $self->sendmail("post-level-recover");
146 sub command_inter_level_recover {
148 $self->sendmail("inter-level-recover");
155 if ($self->{mailto}) {
156 my $destcheck = join ',', @{$self->{mailto}};
157 $destcheck =~ /^([a-zA-Z,]*)$/;
162 my @args = ( "-s", "$self->{config} $function $self->{host} $self->{disk} $self->{device} " . join (" ", @{$self->{level}}), $dest );
163 my $args = join(" ", @args);
164 debug("cmd: $Amanda::Constants::MAILER $args\n");
166 open $mail, '|-', $Amanda::Constants::MAILER, @args;
167 print $mail "$self->{config} $function $self->{host} $self->{disk} $self->{device} ", join (" ", @{$self->{level}}), "\n";
175 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>.
180 my $opt_execute_where;
192 Getopt::Long::Configure(qw{bundling});
194 'execute-where=s' => \$opt_execute_where,
195 'config=s' => \$opt_config,
196 'host=s' => \$opt_host,
197 'disk=s' => \$opt_disk,
198 'device=s' => \$opt_device,
199 'level=s' => \@opt_level,
200 'index=s' => \$opt_index,
201 'message=s' => \$opt_message,
202 'collection=s' => \$opt_collection,
203 'record=s' => \$opt_record,
204 'mailto=s' => \@opt_mailto
207 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);
209 $script->do($ARGV[0]);