10 use POSIX
qw(strftime);
17 Getopt
::Long
::Configure
("pass_through");
23 'stats' => \
$stats_opt,
24 'verbose' => \
$verbose_opt,
27 pod2usage
(-exitval
=> -1, -verbose
=> 0) if $help_opt;
28 pod2usage
(-exitval
=> -2, -verbose
=> 2) if $man_opt;
32 # if the first argument is a file, we'll assume it s a journal file, and
33 # use the PrintingListener
36 $listener_or_code = "LWES::Listeners::EventPrintingListener";
40 $listener_or_code = shift @ARGV;
43 # determine the callback which will process each event
44 my $processEventFunc = getProcessEventFunc
($listener_or_code, \
@ARGV);
46 foreach my $journal (@ARGV)
56 open FH
, "zcat $journal |";
58 # read and parse header
60 while ( read (FH
, $header_bytes, 22) == 22)
62 my $header = bytesToHeader
($header_bytes);
64 # read and parse bytes
66 my $n = read (FH
, $event_bytes, $header->{'PayloadLength'});
67 if (defined ($n) && $n == $header->{'PayloadLength'})
69 my $event = bytesToEvent
($event_bytes);
71 # merge header into event
72 foreach my $h (keys %{$header})
74 unless (exists ($event->{$h}))
76 $event->{$h} = $header->{$h};
81 my ($success, $errors) = $processEventFunc->($event);
83 if (defined ($success))
85 $num_success += $success;
87 if (defined ($errors))
89 $num_error += $errors;
94 die "malformed or truncated journal";
103 my $log_date = strftime
("%a %b %e %H:%M:%S %Y", localtime (time()));
104 my $end = time()-$start;
105 print "$log_date : $journal had $num_events events processed with $num_success successful actions and $num_error errors in $end seconds\n";
115 lwes-perl-journal-listener - listens for events from a journal
119 lwes-perl-journal-listener [options] [<listener> [<args>] | <code>] <journal(s)>
122 --stats Print information about each file processed
123 -help Brief help message
124 -man Full Documentation
126 <listener> is the name of a perl module which extends the base
127 listener LWES::Listener and provides an initialize and processEvent
128 method. The <args> are passed directly to the listener constructor.
130 code is perl code which is embedded in a function which takes one
131 argument, a reference to a perl hash which contains the contents
132 of the event called $event
140 Print information about how many events were processed and how long it took
145 Print help information
149 Print more verbose help information
155 The lwes-perl-journal-listener is a tool for inspecting LWES events that
156 are in journal files created by the lwes-journaller.
158 There are several ways to use the tool. To just print out events as they
159 are seen it can be invoked as
161 % lwes-perl-journal-listener <journal>
163 Alternatively you can provide a LWES::Listener module as outlined in
164 the lwes-perl-event-listener man page.