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@';
27 package Amanda::Script::amlog_script;
28 use base qw(Amanda::Script);
29 use Amanda::Config qw( :getconf :init );
30 use Amanda::Debug qw( :logging );
31 use Amanda::Util qw( :constants );
33 use Amanda::Constants;
38 my ($execute_where, $config, $host, $disk, $device, $level, $index, $message, $collection, $record, $logfile, $text) = @_;
39 my $self = $class->SUPER::new($execute_where, $config);
41 $self->{execute_where} = $execute_where;
42 $self->{config} = $config;
43 $self->{host} = $host;
44 $self->{disk} = $disk;
45 $self->{device} = $device;
46 $self->{level} = [ @{$level} ]; # Copy the array
47 $self->{index} = $index;
48 $self->{message} = $message;
49 $self->{collection} = $collection;
50 $self->{record} = $record;
51 $self->{logfile} = $logfile;
52 $self->{text} = $text;
60 if (!defined $self->{logfile}) {
61 $self->print_to_server_and_die("property LOGFILE not set",
62 $Amanda::Script_App::ERROR);
65 my $dirname = File::Basename::dirname($self->{logfile});
67 $self->print_to_server_and_die("Directory '$dirname' doesn't exist",
68 $Amanda::Script_App::ERROR);
71 $self->print_to_server_and_die(
72 "Directory '$dirname' is not a directory",i
73 $Amanda::Script_App::ERROR);
83 print "MESSAGE-LINE YES\n";
84 print "MESSAGE-XML NO\n";
85 print "EXECUTE-WHERE YES\n";
88 #define a execute_on_* function for every execute_on you want the script to do
90 sub command_pre_amcheck {
94 $self->log_data("pre-amcheck");
97 sub command_pre_dle_amcheck {
101 $self->log_data("pre-dle-amcheck");
104 sub command_pre_host_amcheck {
108 $self->log_data("pre-host-amcheck");
111 sub command_post_amcheck {
115 $self->log_data("post-amcheck");
118 sub command_post_dle_amcheck {
122 $self->log_data("post-dle-amcheck");
125 sub command_post_host_amcheck {
129 $self->log_data("post-host-amcheck");
132 sub command_pre_estimate {
136 $self->log_data("pre-estimate");
139 sub command_pre_dle_estimate {
143 $self->log_data("pre-dle-estimate");
146 sub command_pre_host_estimate {
150 $self->log_data("pre-host-estimate");
153 sub command_post_estimate {
157 $self->log_data("post-estimate");
160 sub command_post_dle_estimate {
164 $self->log_data("post-dle-estimate");
167 sub command_post_host_estimate {
171 $self->log_data("post-host-estimate");
174 sub command_pre_backup {
178 $self->log_data("pre-backup");
181 sub command_pre_dle_backup {
185 $self->log_data("pre-dle-backup");
188 sub command_pre_host_backup {
192 $self->log_data("pre-host-backup");
195 sub command_post_backup {
199 $self->log_data("post-backup");
202 sub command_post_dle_backup {
206 $self->log_data("post-dle-backup");
209 sub command_post_host_backup {
213 $self->log_data("post-host-backup");
216 sub command_pre_recover {
220 $self->log_data("pre-recover");
223 sub command_post_recover {
227 $self->log_data("post-recover");
230 sub command_pre_level_recover {
234 $self->log_data("pre-level-recover");
237 sub command_post_level_recover {
241 $self->log_data("post-level-recover");
244 sub command_inter_level_recover {
248 $self->log_data("inter-level-recover");
253 my($function) = shift;
256 my $text = $self->{'text'} || "";
257 open($log, ">>$self->{logfile}") ||
258 $self->print_to_server_and_die(
259 "Can't open logfile '$self->{logfile}' for append: $!",
260 $Amanda::Script_App::ERROR);
261 print $log "$self->{action} $self->{config} $function $self->{execute_where} $self->{host} $self->{disk} $self->{device} ", join (" ", @{$self->{level}}), " $text\n";
269 Usage: amlog-script <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> --logfile=<filename>.
274 my $opt_execute_where;
287 Getopt::Long::Configure(qw{bundling});
289 'execute-where=s' => \$opt_execute_where,
290 'config=s' => \$opt_config,
291 'host=s' => \$opt_host,
292 'disk=s' => \$opt_disk,
293 'device=s' => \$opt_device,
294 'level=s' => \@opt_level,
295 'index=s' => \$opt_index,
296 'message=s' => \$opt_message,
297 'collection=s' => \$opt_collection,
298 'record=s' => \$opt_record,
299 'logfile=s' => \$opt_logfile,
300 'text=s' => \$opt_text
303 my $script = Amanda::Script::amlog_script->new($opt_execute_where, $opt_config, $opt_host, $opt_disk, $opt_device, \@opt_level, $opt_index, $opt_message, $opt_collection, $opt_record, $opt_logfile, $opt_text);
305 $script->do($ARGV[0]);