Imported Upstream version 2.6.0
[debian/amanda] / perl / Amanda / Logfile.pm
1 # This file was automatically generated by SWIG (http://www.swig.org).
2 # Version 1.3.33
3 #
4 # Don't modify this file, modify the SWIG interface instead.
5
6 package Amanda::Logfile;
7 require Exporter;
8 require DynaLoader;
9 @ISA = qw(Exporter DynaLoader);
10 package Amanda::Logfilec;
11 bootstrap Amanda::Logfile;
12 package Amanda::Logfile;
13 @EXPORT = qw( );
14
15 # ---------- BASE METHODS -------------
16
17 package Amanda::Logfile;
18
19 sub TIEHASH {
20     my ($classname,$obj) = @_;
21     return bless $obj, $classname;
22 }
23
24 sub CLEAR { }
25
26 sub FIRSTKEY { }
27
28 sub NEXTKEY { }
29
30 sub FETCH {
31     my ($self,$field) = @_;
32     my $member_func = "swig_${field}_get";
33     $self->$member_func();
34 }
35
36 sub STORE {
37     my ($self,$field,$newval) = @_;
38     my $member_func = "swig_${field}_set";
39     $self->$member_func($newval);
40 }
41
42 sub this {
43     my $ptr = shift;
44     return tied(%$ptr);
45 }
46
47
48 # ------- FUNCTION WRAPPERS --------
49
50 package Amanda::Logfile;
51
52 *open_logfile = *Amanda::Logfilec::open_logfile;
53 *close_logfile = *Amanda::Logfilec::close_logfile;
54 *get_logline = *Amanda::Logfilec::get_logline;
55 *find_log = *Amanda::Logfilec::find_log;
56 *search_logfile = *Amanda::Logfilec::search_logfile;
57 *dumps_match = *Amanda::Logfilec::dumps_match;
58
59 ############# Class : Amanda::Logfile::find_result_t ##############
60
61 package Amanda::Logfile::find_result_t;
62 use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
63 @ISA = qw( Amanda::Logfile );
64 %OWNER = ();
65 %ITERATORS = ();
66 sub DESTROY {
67     return unless $_[0]->isa('HASH');
68     my $self = tied(%{$_[0]});
69     return unless defined $self;
70     delete $ITERATORS{$self};
71     if (exists $OWNER{$self}) {
72         Amanda::Logfilec::delete_find_result_t($self);
73         delete $OWNER{$self};
74     }
75 }
76
77 *swig_timestamp_get = *Amanda::Logfilec::find_result_t_timestamp_get;
78 *swig_timestamp_set = *Amanda::Logfilec::find_result_t_timestamp_set;
79 *swig_hostname_get = *Amanda::Logfilec::find_result_t_hostname_get;
80 *swig_hostname_set = *Amanda::Logfilec::find_result_t_hostname_set;
81 *swig_diskname_get = *Amanda::Logfilec::find_result_t_diskname_get;
82 *swig_diskname_set = *Amanda::Logfilec::find_result_t_diskname_set;
83 *swig_level_get = *Amanda::Logfilec::find_result_t_level_get;
84 *swig_level_set = *Amanda::Logfilec::find_result_t_level_set;
85 *swig_label_get = *Amanda::Logfilec::find_result_t_label_get;
86 *swig_label_set = *Amanda::Logfilec::find_result_t_label_set;
87 *swig_filenum_get = *Amanda::Logfilec::find_result_t_filenum_get;
88 *swig_filenum_set = *Amanda::Logfilec::find_result_t_filenum_set;
89 *swig_status_get = *Amanda::Logfilec::find_result_t_status_get;
90 *swig_status_set = *Amanda::Logfilec::find_result_t_status_set;
91 *swig_partnum_get = *Amanda::Logfilec::find_result_t_partnum_get;
92 *swig_partnum_set = *Amanda::Logfilec::find_result_t_partnum_set;
93 sub new {
94     my $pkg = shift;
95     my $self = Amanda::Logfilec::new_find_result_t(@_);
96     bless $self, $pkg if defined($self);
97 }
98
99 sub DISOWN {
100     my $self = shift;
101     my $ptr = tied(%$self);
102     delete $OWNER{$ptr};
103 }
104
105 sub ACQUIRE {
106     my $self = shift;
107     my $ptr = tied(%$self);
108     $OWNER{$ptr} = 1;
109 }
110
111
112 # ------- VARIABLE STUBS --------
113
114 package Amanda::Logfile;
115
116 *L_BOGUS = *Amanda::Logfilec::L_BOGUS;
117 *L_FATAL = *Amanda::Logfilec::L_FATAL;
118 *L_ERROR = *Amanda::Logfilec::L_ERROR;
119 *L_WARNING = *Amanda::Logfilec::L_WARNING;
120 *L_INFO = *Amanda::Logfilec::L_INFO;
121 *L_SUMMARY = *Amanda::Logfilec::L_SUMMARY;
122 *L_START = *Amanda::Logfilec::L_START;
123 *L_FINISH = *Amanda::Logfilec::L_FINISH;
124 *L_DISK = *Amanda::Logfilec::L_DISK;
125 *L_DONE = *Amanda::Logfilec::L_DONE;
126 *L_PART = *Amanda::Logfilec::L_PART;
127 *L_PARTPARTIAL = *Amanda::Logfilec::L_PARTPARTIAL;
128 *L_SUCCESS = *Amanda::Logfilec::L_SUCCESS;
129 *L_PARTIAL = *Amanda::Logfilec::L_PARTIAL;
130 *L_FAIL = *Amanda::Logfilec::L_FAIL;
131 *L_STRANGE = *Amanda::Logfilec::L_STRANGE;
132 *L_CHUNK = *Amanda::Logfilec::L_CHUNK;
133 *L_CHUNKSUCCESS = *Amanda::Logfilec::L_CHUNKSUCCESS;
134 *L_STATS = *Amanda::Logfilec::L_STATS;
135 *L_MARKER = *Amanda::Logfilec::L_MARKER;
136 *L_CONT = *Amanda::Logfilec::L_CONT;
137 *P_UNKNOWN = *Amanda::Logfilec::P_UNKNOWN;
138 *P_PLANNER = *Amanda::Logfilec::P_PLANNER;
139 *P_DRIVER = *Amanda::Logfilec::P_DRIVER;
140 *P_REPORTER = *Amanda::Logfilec::P_REPORTER;
141 *P_DUMPER = *Amanda::Logfilec::P_DUMPER;
142 *P_CHUNKER = *Amanda::Logfilec::P_CHUNKER;
143 *P_TAPER = *Amanda::Logfilec::P_TAPER;
144 *P_AMFLUSH = *Amanda::Logfilec::P_AMFLUSH;
145
146 @EXPORT_OK = ();
147 %EXPORT_TAGS = ();
148
149 =head1 NAME
150
151 Amanda::Logfile - manage Amanda trace logs
152
153 =head1 SYNOPSIS
154
155   use Amanda::Logfile qw(:logtype_t); # XXX change
156   use Amanda::Config qw( :getconf config_dir_relative );
157
158   for my $logfile (Amanda::Logfile::find_log()) {
159     $logfile = config_dir_relative(getconf($CNF_LOGDIR)) . "/" . $logfile;
160
161     my $hdl = Amanda::Logfile::open_logfile($logfile);
162     while (my ($type, $prog, $str) = Amanda::Logfile::get_logline($hdl)) {
163       if ($type == $L_INFO) {
164         my $pname = Amanda::Logfile::program_t_to_string($prog);
165         print "Found info line from $pname: $str\n";
166       }
167     }
168     Amanda::Logfile::close_logfile($log);
169
170     my @dumps = Amanda::Logfile::search_logfile("TapeLabel-001", "19780615", $logfile);
171
172     my @matching = Amanda::Logfile::dumps_match([@dumps], "myhost", "/usr", undef, undef, 0);
173     for my $dump (@matching) {
174       print "$dump->{'label'}:$dump->{'filenum'} = $dump->{'hostname'}:$dump->{'disk'}\n";
175     }
176   }
177
178 =head1 API STATUS
179
180 Stabilizing
181
182 =head1 RAW LOGFILE ACCESS
183
184 This section corresponds to the C C<logfile> module. 
185
186 Raw access to logfiles is accomplished by opening a logfile and
187 fetching log lines one by one via the C<get_logline> function.
188
189 A log line is represented by a list C<($type, $prog, $string)>
190 where C<$type> is one of the C<L_*> constants (available in export
191 tag C<logtype_t>), C<$prog> is one of the C<P_*> constants (available
192 in export tag C<program_t>), and C<$str> is the remainder of the line.
193
194 Both families of constants can be converted to symbolic names with
195 C<logtype_t_to_string> and C<program_t_to_string>, respectively.
196
197 =head2 FUNCTIONS
198
199 =over
200
201 =item C<open_logfile($filename)>
202
203 Opens a logfile for reading, returning an opaque log file handle.
204
205 =item C<close_logfile($handle)>
206
207 Closes a log file handle.
208
209 =item C<get_logline($handle)>
210
211 Return a list as described above representing the next log line in
212 C<$handle>, or nothing at the end of the logfile. 
213
214 =back
215
216 All of these functions can be imported by name if desired.
217
218 =head1 Amanda::Find::find_result_t objects
219
220 These objects contain information about dumps, as read from logfiles.
221 Instance variables are:
222
223 =over
224
225 =item C<$timestamp>
226
227 =item C<$hostname>
228
229 =item C<$diskname>
230
231 =item C<$level>
232
233 =item C<$label>
234
235 =item C<$filenum>
236
237 =item C<$status>
238
239 =item C<$partnum>
240
241 =back
242
243 =head1 HIGHER-LEVEL FUNCTIONS
244
245 Functions in this section extract information from logfiles.
246
247 =over
248
249 =item C<find_log()>
250
251 Return a list of logfiles for active tapes.  The tapelist must be loaded before
252 this function is called (see L<Amanda::Tapelist>).
253
254 =item C<search_logfile($label, $datestamp, $logfile, $add_missing_disks)>
255
256 Return all results in C<$logfile> matching C<$label> and C<$datestamp>.
257 If C<$add_missing_disks> is true, then any disks in the logfile
258 not present in the disklist are added to the disklist; otherwise,
259 such dumps are skipped.
260
261 =item C<dumps_match([@results], $hostname, $diskname, $datestamp, $level, $ok)>
262
263 Return a filtered version of C<@results> containing only results that match the 
264 given expressions.  If C<$ok> is true, don't match partial results.  Note that
265 C<$level> is given as a string, since it is a match expression.
266
267 All of these functions can be imported by name.
268
269 =cut
270
271 push @EXPORT_OK, qw(open_logfile get_logline close_logfile);
272
273 push @EXPORT_OK, qw(logtype_t_to_string);
274 push @{$EXPORT_TAGS{"logtype_t"}}, qw(logtype_t_to_string);
275
276 my %_logtype_t_VALUES;
277 #Convert an enum value to a single string
278 sub logtype_t_to_string {
279     my ($enumval) = @_;
280
281     for my $k (keys %_logtype_t_VALUES) {
282         my $v = $_logtype_t_VALUES{$k};
283
284         #is this a matching flag?
285         if ($enumval == $v) {
286             return $k;
287         }
288     }
289
290 #default, just return the number
291     return $enumval;
292 }
293
294 push @EXPORT_OK, qw($L_BOGUS);
295 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_BOGUS);
296
297 $_logtype_t_VALUES{"L_BOGUS"} = $L_BOGUS;
298
299 push @EXPORT_OK, qw($L_FATAL);
300 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_FATAL);
301
302 $_logtype_t_VALUES{"L_FATAL"} = $L_FATAL;
303
304 push @EXPORT_OK, qw($L_ERROR);
305 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_ERROR);
306
307 $_logtype_t_VALUES{"L_ERROR"} = $L_ERROR;
308
309 push @EXPORT_OK, qw($L_WARNING);
310 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_WARNING);
311
312 $_logtype_t_VALUES{"L_WARNING"} = $L_WARNING;
313
314 push @EXPORT_OK, qw($L_INFO);
315 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_INFO);
316
317 $_logtype_t_VALUES{"L_INFO"} = $L_INFO;
318
319 push @EXPORT_OK, qw($L_SUMMARY);
320 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_SUMMARY);
321
322 $_logtype_t_VALUES{"L_SUMMARY"} = $L_SUMMARY;
323
324 push @EXPORT_OK, qw($L_START);
325 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_START);
326
327 $_logtype_t_VALUES{"L_START"} = $L_START;
328
329 push @EXPORT_OK, qw($L_FINISH);
330 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_FINISH);
331
332 $_logtype_t_VALUES{"L_FINISH"} = $L_FINISH;
333
334 push @EXPORT_OK, qw($L_DISK);
335 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_DISK);
336
337 $_logtype_t_VALUES{"L_DISK"} = $L_DISK;
338
339 push @EXPORT_OK, qw($L_DONE);
340 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_DONE);
341
342 $_logtype_t_VALUES{"L_DONE"} = $L_DONE;
343
344 push @EXPORT_OK, qw($L_PART);
345 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_PART);
346
347 $_logtype_t_VALUES{"L_PART"} = $L_PART;
348
349 push @EXPORT_OK, qw($L_PARTPARTIAL);
350 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_PARTPARTIAL);
351
352 $_logtype_t_VALUES{"L_PARTPARTIAL"} = $L_PARTPARTIAL;
353
354 push @EXPORT_OK, qw($L_SUCCESS);
355 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_SUCCESS);
356
357 $_logtype_t_VALUES{"L_SUCCESS"} = $L_SUCCESS;
358
359 push @EXPORT_OK, qw($L_PARTIAL);
360 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_PARTIAL);
361
362 $_logtype_t_VALUES{"L_PARTIAL"} = $L_PARTIAL;
363
364 push @EXPORT_OK, qw($L_FAIL);
365 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_FAIL);
366
367 $_logtype_t_VALUES{"L_FAIL"} = $L_FAIL;
368
369 push @EXPORT_OK, qw($L_STRANGE);
370 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_STRANGE);
371
372 $_logtype_t_VALUES{"L_STRANGE"} = $L_STRANGE;
373
374 push @EXPORT_OK, qw($L_CHUNK);
375 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_CHUNK);
376
377 $_logtype_t_VALUES{"L_CHUNK"} = $L_CHUNK;
378
379 push @EXPORT_OK, qw($L_CHUNKSUCCESS);
380 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_CHUNKSUCCESS);
381
382 $_logtype_t_VALUES{"L_CHUNKSUCCESS"} = $L_CHUNKSUCCESS;
383
384 push @EXPORT_OK, qw($L_STATS);
385 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_STATS);
386
387 $_logtype_t_VALUES{"L_STATS"} = $L_STATS;
388
389 push @EXPORT_OK, qw($L_MARKER);
390 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_MARKER);
391
392 $_logtype_t_VALUES{"L_MARKER"} = $L_MARKER;
393
394 push @EXPORT_OK, qw($L_CONT);
395 push @{$EXPORT_TAGS{"logtype_t"}}, qw($L_CONT);
396
397 $_logtype_t_VALUES{"L_CONT"} = $L_CONT;
398
399 push @EXPORT_OK, qw(program_t_to_string);
400 push @{$EXPORT_TAGS{"program_t"}}, qw(program_t_to_string);
401
402 my %_program_t_VALUES;
403 #Convert an enum value to a single string
404 sub program_t_to_string {
405     my ($enumval) = @_;
406
407     for my $k (keys %_program_t_VALUES) {
408         my $v = $_program_t_VALUES{$k};
409
410         #is this a matching flag?
411         if ($enumval == $v) {
412             return $k;
413         }
414     }
415
416 #default, just return the number
417     return $enumval;
418 }
419
420 push @EXPORT_OK, qw($P_UNKNOWN);
421 push @{$EXPORT_TAGS{"program_t"}}, qw($P_UNKNOWN);
422
423 $_program_t_VALUES{"P_UNKNOWN"} = $P_UNKNOWN;
424
425 push @EXPORT_OK, qw($P_PLANNER);
426 push @{$EXPORT_TAGS{"program_t"}}, qw($P_PLANNER);
427
428 $_program_t_VALUES{"P_PLANNER"} = $P_PLANNER;
429
430 push @EXPORT_OK, qw($P_DRIVER);
431 push @{$EXPORT_TAGS{"program_t"}}, qw($P_DRIVER);
432
433 $_program_t_VALUES{"P_DRIVER"} = $P_DRIVER;
434
435 push @EXPORT_OK, qw($P_REPORTER);
436 push @{$EXPORT_TAGS{"program_t"}}, qw($P_REPORTER);
437
438 $_program_t_VALUES{"P_REPORTER"} = $P_REPORTER;
439
440 push @EXPORT_OK, qw($P_DUMPER);
441 push @{$EXPORT_TAGS{"program_t"}}, qw($P_DUMPER);
442
443 $_program_t_VALUES{"P_DUMPER"} = $P_DUMPER;
444
445 push @EXPORT_OK, qw($P_CHUNKER);
446 push @{$EXPORT_TAGS{"program_t"}}, qw($P_CHUNKER);
447
448 $_program_t_VALUES{"P_CHUNKER"} = $P_CHUNKER;
449
450 push @EXPORT_OK, qw($P_TAPER);
451 push @{$EXPORT_TAGS{"program_t"}}, qw($P_TAPER);
452
453 $_program_t_VALUES{"P_TAPER"} = $P_TAPER;
454
455 push @EXPORT_OK, qw($P_AMFLUSH);
456 push @{$EXPORT_TAGS{"program_t"}}, qw($P_AMFLUSH);
457
458 $_program_t_VALUES{"P_AMFLUSH"} = $P_AMFLUSH;
459
460 push @EXPORT_OK, qw(find_log search_logfile dumps_match);
461 1;