- Logstash Reference: other versions:
- Logstash Reference
- Logstash Introduction
- Getting Started with Logstash
- Package Repositories
- Breaking changes
- Upgrading Logstash
- Configuring Logstash
- Working with plugins
- Logstash Plugins Community Maintainer Guide
- Contributing to Logstash
- Input plugins
- beats
- couchdb_changes
- drupal_dblog
- elasticsearch
- exec
- eventlog
- file
- ganglia
- gelf
- generator
- graphite
- github
- heartbeat
- heroku
- http
- http_poller
- irc
- imap
- jdbc
- jmx
- kafka
- log4j
- lumberjack
- meetup
- pipe
- puppet_facter
- relp
- rss
- rackspace
- rabbitmq
- redis
- salesforce
- snmptrap
- stdin
- sqlite
- s3
- sqs
- stomp
- syslog
- tcp
- unix
- udp
- varnishlog
- wmi
- websocket
- xmpp
- zenoss
- zeromq
- Output plugins
- boundary
- circonus
- csv
- cloudwatch
- datadog
- datadog_metrics
- elasticsearch
- elasticsearch_java
- exec
- file
- google_bigquery
- google_cloud_storage
- ganglia
- gelf
- graphtastic
- graphite
- hipchat
- http
- irc
- influxdb
- juggernaut
- jira
- kafka
- lumberjack
- librato
- loggly
- mongodb
- metriccatcher
- nagios
- null
- nagios_nsca
- opentsdb
- pagerduty
- pipe
- riemann
- redmine
- rackspace
- rabbitmq
- redis
- riak
- s3
- sqs
- stomp
- statsd
- solr_http
- sns
- syslog
- stdout
- tcp
- udp
- webhdfs
- websocket
- xmpp
- zabbix
- zeromq
- Filter plugins
- aggregate
- alter
- anonymize
- collate
- csv
- cidr
- clone
- cipher
- checksum
- date
- de_dot
- dns
- drop
- elasticsearch
- extractnumbers
- environment
- elapsed
- fingerprint
- geoip
- grok
- i18n
- json
- json_encode
- kv
- mutate
- metrics
- multiline
- metaevent
- prune
- punct
- ruby
- range
- syslog_pri
- sleep
- split
- throttle
- translate
- uuid
- urldecode
- useragent
- xml
- zeromq
- Codec plugins
- Logstash 2.1 Release Notes
kv
editkv
editThis filter helps automatically parse messages (or specific event fields)
which are of the foo=bar
variety.
For example, if you have a log message which contains ip=1.2.3.4
error=REFUSED
, you can parse those automatically by configuring:
filter { kv { } }
The above will result in a message of ip=1.2.3.4 error=REFUSED
having
the fields:
-
ip: 1.2.3.4
-
error: REFUSED
This is great for postfix, iptables, and other types of logs that
tend towards key=value
syntax.
You can configure any arbitrary strings to split your data on,
in case your data is not structured using =
signs and whitespace.
For example, this filter can also be used to parse query parameters like
foo=bar&baz=fizz
by setting the field_split
parameter to &
.
Synopsis
editThis plugin supports the following configuration options:
Required configuration options:
kv { }
Available configuration options:
Setting | Input type | Required | Default value |
---|---|---|---|
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|
||
No |
|||
No |
|||
No |
|||
No |
|
Details
edit
add_field
edit- Value type is hash
-
Default value is
{}
If this filter is successful, add any arbitrary fields to this event.
Field names can be dynamic and include parts of the event using the %{field}
.
Example:
filter { kv { add_field => { "foo_%{somefield}" => "Hello world, from %{host}" } } } [source,ruby] # You can also add multiple fields at once: filter { kv { add_field => { "foo_%{somefield}" => "Hello world, from %{host}" "new_field" => "new_static_value" } } }
If the event has field "somefield" == "hello"
this filter, on success,
would add field foo_hello
if it is present, with the
value above and the %{host}
piece replaced with that value from the
event. The second example would also add a hardcoded field.
add_tag
edit- Value type is array
-
Default value is
[]
If this filter is successful, add arbitrary tags to the event.
Tags can be dynamic and include parts of the event using the %{field}
syntax.
Example:
filter { kv { add_tag => [ "foo_%{somefield}" ] } } [source,ruby] # You can also add multiple tags at once: filter { kv { add_tag => [ "foo_%{somefield}", "taggedy_tag"] } }
If the event has field "somefield" == "hello"
this filter, on success,
would add a tag foo_hello
(and the second example would of course add a taggedy_tag
tag).
allow_duplicate_values
edit- Value type is boolean
-
Default value is
true
A bool option for removing duplicate key/value pairs. When set to false, only one unique key/value pair will be preserved.
For example, consider a source like from=me from=me
. [from]
will map to
an Array with two elements: ["me", "me"]
. to only keep unique key/value pairs,
you could use this configuration:
filter { kv { allow_duplicate_values => false } }
default_keys
edit- Value type is hash
-
Default value is
{}
A hash specifying the default keys and their values which should be added to the event in case these keys do not exist in the source field being parsed.
filter { kv { default_keys => [ "from", "logstash@example.com", "to", "default@dev.null" ] } }
exclude_keys
edit- Value type is array
-
Default value is
[]
An array specifying the parsed keys which should not be added to the event. By default no keys will be excluded.
For example, consider a source like Hey, from=<abc>, to=def foo=bar
.
To exclude from
and to
, but retain the foo
key, you could use this configuration:
filter { kv { exclude_keys => [ "from", "to" ] } }
Example with URL Query Strings
editFor example, to split out the args from a url query string such as
?pin=12345~0&d=123&e=foo@bar.com&oq=bobo&ss=12345
:
filter { kv { field_split => "&?" } }
The above splits on both &
and ?
characters, giving you the following
fields:
-
pin: 12345~0
-
d: 123
-
e: foo@bar.com
-
oq: bobo
-
ss: 12345
include_brackets
edit- Value type is boolean
-
Default value is
true
A boolean specifying whether to include brackets as value wrappers
(the default is true)
filter { kv { include_brackets => true } }
For example, the result of this line:
bracketsone=(hello world) bracketstwo=[hello world]
will be: * bracketsone: hello world * bracketstwo: hello world
instead of: * bracketsone: (hello * bracketstwo: [hello
include_keys
edit- Value type is array
-
Default value is
[]
An array specifying the parsed keys which should be added to the event. By default all keys will be added.
For example, consider a source like Hey, from=<abc>, to=def foo=bar
.
To include from
and to
, but exclude the foo
key, you could use this configuration:
filter { kv { include_keys => [ "from", "to" ] } }
periodic_flush
edit- Value type is boolean
-
Default value is
false
Call the filter flush method at regular interval. Optional.
prefix
edit- Value type is string
-
Default value is
""
A string to prepend to all of the extracted keys.
For example, to prepend arg_ to all keys:
filter { kv { prefix => "arg_" } }
recursive
edit- Value type is boolean
-
Default value is
false
A boolean specifying whether to drill down into values and recursively get more key-value pairs from it. The extra key-value pairs will be stored as subkeys of the root key.
Default is not to recursive values.
filter { kv { recursive => "true" } }
remove_field
edit- Value type is array
-
Default value is
[]
If this filter is successful, remove arbitrary fields from this event. Fields names can be dynamic and include parts of the event using the %{field} Example:
filter { kv { remove_field => [ "foo_%{somefield}" ] } } [source,ruby] # You can also remove multiple fields at once: filter { kv { remove_field => [ "foo_%{somefield}", "my_extraneous_field" ] } }
If the event has field "somefield" == "hello"
this filter, on success,
would remove the field with name foo_hello
if it is present. The second
example would remove an additional, non-dynamic field.
remove_tag
edit- Value type is array
-
Default value is
[]
If this filter is successful, remove arbitrary tags from the event.
Tags can be dynamic and include parts of the event using the %{field}
syntax.
Example:
filter { kv { remove_tag => [ "foo_%{somefield}" ] } } [source,ruby] # You can also remove multiple tags at once: filter { kv { remove_tag => [ "foo_%{somefield}", "sad_unwanted_tag"] } }
If the event has field "somefield" == "hello"
this filter, on success,
would remove the tag foo_hello
if it is present. The second example
would remove a sad, unwanted tag as well.
source
edit- Value type is string
-
Default value is
"message"
The field to perform key=value
searching on
For example, to process the not_the_message
field:
filter { kv { source => "not_the_message" } }
target
edit- Value type is string
- There is no default value for this setting.
The name of the container to put all of the key-value pairs into.
If this setting is omitted, fields will be written to the root of the event, as individual fields.
For example, to place all keys into the event field kv:
filter { kv { target => "kv" } }
trim
edit- Value type is string
- There is no default value for this setting.
A string of characters to trim from the value. This is useful if your values are wrapped in brackets or are terminated with commas (like postfix logs).
These characters form a regex character class and thus you must escape special regex
characters like [
or ]
using \
.
For example, to strip <
, >
, [
, ]
and ,
characters from values:
filter { kv { trim => "<>\[\]," } }
trimkey
edit- Value type is string
- There is no default value for this setting.
A string of characters to trim from the key. This is useful if your keys are wrapped in brackets or start with space.
These characters form a regex character class and thus you must escape special regex
characters like [
or ]
using \
.
For example, to strip <
>
[
]
and ,
characters from keys:
filter { kv { trimkey => "<>\[\]," } }
value_split
edit- Value type is string
-
Default value is
"="
A string of characters to use as delimiters for identifying key-value relations.
These characters form a regex character class and thus you must escape special regex
characters like [
or ]
using \
.
For example, to identify key-values such as
key1:value1 key2:value2
:
filter { kv { value_split => ":" } }
On this page