line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# server::logstash::indexer Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Server::Logstash::Indexer; |
7
|
1
|
|
|
1
|
|
783
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Server::Logstash); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
460
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
datadir => [ qw(datadir) ], |
20
|
|
|
|
|
|
|
conf_file => [ qw(file) ], |
21
|
|
|
|
|
|
|
log_file => [ qw(file) ], |
22
|
|
|
|
|
|
|
version => [ qw(2.4.0|5.0.0|5.5.2) ], |
23
|
|
|
|
|
|
|
no_output => [ qw(0|1) ], |
24
|
|
|
|
|
|
|
redis_host => [ qw(host) ], |
25
|
|
|
|
|
|
|
es_nodes => [ qw(node_list) ], |
26
|
|
|
|
|
|
|
binary => [ qw(binary_path) ], |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
attributes_default => { |
29
|
|
|
|
|
|
|
version => '5.5.2', |
30
|
|
|
|
|
|
|
no_output => 0, |
31
|
|
|
|
|
|
|
log_file => 'logstash.log', |
32
|
|
|
|
|
|
|
redis_host => '127.0.0.1', |
33
|
|
|
|
|
|
|
es_nodes => [ '127.0.0.1:9200' ], |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
commands => { |
36
|
|
|
|
|
|
|
install => [ ], |
37
|
|
|
|
|
|
|
get_binary => [ ], |
38
|
|
|
|
|
|
|
check_config => [ qw(conf_file) ], |
39
|
|
|
|
|
|
|
start => [ qw(conf_file|OPTIONAL) ], |
40
|
|
|
|
|
|
|
start_in_foreground => [ qw(conf_file|OPTIONAL) ], |
41
|
|
|
|
|
|
|
stop => [ ], |
42
|
|
|
|
|
|
|
generate_conf => [ qw(conf_file|OPTIONAL redis_host|OPTIONAL) ], |
43
|
|
|
|
|
|
|
status => [ ], |
44
|
|
|
|
|
|
|
restart => [ ], |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub generate_conf { |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my ($conf_file, $redis_host) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $es_nodes = $self->es_nodes; |
54
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('generate_conf', $es_nodes) or return; |
55
|
0
|
0
|
|
|
|
|
$self->brik_help_run_invalid_arg('generate_conf', $es_nodes, 'ARRAY') or return; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
0
|
|
|
|
$conf_file ||= $self->conf_file; |
58
|
0
|
|
0
|
|
|
|
$redis_host ||= $self->redis_host; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $es_hosts = '[ '; |
61
|
0
|
|
|
|
|
|
for my $this (@$es_nodes) { |
62
|
0
|
|
|
|
|
|
$es_hosts .= "\"$this\", "; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
$es_hosts =~ s{, $}{ \]}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $conf =<
|
67
|
|
|
|
|
|
|
input { |
68
|
|
|
|
|
|
|
redis { |
69
|
|
|
|
|
|
|
host => "$redis_host" |
70
|
|
|
|
|
|
|
key => "logstash" |
71
|
|
|
|
|
|
|
data_type => "list" |
72
|
|
|
|
|
|
|
codec => json |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
output { |
77
|
|
|
|
|
|
|
if "_grokparsefailure" in [tags] { |
78
|
|
|
|
|
|
|
null {} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
if [type] == "example" { |
81
|
|
|
|
|
|
|
elasticsearch { |
82
|
|
|
|
|
|
|
hosts => $es_hosts |
83
|
|
|
|
|
|
|
index => "example-%{+YYYY-MM-dd}" |
84
|
|
|
|
|
|
|
document_type => "document" |
85
|
|
|
|
|
|
|
template_name => "example-*" |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
EOF |
90
|
|
|
|
|
|
|
; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
93
|
0
|
|
|
|
|
|
$ft->append(0); |
94
|
0
|
|
|
|
|
|
$ft->overwrite(1); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$ft->write($conf, $conf_file) or return; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $conf_file; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub restart { |
102
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->stop; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
sleep(2); # Wait for process to stop |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->start; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |