line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Output::Redis; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1737
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: plugin to write events to a redis server |
6
|
|
|
|
|
|
|
our $VERSION = '1.6'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::Output'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5859
|
use Redis; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
4
|
use JSON qw(encode_json); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'server' => ( is => 'ro', isa => 'Str', |
15
|
|
|
|
|
|
|
default => '127.0.0.1:6379' |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
has 'sock' => ( is => 'ro', isa => 'Maybe[Str]' ); |
18
|
|
|
|
|
|
|
has 'db' => ( is => 'ro', isa => 'Int', default => 0 ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has '_redis' => ( is => 'rw', isa => 'Redis', lazy => 1, |
21
|
|
|
|
|
|
|
default => sub { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
return $self->_connect_redis; |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'queue' => ( is => 'ro', isa => 'Str', default => 'logs' ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _connect_redis { |
30
|
0
|
|
|
0
|
|
|
my $self = shift; |
31
|
0
|
0
|
|
|
|
|
my $r = Redis->new( |
32
|
|
|
|
|
|
|
defined $self->sock ? ( |
33
|
|
|
|
|
|
|
sock => $self->sock, |
34
|
|
|
|
|
|
|
) : ( |
35
|
|
|
|
|
|
|
server => $self->server, |
36
|
|
|
|
|
|
|
), |
37
|
|
|
|
|
|
|
); |
38
|
0
|
|
|
|
|
|
$r->select( $self->db ); |
39
|
0
|
|
|
|
|
|
return $r; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub output { |
43
|
0
|
|
|
0
|
0
|
|
my ( $self, @events ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my @blobs = map { |
46
|
0
|
|
|
|
|
|
my %output = %$_; |
|
0
|
|
|
|
|
|
|
47
|
0
|
0
|
0
|
|
|
|
if( defined $output{'time'} && |
48
|
|
|
|
|
|
|
ref($output{'time'}) eq 'Time::Piece' ) { |
49
|
0
|
|
|
|
|
|
$output{'@timestamp'} = $output{'time'}->datetime; |
50
|
0
|
|
|
|
|
|
delete $output{'time'}; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
encode_json(\%output) |
53
|
|
|
|
|
|
|
} @events; |
54
|
0
|
|
|
|
|
|
$self->_redis->lpush($self->queue, @blobs); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=pod |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=encoding UTF-8 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 NAME |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Log::Saftpresse::Output::Redis - plugin to write events to a redis server |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 VERSION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
version 1.6 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 Description |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Write events to a queue on a redis server. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 Synopsis |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
<Input myapp> |
82
|
|
|
|
|
|
|
module = "Redis" |
83
|
|
|
|
|
|
|
server = "127.0.0.1:6379" |
84
|
|
|
|
|
|
|
# sock = "/path/to/socket" |
85
|
|
|
|
|
|
|
db = 0 |
86
|
|
|
|
|
|
|
queue = "logs" |
87
|
|
|
|
|
|
|
</Input> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 Format |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The plugin will write entries in JSON format. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This is free software, licensed under: |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |