line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# server::logstash::oneshot Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Server::Logstash::Oneshot; |
7
|
1
|
|
|
1
|
|
777
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw(Metabrik::Server::Logstash); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1038
|
|
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
|
|
|
|
|
|
|
binary => [ qw(binary_path) ], |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
attributes_default => { |
27
|
|
|
|
|
|
|
version => '5.5.2', |
28
|
|
|
|
|
|
|
no_output => 0, |
29
|
|
|
|
|
|
|
log_file => 'logstash.log', |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
commands => { |
32
|
|
|
|
|
|
|
install => [ ], # Inherited |
33
|
|
|
|
|
|
|
stdin_to_stdout => [ ], |
34
|
|
|
|
|
|
|
stdin_to_json => [ ], |
35
|
|
|
|
|
|
|
test_filter_against_string => [ qw(filter_file string|string_list) ], |
36
|
|
|
|
|
|
|
test_filter_against_logs => [ qw(filter_file input_file) ], |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
require_modules => { |
39
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub stdin_to_stdout { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
my $binary = $self->get_binary or return; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $cmd = "$binary -e 'input { stdin { } } output { stdout {} }'"; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->log->info("stdin_to_stdout: starting..."); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return $self->system($cmd); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub stdin_to_json { |
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
my $binary = $self->get_binary or return; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $cmd = "$binary -e 'input { stdin { } } output { stdout { codec => json } }'"; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->log->info("stdin_to_json: starting..."); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $self->system($cmd); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub test_filter_against_string { |
69
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my ($filter_file, $string) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('test_filter_against_string', $string) or return; |
73
|
0
|
0
|
|
|
|
|
my $ref = $self->brik_help_run_invalid_arg('test_filter_against_string', $string, |
74
|
|
|
|
|
|
|
'ARRAY', 'SCALAR') or return; |
75
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('test_filter_against_string', $filter_file) or return; |
76
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('test_filter_against_string', $filter_file) or return; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
79
|
0
|
|
|
|
|
|
$ft->as_array(1); |
80
|
0
|
0
|
|
|
|
|
my $lines = $ft->read($filter_file) or return; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if (@$lines == 0) { |
83
|
0
|
|
|
|
|
|
return $self->log->error("test_filter_against_string: file [$filter_file] is empty"); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my @lines = (); |
87
|
0
|
|
|
|
|
|
for (@$lines) { |
88
|
0
|
0
|
|
|
|
|
push @lines, $_ unless $_ =~ m{^\s*#}; # Remove comments, as it is not supported. |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
my $binary = $self->get_binary or return; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $filter = join('', @lines); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $input =<
|
96
|
|
|
|
|
|
|
input { |
97
|
|
|
|
|
|
|
stdin { } |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
EOF |
100
|
|
|
|
|
|
|
; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $output =<
|
103
|
|
|
|
|
|
|
output { |
104
|
|
|
|
|
|
|
if "_grokparsefailure" in [tags] |
105
|
|
|
|
|
|
|
or "_dateparsefailure" in [tags] |
106
|
|
|
|
|
|
|
{ |
107
|
|
|
|
|
|
|
stdout { |
108
|
|
|
|
|
|
|
codec => rubydebug |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
|
|
|
|
|
|
null {} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
EOF |
116
|
|
|
|
|
|
|
; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my $cmd; |
119
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
120
|
0
|
|
|
|
|
|
my $tmp_file = $self->datadir.'/logstash-test-filter-tmp.txt'; |
121
|
0
|
0
|
|
|
|
|
$ft->write($string, $tmp_file) or return; |
122
|
0
|
|
|
|
|
|
$cmd = "$binary -e '$input filter { $filter } $' < $tmp_file"; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
0
|
|
|
|
|
|
$cmd = "echo \"$string\" | $binary -e '$input filter { $filter } $output'"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->log->info("test_filter_against_string: starting..."); |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $self->system($cmd); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub test_filter_against_logs { |
134
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
135
|
0
|
|
|
|
|
|
my ($filter_file, $input_file) = @_; |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('test_filter_against_logs', $filter_file) or return; |
138
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('test_filter_against_logs', $filter_file) or return; |
139
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('test_filter_against_logs', $input_file) or return; |
140
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('test_filter_against_logs', $input_file) or return; |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
143
|
0
|
|
|
|
|
|
$ft->as_array(1); |
144
|
0
|
|
|
|
|
|
$ft->strip_crlf(1); |
145
|
0
|
0
|
|
|
|
|
my $lines = $ft->read($filter_file) or return; |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
if (@$lines == 0) { |
148
|
0
|
|
|
|
|
|
return $self->log->error("test_filter_against_logs: file [$filter_file] is empty"); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my @lines = (); |
152
|
0
|
|
|
|
|
|
for (@$lines) { |
153
|
0
|
0
|
|
|
|
|
push @lines, $_ unless $_ =~ m{^\s*#}; # Remove comments, as it is not supported. |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $filter_string = join('', @lines); |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $conf =<
|
159
|
|
|
|
|
|
|
input { stdin {} } |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
filter { $filter_string } |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
output { |
164
|
|
|
|
|
|
|
if "_grokparsefailure" in [tags] |
165
|
|
|
|
|
|
|
or "_dateparsefailure" in [tags] |
166
|
|
|
|
|
|
|
{ |
167
|
|
|
|
|
|
|
stdout { |
168
|
|
|
|
|
|
|
codec => rubydebug |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
|
|
|
|
|
|
null {} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
EOF |
176
|
|
|
|
|
|
|
; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my @conf_lines = split(/\n/, $conf); |
179
|
0
|
|
|
|
|
|
my $conf_string = join('', @conf_lines); |
180
|
|
|
|
|
|
|
|
181
|
0
|
0
|
|
|
|
|
my $binary = $self->get_binary or return; |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
my $cmd = "$binary -e '$conf_string' < $input_file"; |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$self->log->info("test_filter_against_string: starting..."); |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $self->system($cmd); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__END__ |