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