File Coverage

blib/lib/Log/Saftpresse/Plugin/SyslogFile.pm
Criterion Covered Total %
statement 6 26 23.0
branch 0 8 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 38 23.6


line stmt bran cond sub pod time code
1             package Log::Saftpresse::Plugin::SyslogFile;
2              
3 1     1   957 use Moose;
  1         2  
  1         6  
4              
5             # ABSTRACT: plugin to parse syslog logfile format
6             our $VERSION = '1.4'; # VERSION
7              
8             extends 'Log::Saftpresse::Plugin';
9              
10 1     1   4424 use Time::Piece;
  1         1  
  1         8  
11              
12             sub process {
13 0     0 1   my ( $self, $stash ) = @_;
14            
15 0 0         if( my ( $date_str, $msg ) = $stash->{'message'} =~
16             /^(... {1,2}\d{1,2} \d{2}:\d{2}:\d{2}) (.+)$/) {
17 0           my $time = Time::Piece->strptime($date_str, "%b %e %H:%M:%S");
18 0           my $now = Time::Piece->new;
19              
20             # guess year
21 0 0         if( $time->mon > $now->mon ) {
22             # Time::Piece->year is ro :-/
23 0           $time->[5] = $now->[5] - 1;
24             } else {
25 0           $time->[5] = $now->[5];
26             }
27              
28 0           $stash->{'time'} = $time;
29 0           $stash->{'message'} = $msg;
30             }
31              
32 0 0         if( my ( $date_str, $msg ) = $stash->{'message'} =~
33             /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[\+\-](?:\d{2}):(?:\d{2})|Z) (.+)$/) {
34 0           $stash->{'time'} = Time::Piece->strptime($date_str, "%Y-%m-%dT%H:%M:%S%z");
35 0           $stash->{'message'} = $msg;
36             }
37              
38 0 0         if( my ( $host, $program, $pid, $msg ) = $stash->{'message'} =~
39             /^(\S+) ([^[]+)\[([^\]]+)\]: (.+)$/) {
40 0           $stash->{'host'} = $host;
41 0           $self->incr_one('by_host', $host);
42 0           $stash->{'program'} = $program;
43 0           $self->incr_one('by_program', $program);
44 0           $stash->{'pid'} = $pid;
45 0           $stash->{'message'} = $msg;
46             }
47              
48 0           return;
49             }
50              
51             1;
52              
53             __END__
54              
55             =pod
56              
57             =encoding UTF-8
58              
59             =head1 NAME
60              
61             Log::Saftpresse::Plugin::SyslogFile - plugin to parse syslog logfile format
62              
63             =head1 VERSION
64              
65             version 1.4
66              
67             =head1 AUTHOR
68              
69             Markus Benning <ich@markusbenning.de>
70              
71             =head1 COPYRIGHT AND LICENSE
72              
73             This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
74              
75             This is free software, licensed under:
76              
77             The GNU General Public License, Version 2, June 1991
78              
79             =cut