logstash-filter-varnishlog 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTORS +10 -0
- data/DEVELOPER.md +2 -0
- data/Gemfile +3 -0
- data/LICENSE +11 -0
- data/README.md +86 -0
- data/lib/logstash/filters/varnishlog.rb +105 -0
- data/lib/logstash/filters/varnishlog/request.rb +24 -0
- data/lib/logstash/filters/varnishlog/response.rb +19 -0
- data/logstash-filter-varnishlog.gemspec +23 -0
- data/spec/CHANGELOG.md +2 -0
- data/spec/CONTRIBUTORS +10 -0
- data/spec/DEVELOPER.md +2 -0
- data/spec/Gemfile +3 -0
- data/spec/LICENSE +11 -0
- data/spec/README.md +86 -0
- data/spec/Rakefile +1 -0
- data/spec/filters/varnishlog_spec.rb +21 -0
- data/spec/lib/logstash/filters/varnishlog.rb +105 -0
- data/spec/lib/logstash/filters/varnishlog/request.rb +24 -0
- data/spec/lib/logstash/filters/varnishlog/response.rb +19 -0
- data/spec/logstash-filter-varnishlog-0.1.0.gem +0 -0
- data/spec/logstash-filter-varnishlog.gemspec +23 -0
- data/spec/spec_helper.rb +2 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6e3188bdffdfe92d62f542480eb7e554c14886c
|
4
|
+
data.tar.gz: 12fd295aea608fca1ab481e5cfaa59bc4d9b3c54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e12b49f6ece97158f12fe423fd63710fe2193209c0b361d3a91d450da6167e553b0268995fc4147a43393b164f497f6b7ab1c275fc11cf50394327ab1fd4c99
|
7
|
+
data.tar.gz: 531064d5d9c9ed71695f94580f2e4e14692b043f4042c65e9b1d468d975bf837a64a2d9ead38e8385742a1c96e3a77b97fa06dbe2c31e6decda268b9a0e22efc
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Christian Herweg - christian.herweg@gmail.com
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
you may not use this file except in compliance with the License.
|
3
|
+
You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
See the License for the specific language governing permissions and
|
11
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
10
|
+
|
11
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
13
|
+
|
14
|
+
## Need Help?
|
15
|
+
|
16
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
17
|
+
|
18
|
+
## Developing
|
19
|
+
|
20
|
+
### 1. Plugin Developement and Testing
|
21
|
+
|
22
|
+
#### Code
|
23
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
24
|
+
|
25
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
26
|
+
|
27
|
+
- Install dependencies
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Test
|
33
|
+
|
34
|
+
- Update your dependencies
|
35
|
+
|
36
|
+
```sh
|
37
|
+
bundle install
|
38
|
+
```
|
39
|
+
|
40
|
+
- Run tests
|
41
|
+
|
42
|
+
```sh
|
43
|
+
bundle exec rspec
|
44
|
+
```
|
45
|
+
|
46
|
+
### 2. Running your unpublished Plugin in Logstash
|
47
|
+
|
48
|
+
#### 2.1 Run in a local Logstash clone
|
49
|
+
|
50
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
51
|
+
```ruby
|
52
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
53
|
+
```
|
54
|
+
- Install plugin
|
55
|
+
```sh
|
56
|
+
bin/logstash-plugin install --no-verify
|
57
|
+
```
|
58
|
+
- Run Logstash with your plugin
|
59
|
+
```sh
|
60
|
+
bin/logstash -e 'filter {awesome {}}'
|
61
|
+
```
|
62
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
63
|
+
|
64
|
+
#### 2.2 Run in an installed Logstash
|
65
|
+
|
66
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
67
|
+
|
68
|
+
- Build your plugin gem
|
69
|
+
```sh
|
70
|
+
gem build logstash-filter-awesome.gemspec
|
71
|
+
```
|
72
|
+
- Install the plugin from the Logstash home
|
73
|
+
```sh
|
74
|
+
bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
|
75
|
+
```
|
76
|
+
- Start Logstash and proceed to test the plugin
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
81
|
+
|
82
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
83
|
+
|
84
|
+
It is more important to the community that you are able to contribute.
|
85
|
+
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
# This filter reads a varnishlog grouped by reqid
|
6
|
+
# message field with whatever you specify in the configuration.
|
7
|
+
#
|
8
|
+
# It is only intended to be used as an .
|
9
|
+
class LogStash::Filters::Varnishlog < LogStash::Filters::Base
|
10
|
+
|
11
|
+
# Setting the config_name here is required. This is how you
|
12
|
+
# See https://varnish-cache.org/docs/trunk/reference/varnishlog.html
|
13
|
+
#
|
14
|
+
# filter {
|
15
|
+
# {
|
16
|
+
# varnishlog {}
|
17
|
+
# }
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
config_name "varnishlog"
|
21
|
+
|
22
|
+
# Replace the message with this value.
|
23
|
+
#config :message, :validate => :string, :default => "Hello World!"
|
24
|
+
|
25
|
+
|
26
|
+
public
|
27
|
+
def register
|
28
|
+
# Add instance variables
|
29
|
+
end # def register
|
30
|
+
|
31
|
+
public
|
32
|
+
def filter(event)
|
33
|
+
items = event.get("[message]").split("\n")
|
34
|
+
##timestamps
|
35
|
+
timestamps = items.grep(/Timestamp/)
|
36
|
+
timestamps.each do |timestamp|
|
37
|
+
if match = /-\s+Timestamp\s+(?<step>.*): (?<time_a>.*) (?<time_b>.*) (?<time_c>.*)/.match(timestamp)
|
38
|
+
event.set("timestamp_" + match['step'], match['time_a'])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
## VCL Log
|
42
|
+
vcl_log = items.grep(/VCL_Log/)
|
43
|
+
vcl_log.each do |log|
|
44
|
+
if match = /-\s+VCL_Log\s+(?<log_line>.*)/.match(log)
|
45
|
+
(log_lines ||= []).push(match['log_line'])
|
46
|
+
event.set("VCL_Log", log_lines)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Requests
|
51
|
+
## Request headers.
|
52
|
+
request_headers = items.grep(/ReqHeader/)
|
53
|
+
request_headers.each do |header|
|
54
|
+
if match = /-\s+ReqHeader\s+(?<header_name>.*): (?<header_value>.*)/.match(header)
|
55
|
+
event.set(match['header_name'], match['header_value'])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
## Match ReqMethod.
|
59
|
+
if method_match = /-\s+ReqMethod\s+(?<method>.*)/.match(items.grep(/ReqMethod/)[0])
|
60
|
+
event.set("http-method", method_match['method'])
|
61
|
+
end
|
62
|
+
## Match ReqURL.
|
63
|
+
if url_match = /-\s+ReqURL\s+(?<url>\/.*)/.match(items.grep(/ReqURL/)[0])
|
64
|
+
event.set("url", url_match['url'])
|
65
|
+
end
|
66
|
+
## Match ReqProtocol.
|
67
|
+
if protocol_match = /-\s+ReqProtocol\s+(?<protocol>.*)/.match(items.grep(/ReqProtocol/)[0])
|
68
|
+
event.set("ReqProtocol", protocol_match['protocol'])
|
69
|
+
end
|
70
|
+
|
71
|
+
# Response
|
72
|
+
## Response headers.
|
73
|
+
response_headers = items.grep(/RespHeader/)
|
74
|
+
response_headers.each do |header|
|
75
|
+
if match = /-\s+RespHeader\s+(?<header_name>.*): (?<header_value>.*)/.match(header)
|
76
|
+
event.set(match['header_name'], match['header_value'])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
## Match RespProtocol
|
80
|
+
if protocol_match = /-\s+RespProtocol\s+(?<protocol>.*)/.match(items.grep(/RespProtocol/)[0])
|
81
|
+
event.set("RespProtocol", protocol_match['protocol'])
|
82
|
+
end
|
83
|
+
## Match RespStatus
|
84
|
+
if status_match = /-\s+RespStatus\s+(?<status>.*)/.match(items.grep(/RespStatus/)[0])
|
85
|
+
event.set("RespStatus", status_match['status'].to_i)
|
86
|
+
end
|
87
|
+
## Match RespReason
|
88
|
+
response_reason = items.grep(/RespReason/)
|
89
|
+
response_reason.each do |reason|
|
90
|
+
if match = /-\s+RespReason\s+(?<reason>.*)/.match(reason)
|
91
|
+
(reasons ||= []).push(match['reason'])
|
92
|
+
event.set("RespReason", reasons)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if @message
|
97
|
+
# Replace the event message with our message as configured in the
|
98
|
+
# config file.
|
99
|
+
event.set("message", @message)
|
100
|
+
end
|
101
|
+
|
102
|
+
# filter_matched should go in the last line of our successful code
|
103
|
+
filter_matched(event)
|
104
|
+
end # def filter
|
105
|
+
end # class LogStash::Filters::Varnishlog
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'headers'
|
4
|
+
|
5
|
+
#
|
6
|
+
# VarnishLog::Request - This class is used to create objects that represent HTTP
|
7
|
+
# requests from Varnish's perspective.
|
8
|
+
#
|
9
|
+
|
10
|
+
class VarnishLog
|
11
|
+
class Request < Headers
|
12
|
+
@methods = [:method, :url, :protocol]
|
13
|
+
@methods.each do |method|
|
14
|
+
attr_accessor method
|
15
|
+
end
|
16
|
+
|
17
|
+
# Assume the powers of Headers.
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'headers'
|
4
|
+
|
5
|
+
#
|
6
|
+
# VarnishLog::Response - This class is used to create objects that represent HTTP
|
7
|
+
# responses from Varnish's perspective.
|
8
|
+
#
|
9
|
+
|
10
|
+
class VarnishLog
|
11
|
+
class Response < Headers
|
12
|
+
|
13
|
+
# Assume the powers of Headers.
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-varnishlog'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.licenses = ['Apache License (2.0)']
|
5
|
+
s.summary = 'A logstash plugin reading varnishlog output'
|
6
|
+
s.description = 'logstash filter plugin reading varnishlog grouped by id'
|
7
|
+
s.homepage = 'https://github.com/cherweg/logstash-filter-varnishlog'
|
8
|
+
s.authors = ['Christian Herweg']
|
9
|
+
s.email = 'christian.herweg@gmail.com'
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
22
|
+
s.add_development_dependency 'logstash-devutils'
|
23
|
+
end
|
data/spec/CHANGELOG.md
ADDED
data/spec/CONTRIBUTORS
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Christian Herweg - christian.herweg@otto.de
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/spec/DEVELOPER.md
ADDED
data/spec/Gemfile
ADDED
data/spec/LICENSE
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
2
|
+
you may not use this file except in compliance with the License.
|
3
|
+
You may obtain a copy of the License at
|
4
|
+
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
10
|
+
See the License for the specific language governing permissions and
|
11
|
+
limitations under the License.
|
data/spec/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
10
|
+
|
11
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
13
|
+
|
14
|
+
## Need Help?
|
15
|
+
|
16
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
17
|
+
|
18
|
+
## Developing
|
19
|
+
|
20
|
+
### 1. Plugin Developement and Testing
|
21
|
+
|
22
|
+
#### Code
|
23
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
24
|
+
|
25
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
26
|
+
|
27
|
+
- Install dependencies
|
28
|
+
```sh
|
29
|
+
bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Test
|
33
|
+
|
34
|
+
- Update your dependencies
|
35
|
+
|
36
|
+
```sh
|
37
|
+
bundle install
|
38
|
+
```
|
39
|
+
|
40
|
+
- Run tests
|
41
|
+
|
42
|
+
```sh
|
43
|
+
bundle exec rspec
|
44
|
+
```
|
45
|
+
|
46
|
+
### 2. Running your unpublished Plugin in Logstash
|
47
|
+
|
48
|
+
#### 2.1 Run in a local Logstash clone
|
49
|
+
|
50
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
51
|
+
```ruby
|
52
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
53
|
+
```
|
54
|
+
- Install plugin
|
55
|
+
```sh
|
56
|
+
bin/logstash-plugin install --no-verify
|
57
|
+
```
|
58
|
+
- Run Logstash with your plugin
|
59
|
+
```sh
|
60
|
+
bin/logstash -e 'filter {awesome {}}'
|
61
|
+
```
|
62
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
63
|
+
|
64
|
+
#### 2.2 Run in an installed Logstash
|
65
|
+
|
66
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
67
|
+
|
68
|
+
- Build your plugin gem
|
69
|
+
```sh
|
70
|
+
gem build logstash-filter-awesome.gemspec
|
71
|
+
```
|
72
|
+
- Install the plugin from the Logstash home
|
73
|
+
```sh
|
74
|
+
bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
|
75
|
+
```
|
76
|
+
- Start Logstash and proceed to test the plugin
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
81
|
+
|
82
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
83
|
+
|
84
|
+
It is more important to the community that you are able to contribute.
|
85
|
+
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
data/spec/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "logstash/devutils/rake"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require_relative '../spec_helper'
|
3
|
+
require "logstash/filters/varnishlog"
|
4
|
+
|
5
|
+
describe LogStash::Filters::Varnishlog do
|
6
|
+
describe "Set to Hello World" do
|
7
|
+
let(:config) do <<-CONFIG
|
8
|
+
filter {
|
9
|
+
varnishlog {
|
10
|
+
message => "Hello World"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
CONFIG
|
14
|
+
end
|
15
|
+
|
16
|
+
sample("message" => "some text") do
|
17
|
+
expect(subject).to include("message")
|
18
|
+
expect(subject.get('message')).to eq('Hello World')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/filters/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
|
5
|
+
# This filter reads a varnishlog grouped by reqid
|
6
|
+
# message field with whatever you specify in the configuration.
|
7
|
+
#
|
8
|
+
# It is only intended to be used as an .
|
9
|
+
class LogStash::Filters::Varnishlog < LogStash::Filters::Base
|
10
|
+
|
11
|
+
# Setting the config_name here is required. This is how you
|
12
|
+
# See https://varnish-cache.org/docs/trunk/reference/varnishlog.html
|
13
|
+
#
|
14
|
+
# filter {
|
15
|
+
# {
|
16
|
+
# varnishlog {}
|
17
|
+
# }
|
18
|
+
# }
|
19
|
+
#
|
20
|
+
config_name "varnishlog"
|
21
|
+
|
22
|
+
# Replace the message with this value.
|
23
|
+
#config :message, :validate => :string, :default => "Hello World!"
|
24
|
+
|
25
|
+
|
26
|
+
public
|
27
|
+
def register
|
28
|
+
# Add instance variables
|
29
|
+
end # def register
|
30
|
+
|
31
|
+
public
|
32
|
+
def filter(event)
|
33
|
+
items = event.get("[message]").split("\n")
|
34
|
+
##timestamps
|
35
|
+
timestamps = items.grep(/Timestamp/)
|
36
|
+
timestamps.each do |timestamp|
|
37
|
+
if match = /-\s+Timestamp\s+(?<step>.*): (?<time_a>.*) (?<time_b>.*) (?<time_c>.*)/.match(timestamp)
|
38
|
+
event.set("timestamp_" + match['step'], match['time_a'])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
## VCL Log
|
42
|
+
vcl_log = items.grep(/VCL_Log/)
|
43
|
+
vcl_log.each do |log|
|
44
|
+
if match = /-\s+VCL_Log\s+(?<log_line>.*)/.match(log)
|
45
|
+
(log_lines ||= []).push(match['log_line'])
|
46
|
+
event.set("VCL_Log", log_lines)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Requests
|
51
|
+
## Request headers.
|
52
|
+
request_headers = items.grep(/ReqHeader/)
|
53
|
+
request_headers.each do |header|
|
54
|
+
if match = /-\s+ReqHeader\s+(?<header_name>.*): (?<header_value>.*)/.match(header)
|
55
|
+
event.set(match['header_name'], match['header_value'])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
## Match ReqMethod.
|
59
|
+
if method_match = /-\s+ReqMethod\s+(?<method>.*)/.match(items.grep(/ReqMethod/)[0])
|
60
|
+
event.set("http-method", method_match['method'])
|
61
|
+
end
|
62
|
+
## Match ReqURL.
|
63
|
+
if url_match = /-\s+ReqURL\s+(?<url>\/.*)/.match(items.grep(/ReqURL/)[0])
|
64
|
+
event.set("url", url_match['url'])
|
65
|
+
end
|
66
|
+
## Match ReqProtocol.
|
67
|
+
if protocol_match = /-\s+ReqProtocol\s+(?<protocol>.*)/.match(items.grep(/ReqProtocol/)[0])
|
68
|
+
event.set("ReqProtocol", protocol_match['protocol'])
|
69
|
+
end
|
70
|
+
|
71
|
+
# Response
|
72
|
+
## Response headers.
|
73
|
+
response_headers = items.grep(/RespHeader/)
|
74
|
+
response_headers.each do |header|
|
75
|
+
if match = /-\s+RespHeader\s+(?<header_name>.*): (?<header_value>.*)/.match(header)
|
76
|
+
event.set(match['header_name'], match['header_value'])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
## Match RespProtocol
|
80
|
+
if protocol_match = /-\s+RespProtocol\s+(?<protocol>.*)/.match(items.grep(/RespProtocol/)[0])
|
81
|
+
event.set("RespProtocol", protocol_match['protocol'])
|
82
|
+
end
|
83
|
+
## Match RespStatus
|
84
|
+
if status_match = /-\s+RespStatus\s+(?<status>.*)/.match(items.grep(/RespStatus/)[0])
|
85
|
+
event.set("RespStatus", status_match['status'].to_i)
|
86
|
+
end
|
87
|
+
## Match RespReason
|
88
|
+
response_reason = items.grep(/RespReason/)
|
89
|
+
response_reason.each do |reason|
|
90
|
+
if match = /-\s+RespReason\s+(?<reason>.*)/.match(reason)
|
91
|
+
(reasons ||= []).push(match['reason'])
|
92
|
+
event.set("RespReason", reasons)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
if @message
|
97
|
+
# Replace the event message with our message as configured in the
|
98
|
+
# config file.
|
99
|
+
event.set("message", @message)
|
100
|
+
end
|
101
|
+
|
102
|
+
# filter_matched should go in the last line of our successful code
|
103
|
+
filter_matched(event)
|
104
|
+
end # def filter
|
105
|
+
end # class LogStash::Filters::Varnishlog
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'headers'
|
4
|
+
|
5
|
+
#
|
6
|
+
# VarnishLog::Request - This class is used to create objects that represent HTTP
|
7
|
+
# requests from Varnish's perspective.
|
8
|
+
#
|
9
|
+
|
10
|
+
class VarnishLog
|
11
|
+
class Request < Headers
|
12
|
+
@methods = [:method, :url, :protocol]
|
13
|
+
@methods.each do |method|
|
14
|
+
attr_accessor method
|
15
|
+
end
|
16
|
+
|
17
|
+
# Assume the powers of Headers.
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'headers'
|
4
|
+
|
5
|
+
#
|
6
|
+
# VarnishLog::Response - This class is used to create objects that represent HTTP
|
7
|
+
# responses from Varnish's perspective.
|
8
|
+
#
|
9
|
+
|
10
|
+
class VarnishLog
|
11
|
+
class Response < Headers
|
12
|
+
|
13
|
+
# Assume the powers of Headers.
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-filter-varnishlog'
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.licenses = ['Apache License (2.0)']
|
5
|
+
s.summary = 'A logstash plugin reading varnishlog output'
|
6
|
+
s.description = 'logstash filter plugin reading varnishlog grouped by id'
|
7
|
+
s.homepage = 'https://github.com/cherweg/logstash-filter-varnishlog'
|
8
|
+
s.authors = ['Christian Herweg']
|
9
|
+
s.email = 'christian.herweg@gmail.com'
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
22
|
+
s.add_development_dependency 'logstash-devutils'
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-filter-varnishlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christian Herweg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.0'
|
19
|
+
name: logstash-core-plugin-api
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: logstash-devutils
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: logstash filter plugin reading varnishlog grouped by id
|
42
|
+
email: christian.herweg@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- CHANGELOG.md
|
48
|
+
- CONTRIBUTORS
|
49
|
+
- DEVELOPER.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- lib/logstash/filters/varnishlog.rb
|
54
|
+
- lib/logstash/filters/varnishlog/request.rb
|
55
|
+
- lib/logstash/filters/varnishlog/response.rb
|
56
|
+
- logstash-filter-varnishlog.gemspec
|
57
|
+
- spec/CHANGELOG.md
|
58
|
+
- spec/CONTRIBUTORS
|
59
|
+
- spec/DEVELOPER.md
|
60
|
+
- spec/Gemfile
|
61
|
+
- spec/LICENSE
|
62
|
+
- spec/README.md
|
63
|
+
- spec/Rakefile
|
64
|
+
- spec/filters/varnishlog_spec.rb
|
65
|
+
- spec/lib/logstash/filters/varnishlog.rb
|
66
|
+
- spec/lib/logstash/filters/varnishlog/request.rb
|
67
|
+
- spec/lib/logstash/filters/varnishlog/response.rb
|
68
|
+
- spec/logstash-filter-varnishlog-0.1.0.gem
|
69
|
+
- spec/logstash-filter-varnishlog.gemspec
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
homepage: https://github.com/cherweg/logstash-filter-varnishlog
|
72
|
+
licenses:
|
73
|
+
- Apache License (2.0)
|
74
|
+
metadata:
|
75
|
+
logstash_plugin: 'true'
|
76
|
+
logstash_group: filter
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A logstash plugin reading varnishlog output
|
97
|
+
test_files:
|
98
|
+
- spec/CHANGELOG.md
|
99
|
+
- spec/CONTRIBUTORS
|
100
|
+
- spec/DEVELOPER.md
|
101
|
+
- spec/Gemfile
|
102
|
+
- spec/LICENSE
|
103
|
+
- spec/README.md
|
104
|
+
- spec/Rakefile
|
105
|
+
- spec/filters/varnishlog_spec.rb
|
106
|
+
- spec/lib/logstash/filters/varnishlog.rb
|
107
|
+
- spec/lib/logstash/filters/varnishlog/request.rb
|
108
|
+
- spec/lib/logstash/filters/varnishlog/response.rb
|
109
|
+
- spec/logstash-filter-varnishlog-0.1.0.gem
|
110
|
+
- spec/logstash-filter-varnishlog.gemspec
|
111
|
+
- spec/spec_helper.rb
|