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@';
25 package Amanda::Script::amlog_script;
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, $logfile, $text) = @_;
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->{logfile} = $logfile;
50 $self->{text} = $text;
58 if (!defined $self->{logfile}) {
59 $self->print_to_server_and_die("property LOGFILE not set",
60 $Amanda::Script_App::ERROR);
63 my $dirname = File::Basename::dirname($self->{logfile});
65 $self->print_to_server_and_die("Directory '$dirname' doesn't exist",
66 $Amanda::Script_App::ERROR);
69 $self->print_to_server_and_die(
70 "Directory '$dirname' is not a directory",i
71 $Amanda::Script_App::ERROR);
81 print "MESSAGE-LINE YES\n";
82 print "MESSAGE-XML NO\n";
83 print "EXECUTE-WHERE YES\n";
86 #define a execute_on_* function for every execute_on you want the script to do
88 sub command_pre_dle_amcheck {
92 $self->log_data("pre-dle-amcheck");
95 sub command_pre_host_amcheck {
99 $self->log_data("pre-host-amcheck");
102 sub command_post_dle_amcheck {
106 $self->log_data("post-dle-amcheck");
109 sub command_post_host_amcheck {
113 $self->log_data("post-host-amcheck");
116 sub command_pre_dle_estimate {
120 $self->log_data("pre-dle-estimate");
123 sub command_pre_host_estimate {
127 $self->log_data("pre-host-estimate");
130 sub command_post_dle_estimate {
134 $self->log_data("post-dle-estimate");
137 sub command_post_host_estimate {
141 $self->log_data("post-host-estimate");
144 sub command_pre_dle_backup {
148 $self->log_data("pre-dle-backup");
151 sub command_pre_host_backup {
155 $self->log_data("pre-host-backup");
158 sub command_post_dle_backup {
162 $self->log_data("post-dle-backup");
165 sub command_post_host_backup {
169 $self->log_data("post-host-backup");
172 sub command_pre_recover {
176 $self->log_data("pre-recover");
179 sub command_post_recover {
183 $self->log_data("post-recover");
186 sub command_pre_level_recover {
190 $self->log_data("pre-level-recover");
193 sub command_post_level_recover {
197 $self->log_data("post-level-recover");
200 sub command_inter_level_recover {
204 $self->log_data("inter-level-recover");
209 my($function) = shift;
212 open($log, ">>$self->{logfile}") ||
213 $self->print_to_server_and_die(
214 "Can't open logfile '$self->{logfile}' for append: $!",
215 $Amanda::Script_App::ERROR);
216 print $log "$self->{action} $self->{config} $function $self->{execute_where} $self->{host} $self->{disk} $self->{device} ", join (" ", @{$self->{level}}), " $self->{text}\n";
224 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>.
229 my $opt_execute_where;
242 Getopt::Long::Configure(qw{bundling});
244 'execute-where=s' => \$opt_execute_where,
245 'config=s' => \$opt_config,
246 'host=s' => \$opt_host,
247 'disk=s' => \$opt_disk,
248 'device=s' => \$opt_device,
249 'level=s' => \@opt_level,
250 'index=s' => \$opt_index,
251 'message=s' => \$opt_message,
252 'collection=s' => \$opt_collection,
253 'record=s' => \$opt_record,
254 'logfile=s' => \$opt_logfile,
255 'text=s' => \$opt_text
258 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);
260 $script->do($ARGV[0]);