Fwctl/Report.pm untested

filter: Statementstmt 0.0% 0 / 307 Branchbran 0.0% 0 / 128 Conditioncond 0.0% 0 / 49 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 0.0% 0 / 50 Podpod 0.0% 0 / 30 totaltotal 0.0% 0 / 594 CC 59 SCAR 44.9
CC
59
Cov
0%
parse_term
342.0
read_records
110.0
is_duplicate
90.0
CRAP 89.6
1 #
2 # Report.pm - Module that compiles reports from the logs preprocessed by
3 # the fwctllog program.
4 #
5 # This file is part of Fwctl.
6 #
7 # Author: Francis J. Lacoste <francis@iNsu.COM>
8 #
9 # Copyright (c) 1999,2000 iNsu Innovations Inc.
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 package Fwctl::Report;
17  
18 use strict;
19  
20 use vars qw( $VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS @ISA );
21  
22 use Symbol;
23 use Time::Local;
24 use Exporter;
25  
26 use vars qw( $DATE_MANIP );
27  
28 =pod
29  
30 =head1 NAME
31  
32 Fwctl::Report - Generates reports from fwctllog output.
33  
34 =head1 SYNOPSIS
35  
36 use Fwctl::Report;
37  
38 my $report = new Fwctl::Report( options ... );
39  
40 my $src_alias_sum = $report->src_alias_summary_report;
41  
42 foreach my $r ( @$src_alias_sum ) {
43 print $r->{host_ip}, " = ", $r->{count}, "\n";
44 }
45  
46 =head1 DESCRIPTION
47  
48 The Fwctl::Report(3) module can be used to generate various reports from
49 the output of the B<fwctllog> program.
50  
51 This module generates two kinds of report C<summary> and <report>. The
52 summary compiles the number of occurence for an item (source,
53 destination, service, etc.). The report methods will returns all the
54 log entry that shares the same key ( source, destination, service,
55 etc.)
56  
57 =cut
58  
59 BEGIN {
60 ($VERSION) = '$Revision: 1.8 $' =~ /(Revision: ([\d.]+))/;
61 @ISA = qw( Exporter );
62  
63 @EXPORT = ();
64  
65 @EXPORT_OK = ();
66  
67 %EXPORT_TAGS = ( fields => [ qw( TIME ACTION DEVICE IF CHAIN
68 PROTO PROTO_NAME
69 SRC_IP SRC_HOST SRC_IF
70 SRC_ALIAS SRC_PORT SRC_SERV
71 DST_IP DST_HOST DST_IF
72 DST_ALIAS DST_PORT DST_SERV
73 )
74 ],
75 );
76 }
77  
78  
79  
80 BEGIN {
81 $DATE_MANIP = 0;
82 eval "use Date::Manip;";
83 $DATE_MANIP = 1 unless $@;
84 }
85  
86 BEGIN {
87 # Create the necessary constant
88 my $i = 0;
89 for my $f ( @{$EXPORT_TAGS{fields}} ) {
90 eval "use constant $f => $i;";
91 $i++;
92 }
93  
94 Exporter::export_ok_tags( 'fields' );
95 };
96  
97 use constant SERVICE_ALIAS_KEY =>
98 sub { if ( $_[0][PROTO] == 6 || $_[0][PROTO] == 17)
99 {
100 return $_[0][DST_ALIAS] . "/" . $_[0][PROTO] . "/" .
101 $_[0][DST_PORT];
102 } else {
103 return $_[0][DST_ALIAS] . "/" . $_[0][PROTO] . "/" .
104 $_[0][SRC_PORT] . "/" . $_[0][DST_PORT];
105 }
106 };
107  
108 use constant SERVICE_HOST_KEY =>
109 sub { if ( $_[0][PROTO] == 6 || $_[0][PROTO] == 17 )
110 {
111 return $_[0][DST_IP] . "/" . $_[0][PROTO] . "/" . $_[0][DST_PORT];
112 } else {
113 return $_[0][DST_IP] . "/" . $_[0][PROTO] . "/" .
114 $_[0][SRC_PORT] . "/" . $_[0][DST_PORT];
115 }
116 };
117  
118 use constant SERVICE_KEY =>
119 sub { if ( $_[0][PROTO] == 6 || $_[0][PROTO] == 17) {
120 return $_[0][PROTO] . "/" . $_[0][DST_PORT];
121 } else {
122 return $_[0][PROTO] . "/" . $_[0][SRC_PORT]."/" . $_[0][DST_PORT];
123 }
124 };
125  
126  
127 use constant DST_HOST_KEY => sub { $_[0][DST_IP] };
128  
129 use constant DST_ALIAS_KEY => sub { $_[0][DST_ALIAS] };
130  
131 use constant SRC_HOST_KEY => sub { $_[0][SRC_IP] };
132  
133 use constant SRC_ALIAS_KEY => sub { $_[0][SRC_ALIAS] };
134  
135 use constant SRC_HOST_SUMMARY_RECORD =>
136 sub { { host_ip => $_[0][SRC_IP],
137 host_name => $_[0][SRC_HOST],
138 host_alias => $_[0][SRC_ALIAS],
139 };
140 };
141  
142 use constant SRC_ALIAS_SUMMARY_RECORD =>
143 sub { {
144 host_alias => $_[0][SRC_ALIAS],
145 };
146 };
147  
148 use constant DST_ALIAS_SUMMARY_RECORD =>
149 sub { {
150 host_alias => $_[0][DST_ALIAS],
151 };
152 };
153  
154 use constant DST_HOST_SUMMARY_RECORD =>
155 sub { { host_ip => $_[0][DST_IP],
156 host_name => $_[0][DST_HOST],
157 host_alias => $_[0][DST_ALIAS],
158 };
159 };
160  
161 use constant SERVICE_SUMMARY_RECORD =>
162 sub {
163 my $result = { proto => $_[0][PROTO],
164 proto_name => $_[0][PROTO_NAME],
165 dst_port => $_[0][DST_PORT],
166 dst_serv => $_[0][DST_SERV],
167 };
168 if ( $_[0][PROTO] != 6 && $_[0][PROTO] != 17 ) {
169 $result->{src_port} = $_[0][SRC_PORT];
170 $result->{src_serv} = $_[0][SRC_SERV];
171 }
172 $result;
173 };
174  
175 use constant SERVICE_ALIAS_SUMMARY_RECORD =>
176 sub {
177 my $result = { host_alias => $_[0][DST_ALIAS],
178 proto => $_[0][PROTO],
179 proto_name => $_[0][PROTO_NAME],
180 dst_port => $_[0][DST_PORT],
181 dst_serv => $_[0][DST_SERV],
182 };
183 if ( $_[0][PROTO] != 6 && $_[0][PROTO] != 17 ) {
184 $result->{src_port} = $_[0][SRC_PORT];
185 $result->{src_serv} = $_[0][SRC_SERV];
186 }
187 $result;
188 };
189  
190 use constant SERVICE_HOST_SUMMARY_RECORD =>
191 sub {
192 my $result = { host_ip => $_[0][DST_IP],
193 host_name => $_[0][DST_HOST],
194 host_alias => $_[0][DST_ALIAS],
195 proto => $_[0][PROTO],
196 proto_name => $_[0][PROTO_NAME],
197 dst_port => $_[0][DST_PORT],
198 dst_serv => $_[0][DST_SERV],
199 };
200 if ( $_[0][PROTO] != 6 && $_[0][PROTO] != 17 ) {
201 $result->{src_port} = $_[0][SRC_PORT];
202 $result->{src_serv} = $_[0][SRC_SERV];
203 }
204 $result;
205 };
206  
207 sub summary_iterator {
208 my ($records, $get_key_sub, $create_record_sub ) = @_;
209  
210 my %cache = ();
211 foreach my $r ( @$records ) {
212 my $key = $get_key_sub->( $r );
213 if ( ! exists $cache{$key} ) {
214 $cache{$key} = $create_record_sub->( $r );
215 $cache{$key}{count} = 0;
216 $cache{$key}{first} = $r->[TIME];
217 }
218 $cache{$key}{count}++;
219 $cache{$key}{last} = $r->[TIME];
220 }
221  
222 return [ sort { $b->{count} <=> $a->{count} } values %cache ];
223 }
224  
225 sub report_iterator {
226 my ( $records, $key_sub ) = @_;
227  
228 my %cache = ();
229 foreach my $r ( @$records ) {
230 my $key = $key_sub->( $r );
231  
232 unless ( exists $cache{$key}) {
233 $cache{$key} = [ $key, [] ];
234 }
235 push @{$cache{$key}[1]}, $r;
236 }
237 return [ map { $_->[1] } sort { $a->[0] cmp $b->[0] } values %cache ];
238 }
239  
240 # Removes packets that are in the same time window.
241 sub is_duplicate {
242 my ( $self, $r ) = @_;
243  
244 my $cutoff = $self->{threshold};
245 return 0 unless $cutoff > 0;
246 my $window = $r->[TIME] - $cutoff;
247 my $seen = 0;
248 for ( my $i = $#{$self->{records}};
249 $i >= 0 && $self->{records}[$i][TIME] > $window;
250 $i--
251 )
252 {
253 my $nr = $self->{records}[$i];
254 next unless $r->[PROTO] == $nr->[PROTO];
255 next unless $r->[SRC_IP] eq $nr->[SRC_IP];
256 next unless $r->[DST_IP] eq $nr->[DST_IP];
257 if ( $r->[PROTO] == 6 ||
258 $r->[PROTO] == 17
259 )
260 {
261 # For TCP/UDP we only need to check the dst port
262 next unless $r->[DST_PORT] == $nr->[DST_PORT];
263 } else {
264 next unless $r->[SRC_PORT] == $nr->[SRC_PORT];
265 next unless $r->[DST_PORT] == $nr->[DST_PORT];
266 }
267  
268 # This is part of the same try
269 return 1;
270 }
271  
272 return 0;
273 }
274  
275 sub parse_date {
276 my $str = shift;
277  
278 if ( $DATE_MANIP) {
279 my $date = ParseDate( $str ) or return undef;
280 return UnixDate( $date, '%s' );
281 } else {
282 my ( $yearpart, $year, $month, $day, $time, $hour, $min, $sec) =
283 $str =~ /((\d\d\d?\d?|\d\d)?-?(\d\d?)-(\d\d?) ?)?((\d\d?):(\d\d?):?(\d\d?)?)?/;
284 return undef unless $yearpart || $time;
285  
286 if ( $yearpart ) {
287 if (defined $year) {
288 $year = $year > 1900 ? $year - 1900 :
289 $year < 70 ? $year + 100 : $year;
290 } else {
291 $year = (localtime)[5];
292 }
293 $month = $month == 12 ? 0 : $month - 1;
294 } else {
295 ($year,$month,$day ) = (localtime)[5,4,3];
296 }
297 unless ($time) {
298 # Midnight
299 ($hour,$min,$sec) = (0,0,0);
300 }
301 $sec ||= 0;
302 return timelocal $sec, $min, $hour, $day, $month, $year;
303 }
304 }
305  
306 sub parse_period {
307 my $str = shift;
308 if ( $DATE_MANIP ) {
309 my $period = ParseDateDelta( $str ) or return undef;
310 return Delta_Format( $period, 0, '%st' );
311 } else {
312 my ( $weeks, $days, $hours, $mins, $secs ) =
313 $str =~ /(?:(\d+) ?w[eks ]*)?(?:(\d+) ?d[ays ]*)?(?:(\d+) ?h[hours ]*)?(?:(\d+) ?m[inutes ]*)?(?:(\d+) ?s[econds ]*)?/i;
314  
315 my $time = 0;
316  
317 $time += $weeks * 7 * 24 * 60 * 60 if $weeks;
318 $time += $days * 24 * 60 * 60 if $days;
319 $time += $hours * 60 * 60 if $hours;
320 $time += $mins * 60 if $mins;
321 $time += $secs if $secs;
322  
323 return $time || undef;
324 }
325 }
326  
327 my $needs_and = 0;
328 sub parse_term {
329 my ($valid_fields, $sub, $constraints ) = @_;
330  
331 # Parse assertion
332 my $term = shift @$constraints;
333 die "missing term\n" unless $term;
334  
335 if ( $term eq '(' ) {
336 $sub .= " && " if $needs_and;
337 $sub .= ' ( ';
338 $needs_and = 0;
339 $sub = parse_term( $valid_fields, $sub, $constraints );
340 $term = shift @$constraints;
341 die "missing )\n" unless $term eq ')';
342 $needs_and = 1;
343 } elsif ( $term eq 'not' ) {
344 $sub .= " && " if $needs_and;
345 $sub .= ' ! (';
346 $needs_and = 0;
347 $sub = parse_term( $valid_fields, $sub, $constraints );
348 $sub .= ' )';
349 $needs_and = 1;
350 } elsif ( $term eq 'and' ) {
351 $sub .= ' && ( ';
352 $needs_and = 0;
353 $sub = parse_term( $valid_fields, $sub, $constraints );
354 $sub .= ' )';
355 $needs_and = 1;
356 } elsif ( $term eq 'or' ) {
357 $sub .= ' || ( ';
358 $needs_and = 0;
359 $sub = parse_term( $valid_fields, $sub, $constraints );
360 $sub .= ' )';
361 $needs_and = 1;
362 } elsif ( exists $valid_fields->{$term} ) {
363 my $field = ' $r->[' . $valid_fields->{$term} . ']';
364  
365 $term = shift @$constraints;
366 die "incomplete constraint $field\n" unless defined $term;
367  
368 $sub .= " && " if $needs_and;
369 if ( $term =~ /<|>|!=|=|>=|<=/ ) {
370 my $op = $term;
371 $op = "eq" if $op eq '=';
372 $term = shift @$constraints;
373 die "incomplete constraint $field $op\n" unless defined $term;
374  
375 # Quote term if necessary
376 $term = 'q{' . $term . '}' unless $term =~ /^\d+$/;
377 $sub .= " $field $op $term ";
378 } elsif ( $term =~ m!^/.+/i?! )
379 {
380 # Regular expression
381 $sub .= " $field =~ $term ";
382 } else {
383 # Comparison
384  
385 # Quote term if necessary
386 $term = 'q{' . $term . '}' unless $term =~ /^\d+$/;
387  
388 $sub .= " $field eq $term ";
389 }
390 $needs_and = 1;
391 } else {
392 die "unknown field ($term)\n";
393 }
394  
395 return $sub;
396 }
397  
398 my $true = sub { 1 };
399  
400 sub build_constraints {
401 my $valid_fields = shift;
402 my @constraints = split /\s+/, join " ", @_;
403  
404 return $true unless @constraints;
405  
406 my $sub = 'sub { my $r = shift; return ';
407  
408 $needs_and = 0;
409 while ( @constraints ) {
410 $sub = parse_term( $valid_fields, $sub, \@constraints );
411 }
412 $sub .= ' }';
413  
414 # Compile into code ref
415 $sub = eval $sub;
416 die "error compiling constraints : $@\n" if $@;
417  
418 return $sub;
419 }
420  
421 ## Assumes that the records are already sorted by time.
422 sub read_records {
423 my $self = shift;
424  
425 # Read in the data
426 push @{$self->{opts}{files}}, \*STDIN unless @{$self->{opts}{files}};
427 FILE:
428 foreach my $file ( @{$self->{opts}{files}} ) {
429 my $fh;
430 if ( ref $file ) {
431 $fh = $file;
432 } elsif ( $file eq "-" ) {
433 $fh = \*STDIN;
434 } else {
435 $fh = gensym;
436 open $fh, $file
437 or do { warn "can't open file $file\n"; next FILE };
438 }
439  
440 my $i = 0;
441 while (<$fh>) {
442 chomp;
443 my @fields = split /\|/, $_;
444 if ( ! defined $self->{start}) {
445 $self->{start} = $fields[TIME];
446 $self->{end} = $self->{start} + $self->{period}
447 if defined $self->{period};
448 }
449 # Skip fields before the period
450 next unless $self->{start} <= $fields[TIME];
451  
452 # Quit loop if we reach the end of the period.
453 last FILE if $self->{end} < $fields[TIME];
454  
455 next unless $self->{constraints}->( \@fields );
456  
457 next if $self->is_duplicate( \@fields );
458  
459 push @{$self->{records}}, \@fields;
460 }
461 }
462 }
463  
464  
465 =pod
466  
467 =head1 CREATING A NEW REPORT OBJECT
468  
469 Ex. my $report = new Fwctl::Report( start => 'yesterday',
470 period => '1 day',
471 files => [ 'log' ] );
472  
473 =head2 PARAMETERS
474  
475 The C<new> method accepts the following parameter :
476  
477 =over
478  
479 =item files
480  
481 Specifies the file from which to read the F<fwctllog> output. It is an
482 array of file handle or file names. If this parameter is not specified
483 the records will be read from STDIN.
484  
485 =item start
486  
487 Sets the start of the report's period. If the Date::Manip(3) module is
488 installed, you can use any format that this module can parse. If that module
489 is'nt installed you must use the following format YYYY-MM-DD HH:MM:SS or any
490 meaningful subset of that format.
491  
492 If this option is not used, the report will start with the first record.
493  
494 =item end
495  
496 Sets the end of the report's period. If the Date::Manip(3) module is
497 installed, you can use any format that this module can parse. If that module
498 is'nt installed you must use the following format YYYY-MM-DD HH:MM:SS or any
499 meaningful subset of that format.
500  
501 If this option is not used, the report will end with the last record.
502  
503 =item period
504  
505 Sets the length of the report's period. This length is interpreted relative
506 to the report's start. This option has priority over the B<end> option.
507  
508 If you have the Date::Manip module installed, you can use any format that this
509 module can parse. If that module isn't available, you can use a subset of the
510 following format X weeks X days X hours X mins X secs.
511  
512 =item threshold
513  
514 This option will removed records identical in protocol, destination
515 ports, source addresses and destination addressesses that appears in
516 the time window specified by the threshold parameters. Defaults is 120
517 (2 minutes). Use 0 to generates reports for all the packets.
518  
519 =item limit
520  
521 This parameter can be used to restrict the records over which the
522 report is generated. It is an expression which will be used to select
523 a subset of all the records. You can use the following fields :
524 src_ip, dst_ip, src_host, dst_host, action, device, src_port,
525 dst_port, src_serv, dst_serv, proto, proto_name, and the following
526 operator =, !=, <, >, <=, >=, /regex/, /regex/i. Those operators have
527 the same meaning as in perl. You can also use parentheses and the
528 following logic operator : or, and, not .
529  
530 =back
531  
532 =cut
533  
534 sub new {
535 my $proto = shift;
536 my $class = ref $proto || $proto;
537  
538 my $self = { opts => { @_ },
539 records => undef,
540 start => undef,
541 end => undef,
542 period => undef,
543 threshold => undef,
544 };
545  
546 # Determine start and end of the report;
547 if ( $self->{opts}{start} ) {
548 $self->{start} = Fwctl::Report::parse_date( $self->{opts}{start} )
549 or die "invalid start date format: $self->{opts}{start}\n";
550 }
551  
552 if ( $self->{opts}{period} ) {
553 $self->{period} = Fwctl::Report::parse_period( $self->{opts}{period})
554 or die "fwctlreport: invalid period delta: $self->{opts}{period}\n";
555 if ( $self->{start} ) {
556 $self->{end} = $self->{start} + $self->{period};
557 }
558 } elsif ( $self->{opts}{end} ) {
559 $self->{end} = Fwctl::Report::parse_date( $self->{opts}{end} )
560 or die "fwctlreport: invalid end date format: $self->{opts}{end}\n";
561 } else {
562 $self->{end} = time;
563 }
564  
565 if ( $self->{opts}{threshold} ) {
566 $self->{threshold} = Fwctl::Report::parse_period( $self->{opts}{threshold} )
567 or die "fwctlreport: invalid threshold: $self->{opts}{threshold}\n";
568 } else {
569 $self->{threshold} = 120; # 2 minutes
570 }
571  
572 $self->{constraints} = build_constraints( {
573 action => ACTION,
574 device => DEVICE,
575 proto => PROTO,
576 proto_name => PROTO_NAME,
577 src_ip => SRC_IP,
578 src_host => SRC_HOST,
579 src_if => SRC_IF,
580 src_alias => SRC_ALIAS,
581 src_port => SRC_PORT,
582 src_serv => SRC_SERV,
583 dst_ip => DST_IP,
584 dst_host => DST_HOST,
585 dst_if => DST_IF,
586 dst_alias => DST_ALIAS,
587 dst_port => DST_PORT,
588 }, $self->{opts}{limit} );
589 bless $self, $class;
590  
591 $self->read_records;
592  
593 $self;
594 }
595  
596 =pod
597  
598 =head1 METHODS
599  
600 =head1 start()
601  
602 Return the start of the report in seconds since epoch.
603  
604 =cut
605  
606 sub start {
607 $_[0]->{start};
608 }
609  
610 =pod
611  
612 =head1 end()
613  
614 Returns the end of the report in seconds since epoch.
615  
616 =cut
617  
618 sub end {
619 $_[0]->{end};
620 }
621  
622 =pod
623  
624 =head1 period()
625  
626 Returns the length of the report's period ( $report->end() - $report->start() )
627  
628 =cut
629  
630 sub period {
631 $_[0]->{end} - $_[0]->{period};
632 }
633  
634 =pod
635  
636 =head1 records()
637  
638 Returns an array reference to all the records read and which makes the
639 report's sample.
640  
641 =head2 RECORD FIELDS
642  
643 Each record is an array ref. You can accessed the individual fields of
644 the record by using the following constants. (Those can be imported by
645 using the C<:fields> import tag.)
646  
647 =over
648  
649 =item TIME
650  
651 The epoch time of the log entry.
652  
653 =item ACTION
654  
655 The resulting action (ACCEPT,DENY,REJECT).
656  
657 =item DEVICE
658  
659 The physical device on which the packet was logged.
660  
661 =item IF
662  
663 The Fwctl(3) interface to which this device is related.
664  
665 =item CHAIN
666  
667 The kernel chain on which that packet was logged.
668  
669 =item PROTO
670  
671 The protocol number.
672  
673 =item PROTO_NAME
674  
675 The name of the protocol.
676  
677 =item SRC_IP
678  
679 The source address of the packet.
680  
681 =item SRC_HOST
682  
683 The source hostname.
684  
685 =item SRC_IF
686  
687 The Fwct(3) interface related to the source address.
688  
689 =item SRC_ALIAS
690  
691 The Fwctl(3) alias associated to the source address.
692  
693 =item SRC_PORT
694  
695 The source port of the logged packet.
696  
697 =item SRC_SERV
698  
699 The service name associated to the logged packet.
700  
701 =item DST_IP
702  
703 The destination IP of the packet.
704  
705 =item DST_HOST
706  
707 The destination hostname.
708  
709 =item DST_IF
710  
711 The Fwctl(3) interface associated with the destination address.
712  
713 =item DST_ALIAS
714  
715 The Fwctl(3) alias related to the destination address.
716  
717 =item DST_PORT
718  
719 The destination port number.
720  
721 =item DST_SERV
722  
723 The service name of the the destination port.
724  
725 =back
726  
727 =cut
728  
729 sub records {
730 # Copy the records
731 [ @{$_[0]->{records}} ];
732 }
733  
734 =pod
735  
736 =head1 REPORTS
737  
738 The following report generation methods are available :
739  
740 =head2 service_summary_report()
741  
742 my $r = $report->service_summary_report();
743  
744  
745 Generates a report that shows the number of log entries for each
746 services.
747  
748 The resulting report is an array ref of hash reference. Each report
749 record's has the following fields.
750  
751 =over
752  
753 =item proto
754  
755 The protocol number.
756  
757 =item proto_name
758  
759 The protocol name.
760  
761 =item dst_port
762  
763 The destination port.
764  
765 =item dst_serv
766  
767 The destination service's name.
768  
769 =item src_port
770  
771 If the protocol B<is not> UDP or TCP, the source port.
772  
773 =item src_serv
774  
775 If the protocol B<is not> UDP or TCP, the service name associated to the
776 source port.
777  
778 =item count
779  
780 The number of log entries matching the service.
781  
782 =item first
783  
784 The epoch time of the first occurence.
785  
786 =item last
787  
788 The epoch time of the last occurence.
789  
790 =back
791  
792 =cut
793  
794 sub service_summary_report {
795 return summary_iterator( $_[0]->{records}, SERVICE_KEY,
796 SERVICE_SUMMARY_RECORD );
797 }
798  
799 =pod
800  
801 =head2 service_report()
802  
803 my $r = $report->service_report();
804  
805 Generates a report that sort the log entries by service.
806  
807 The report is an array of arrays. Each elements of the report is an
808 array of records which shares the same service.
809  
810 =cut
811  
812 sub service_report {
813 return report_iterator( $_[0]->{records}, SERVICE_KEY );
814 }
815  
816 =pod
817  
818 =head2 service_alias_summary_report()
819  
820 my $r = $report->service_alias_summary_report();
821  
822  
823 Generates a report that shows the number of log entries for each
824 destination aliases / service.
825  
826 The resulting report is an array ref of hash reference. Each report
827 record's has the following fields.
828  
829 =over
830  
831 =item proto
832  
833 The protocol number.
834  
835 =item proto_name
836  
837 The protocol name.
838  
839 =item host_alias
840  
841 The alias of the destination hosts.
842  
843 =item dst_port
844  
845 The destination port.
846  
847 =item dst_serv
848  
849 The destination's service name.
850  
851 =item src_port
852  
853 If the protocol B<is not> UDP or TCP, the source port.
854  
855 =item src_serv
856  
857 If the protocol B<is not> UDP or TCP, the service name associated to the
858 source port.
859  
860 =item count
861  
862 The number of log entries.
863  
864 =item first
865  
866 The epoch time of the first occurence.
867  
868 =item last
869  
870 The epoch time of the last occurence.
871  
872 =back
873  
874 =cut
875  
876 sub service_alias_summary_report {
877 return summary_iterator( $_[0]->{records}, SERVICE_ALIAS_KEY,
878 SERVICE_ALIAS_SUMMARY_RECORD );
879 }
880  
881 =head2 service_alias_report()
882  
883 my $r = $report->service_alias_report();
884  
885 Generates a report that sort the log entries by destination alias and
886 service.
887  
888 The report is an array of arrays. Each elements of the report is an
889 array of records which shares the same destination alias and service.
890  
891 =cut
892  
893 sub service_alias_report {
894 return report_iterator( $_[0]->{records}, SERVICE_ALIAS_KEY );
895 }
896  
897 =pod
898  
899 =head2 service_host_summary_report()
900  
901 my $r = $report->service_host_summary_report();
902  
903  
904 Generates a report that shows the number of log entries for each
905 destination aliases / service.
906  
907 The resulting report is an array ref of hash reference. Each report
908 record's has the following fields.
909  
910 =over
911  
912 =item proto
913  
914 The protocol number.
915  
916 =item proto_name
917  
918 The protocol name.
919  
920 =item host_ip
921  
922 The destination host ip address.
923  
924 =item host_name
925  
926 The destination host name.
927  
928 =item host_alias
929  
930 The alias of that host.
931  
932 =item dst_port
933  
934 The destination port.
935  
936 =item dst_serv
937  
938 The destination service's name.
939  
940 =item src_port
941  
942 If the protocol B<is not> UDP or TCP, the source port.
943  
944 =item src_serv
945  
946 If the protocol B<is not> UDP or TCP, the service name associated to the
947 source port.
948  
949 =item count
950  
951 The number of log entries.
952  
953 =item first
954  
955 The epoch time of the first occurence.
956  
957 =item last
958  
959 The epoch time of the last occurence.
960  
961 =back
962  
963 =cut
964  
965 sub service_host_summary_report {
966 return summary_iterator( $_[0]->{records}, SERVICE_HOST_KEY,
967 SERVICE_HOST_SUMMARY_RECORD );
968  
969 }
970  
971 =head2 service_host_report()
972  
973 my $r = $report->service_host_report();
974  
975 Generates a report that sort the log entries by destination host and
976 service.
977  
978 The report is an array of arrays. Each elements of the report is an
979 array of records which shares the same destination host and service.
980  
981 =cut
982  
983 sub service_host_report {
984 return report_iterator( $_[0]->{records}, SERVICE_HOST_KEY );
985 }
986  
987 =pod
988  
989 =head2 src_alias_summary_report()
990  
991 my $r = $report->service_alias_summary_report();
992  
993  
994 Generates a report that shows the number of log entries for each
995 source aliases.
996  
997 The resulting report is an array ref of hash reference. Each report
998 record's has the following fields.
999  
1000 =over
1001  
1002 =item host_alias
1003  
1004 The source alias.
1005  
1006 =item count
1007  
1008 The number of log entries.
1009  
1010 =item first
1011  
1012 The epoch time of the first occurence.
1013  
1014 =item last
1015  
1016 The epoch time of the last occurence.
1017  
1018 =back
1019  
1020 =cut
1021  
1022 sub src_alias_summary_report {
1023 return summary_iterator( $_[0]->{records}, SRC_ALIAS_KEY,
1024 SRC_ALIAS_SUMMARY_RECORD );
1025 }
1026  
1027 =head2 src_alias_report()
1028  
1029 my $r = $report->src_alias_report();
1030  
1031 Generates a report that sort the log entries by source alias.
1032  
1033 The report is an array of arrays. Each elements of the report is an
1034 array of records which shares the same source alias.
1035  
1036 =cut
1037  
1038 sub src_alias_report {
1039 return report_iterator( $_[0]->{records}, SRC_ALIAS_KEY );
1040 }
1041  
1042 =pod
1043  
1044 =head2 src_host_summary_report()
1045  
1046 my $r = $report->src_host_summary_report();
1047  
1048  
1049 Generates a report that shows the number of log entries for each
1050 source host.
1051  
1052 The resulting report is an array ref of hash reference. Each report
1053 record's has the following fields.
1054  
1055 =over
1056  
1057 =item host_ip
1058  
1059 The source host ip address.
1060  
1061 =item host_name
1062  
1063 The source host name.
1064  
1065 =item host_alias
1066  
1067 The alias of the source host.
1068  
1069 =item count
1070  
1071 The number of log entries.
1072  
1073 =item first
1074  
1075 The epoch time of the first occurence.
1076  
1077 =item last
1078  
1079 The epoch time of the last occurence.
1080  
1081 =back
1082  
1083 =cut
1084  
1085 sub src_host_summary_report {
1086 return summary_iterator( $_[0]->{records}, SRC_HOST_KEY,
1087 SRC_HOST_SUMMARY_RECORD );
1088  
1089 }
1090  
1091 =head2 src_host_report()
1092  
1093 my $r = $report->src_host_report();
1094  
1095 Generates a report that sort the log entries by source host.
1096  
1097 The report is an array of arrays. Each elements of the report is an
1098 array of records which shares the same source host.
1099  
1100 =cut
1101  
1102 sub src_host_report {
1103 return report_iterator( $_[0]->{records}, SRC_HOST_KEY );
1104 }
1105  
1106 =pod
1107  
1108 =head2 dst_alias_summary_report()
1109  
1110 my $r = $report->dst_alias_summary_report();
1111  
1112  
1113 Generates a report that shows the number of log entries for each
1114 destination aliases.
1115  
1116 The resulting report is an array ref of hash reference. Each report
1117 record's has the following fields.
1118  
1119 =over
1120  
1121 =item host_alias
1122  
1123 The destination alias.
1124  
1125 =item count
1126  
1127 The number of log entries.
1128  
1129 =item first
1130  
1131 The epoch time of the first occurence.
1132  
1133 =item last
1134  
1135 The epoch time of the last occurence.
1136  
1137 =back
1138  
1139 =cut
1140  
1141 sub dst_alias_summary_report {
1142 return summary_iterator( $_[0]->{records}, DST_ALIAS_KEY,
1143 DST_ALIAS_SUMMARY_RECORD );
1144 }
1145  
1146 =head2 dst_alias_report()
1147  
1148 my $r = $report->dst_alias_report();
1149  
1150 Generates a report that sort the log entries by destination alias.
1151  
1152 The report is an array of arrays. Each elements of the report is an
1153 array of records which shares the same destination alias.
1154  
1155 =cut
1156  
1157 sub dst_alias_report {
1158 return report_iterator( $_[0]->{records}, DST_ALIAS_KEY );
1159 }
1160  
1161 =pod
1162  
1163 =head2 src_host_summary_report()
1164  
1165 my $r = $report->src_host_summary_report();
1166  
1167  
1168 Generates a report that shows the number of log entries for each
1169 destination hosts.
1170  
1171 The resulting report is an array ref of hash reference. Each report
1172 record's has the following fields.
1173  
1174 =over
1175  
1176 =item host_ip
1177  
1178 The destination host ip address.
1179  
1180 =item host_name
1181  
1182 The destination host name.
1183  
1184 =item host_alias
1185  
1186 The alias of the destination hosts.
1187  
1188 =item count
1189  
1190 The number of log entries.
1191  
1192 =item first
1193  
1194 The epoch time of the first occurence.
1195  
1196 =item last
1197  
1198 The epoch time of the last occurence.
1199  
1200 =back
1201  
1202 =cut
1203  
1204 sub dst_host_summary_report {
1205 return summary_iterator( $_[0]->{records}, DST_HOST_KEY,
1206 DST_HOST_SUMMARY_RECORD );
1207  
1208 }
1209  
1210 =head2 dst_host_report()
1211  
1212 my $r = $report->dst_host_report();
1213  
1214 Generates a report that sort the log entries by destination host.
1215  
1216 The report is an array of arrays. Each elements of the report is an
1217 array of records which shares the same destination host.
1218  
1219 =cut
1220  
1221 sub dst_host_report {
1222 return report_iterator( $_[0]->{records}, DST_HOST_KEY );
1223 }
1224  
1225 1;
1226  
1227 __END__