Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
| <<plugins-{type}s-{plugin}-concatenate_all_fields>> |<<boolean,boolean>>|No
| <<plugins-{type}s-{plugin}-ecs_compatibility>> | <<string,string>>|No
| <<plugins-{type}s-{plugin}-key>> |<<string,string>>|No
| <<plugins-{type}s-{plugin}-method>> |<<string,string>>, one of `["SHA1", "SHA256", "SHA384", "SHA512", "MD5", "MURMUR3", "IPV4_NETWORK", "UUID", "PUNCTUATION"]`|Yes
| <<plugins-{type}s-{plugin}-method>> |<<string,string>>, one of `["SHA1", "SHA256", "SHA384", "SHA512", "MD5", "MURMUR3", "IPV4_NETWORK", "IPV6_NETWORK", "UUID", "PUNCTUATION"]`|Yes
| <<plugins-{type}s-{plugin}-source>> |<<array,array>>|No
| <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
|=======================================================================
Expand Down Expand Up @@ -167,14 +167,14 @@ See <<plugins-{type}s-{plugin}-ecs_metadata>> for detailed information.
* Value type is <<string,string>>
* There is no default value for this setting.

When used with the `IPV4_NETWORK` method fill in the subnet prefix length.
When used with the `IPV4_NETWORK` or `IPV6_NETWORK` method fill in the subnet prefix length.
With other methods, optionally fill in the HMAC key.

[id="plugins-{type}s-{plugin}-method"]
===== `method`

* This is a required setting.
* Value can be any of: `SHA1`, `SHA256`, `SHA384`, `SHA512`, `MD5`, `MURMUR3`, `IPV4_NETWORK`, `UUID`, `PUNCTUATION`
* Value can be any of: `SHA1`, `SHA256`, `SHA384`, `SHA512`, `MD5`, `MURMUR3`, `IPV4_NETWORK`, `IPV6_NETWORK`, `UUID`, `PUNCTUATION`
* Default value is `"SHA1"`

The fingerprint method to use.
Expand All @@ -190,6 +190,11 @@ the hash value will be the masked-out address using the number of bits
specified in the `key` option. For example, with "1.2.3.4" as the input
and `key` set to 16, the hash becomes "1.2.0.0".

If set to `IPV6_NETWORK` the input data needs to be a IPv6 address and
the hash value will be the masked-out address using the number of bits
specified in the `key` option. For example, with "2001:db8:85a3::8a2e:370:7334" as the input
and `key` set to 112, the hash becomes "2001:db8:85a3::8a2e:370:0".

If set to `PUNCTUATION`, all non-punctuation characters will be removed
from the input string.

Expand Down
11 changes: 8 additions & 3 deletions lib/logstash/filters/fingerprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
# Any current contents of that field will be overwritten.
config :target, :validate => :string

# When used with the `IPV4_NETWORK` method fill in the subnet prefix length.
# When used with the `IPV4_NETWORK` or `IPV6_NETWORK` method fill in the subnet prefix length.
# With other methods, optionally fill in the HMAC key.
config :key, :validate => :string

Expand All @@ -58,13 +58,18 @@ class LogStash::Filters::Fingerprint < LogStash::Filters::Base
# specified in the `key` option. For example, with "1.2.3.4" as the input
# and `key` set to 16, the hash becomes "1.2.0.0".
#
# If set to `IPV6_NETWORK` the input data needs to be a IPv6 address and
# the hash value will be the masked-out address using the number of bits
# specified in the `key` option. For example, with "2001:db8:85a3::8a2e:370:7334" as the input
# and `key` set to 112, the hash becomes "2001:db8:85a3::8a2e:370:0".
#
# If set to `PUNCTUATION`, all non-punctuation characters will be removed
# from the input string.
#
# If set to `UUID`, a
# https://en.wikipedia.org/wiki/Universally_unique_identifier[UUID] will
# be generated. The result will be random and thus not a consistent hash.
config :method, :validate => ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5', "MURMUR3", "IPV4_NETWORK", "UUID", "PUNCTUATION"], :required => true, :default => 'SHA1'
config :method, :validate => ['SHA1', 'SHA256', 'SHA384', 'SHA512', 'MD5', "MURMUR3", "IPV4_NETWORK", "IPV6_NETWORK", "UUID", "PUNCTUATION"], :required => true, :default => 'SHA1'

# When set to `true` and `method` isn't `UUID` or `PUNCTUATION`, the
# plugin concatenates the names and values of all fields given in the
Expand All @@ -90,7 +95,7 @@ def register

# require any library and set the fingerprint function
case @method
when :IPV4_NETWORK
when :IPV4_NETWORK, :IPV6_NETWORK
if @key.nil?
raise LogStash::ConfigurationError, I18n.t(
"logstash.runner.configuration.invalid_plugin_register",
Expand Down
10 changes: 10 additions & 0 deletions spec/filters/fingerprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
end
end

describe "the IPV6_NETWORK method" do
let(:data) { {"clientip" => "2001:db8:85a3::8a2e:370:7334" } }
let(:fingerprint_method) { "IPV6_NETWORK" }
let(:config) { super().merge("key" => 112) }

it "fingerprints the ip as the network" do
expect(fingerprint).to eq("2001:db8:85a3::8a2e:370:0")
end
end

describe "the MURMUR3 method" do
let(:fingerprint_method) { "MURMUR3" }

Expand Down