Skip to content

Instantly share code, notes, and snippets.

@wiibaa
Last active March 18, 2016 09:38
Show Gist options
  • Select an option

  • Save wiibaa/de3f84c138919faa3b0c to your computer and use it in GitHub Desktop.

Select an option

Save wiibaa/de3f84c138919faa3b0c to your computer and use it in GitHub Desktop.

Revisions

  1. wiibaa revised this gist Mar 18, 2016. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions generated-date.asciidoc
    Original file line number Diff line number Diff line change
    @@ -202,8 +202,8 @@ Here's what you can use to parse dates and times:

    [horizontal]
    y:: year
    yy::: two-digit year. Example: `2015`.
    yyyy::: full year number. Example: `15` for the year 2015.
    yyyy::: full year number. Example: `2015`.
    yy::: two-digit year. Example: `15` for the year 2015.

    M:: month of the year
    M::: minimal-digit month. Example: `1` for January and `12` for December.
    @@ -355,4 +355,3 @@ Canonical ID is good as it takes care of daylight saving time for you
    For example, `America/Los_Angeles` or `Europe/Paris` are valid IDs.
    This field can be dynamic and include parts of the event using the `%{field}` syntax


  2. wiibaa revised this gist Mar 18, 2016. 1 changed file with 65 additions and 67 deletions.
    132 changes: 65 additions & 67 deletions generated-date.asciidoc
    Original file line number Diff line number Diff line change
    @@ -160,6 +160,40 @@ an english parser will also be used as a fallback mechanism.
    * Value type is <<array,array>>
    * Default value is `[]`

    An array with field name first, and format patterns following, `[ field,
    formats... ]`

    If your time field has multiple possible formats, you can do this:
    [source,ruby]
    match => [ "logdate", "MMM dd YYY HH:mm:ss",
    "MMM d YYY HH:mm:ss", "ISO8601" ]

    The above will match a syslog (rfc3164) or `iso8601` timestamp.

    There are a few special exceptions. The following format literals exist
    to help you save time and ensure correctness of date parsing.

    * `ISO8601` - should parse any valid ISO8601 timestamp, such as
    `2011-04-19T03:44:01.103Z`
    * `UNIX` - will parse *float or int* value expressing unix time in seconds since epoch like 1326149001.132 as well as 1326149001
    * `UNIX_MS` - will parse **int** value expressing unix time in milliseconds since epoch like 1366125117000
    * `TAI64N` - will parse tai64n time values

    For example, if you have a field `logdate`, with a value that looks like
    `Aug 13 2010 00:03:44`, you would use this configuration:
    [source,ruby]
    filter {
    date {
    match => [ "logdate", "MMM dd YYYY HH:mm:ss" ]
    }
    }

    If your field is nested in your structure, you can use the nested
    syntax `[foo][bar]` to match its value. For more information, please refer to
    <<logstash-config-field-references>>

    *More details on the syntax*

    The syntax used for parsing date and time text uses letters to indicate the
    kind of time value (month, minute, etc), and a repetition of letters to
    indicate the form of that value (2-digit month, full month name, etc).
    @@ -168,97 +202,60 @@ Here's what you can use to parse dates and times:

    [horizontal]
    y:: year
    The full year number, such as 2015.
    +
    Special cases:
    yy::: 2-digit year, such as 15 for the year 2015.

    yy::: two-digit year. Example: `2015`.
    yyyy::: full year number. Example: `15` for the year 2015.

    M:: month of the year
    M::: Single-digit month. `1` for January.
    MM::: Two-digit month; zero-padded. `01` for January.
    MMM::: Abbreviated month text. `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
    MMMM::: Full month text, `January`. Note: The language used depends on your locale.
    M::: minimal-digit month. Example: `1` for January and `12` for December.
    MM::: two-digit month. zero-padded if needed. Example: `01` for January and `12` for December
    MMM::: abbreviated month text. Example: `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
    MMMM::: full month text, Example: `January`. Note: The language used depends on your locale.

    d:: day of the month
    d::: single-digit day. `1` for the 1st of the month.
    dd::: two-digit day. `01` for the 1st of the month.
    d::: minimal-digit day. Example: `1` for the 1st of the month.
    dd::: two-digit day, zero-padded if needed. Example: `01` for the 1st of the month.

    H:: hour of the day (24-hour clock)
    H::: hour. `0` for midnight.
    HH::: two-digit hour, zero-padded if needed. Example: `00` for midnight
    H::: minimal-digit hour. Example: `0` for midnight.
    HH::: two-digit hour, zero-padded if needed. Example: `00` for midnight.

    m:: minutes of the hour (60 minutes per hour)
    m::: minutes. `0`
    mm::: two-digit minutes, zero-padded if needed. Example: `00
    m::: minimal-digit minutes. Example: `0`.
    mm::: two-digit minutes, zero-padded if needed. Example: `00`.

    s:: seconds of the minute (60 seconds per minute)
    s::: seconds. `0`
    ss::: two-digit seconds, zero-padded if needed. Example: `00`
    s::: minimal-digit seconds. Example: `0`.
    ss::: two-digit seconds, zero-padded if needed. Example: `00`.

    S:: fraction of a second
    Maximum precision is milliseconds (`SSS`). Beyond that, zeroes are appended.
    S::: tenths of a second `0` for a subsecond value `012`
    SS::: hundredths of a second `01` for a subsecond value `01`
    SSS::: thousandths of a second `012` for a subsecond value `012`
    *Maximum precision is milliseconds (`SSS`). Beyond that, zeroes are appended.*
    S::: tenths of a second. Example: `0` for a subsecond value `012`
    SS::: hundredths of a second. Example: `01` for a subsecond value `01`
    SSS::: thousandths of a second. Example: `012` for a subsecond value `012`

    Z:: time zone offset or identity
    Z::: Timezone offset structured as HHmm (hour and minutes offset from Zulu/UTC). Example: -0700
    ZZ::: Timezone offset structured as HH:mm (colon in between hour and minute offsets). Example: -07:00
    ZZZ::: Timezone identity, such as "America/Los_Angeles"
    Z::: Timezone offset structured as HHmm (hour and minutes offset from Zulu/UTC). Example: `-0700`.
    ZZ::: Timezone offset structured as HH:mm (colon in between hour and minute offsets). Example: `-07:00`.
    ZZZ::: Timezone identity. Example: `America/Los_Angeles`. Note: Valid IDs are listed on the http://joda-time.sourceforge.net/timezones.html[Joda.org available time zones page].

    z:: time zone description or abbreviation
    z, zz, zzz::: Time zone abbreviation. Examples: PDT, CEST, GMT, UTC.
    zzzz::; Time zone text description. Examples: Pacific Standard Time
    z:: time zone names. *Time zone names ('z') cannot be parsed.*

    w:: week of the year
    w::: week.
    ww::: two-digit week, zero-padded if needed. Example: `01`
    w::: minimal-digit week. Example: `1`.
    ww::: two-digit week, zero-padded if needed. Example: `01`.

    D:: day of the year
    The number of the day of the year.

    e:: day of the week (number)

    E:: day of the week (text)
    E, EE, EEE:: Abbreviated day of the week (Mon, Tue, Wed, Thu, Fri, Sat, Sun). The actual language of this will depend on your locale.
    EEEE:: The full text day of the week (Monday, Tuesday, ...). The actual language of this will depend on your locale.
    E, EE, EEE::: Abbreviated day of the week. Example: `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat`, `Sun`. Note: The actual language of this will depend on your locale.
    EEEE::: The full text day of the week. Example: `Monday`, `Tuesday`, ... Note: The actual language of this will depend on your locale.

    For non-formatting syntax, you'll need to put single-quote characters around the value. For example, if you were parsing ISO8601 time, "2015-01-01T01:12:23" that little "T" isn't a valid time format, and you want to say "literally, a T", your format would be this: "yyyy-MM-dd'T'HH:mm:ss"

    Other less common date units, such as era (G), century (C), am/pm (a), and # more, can be learned about on the
    http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html[joda-time # DateTimeFormat] docs

    An array with field name first, and format patterns following, `[ field,
    formats... ]`

    If your time field has multiple possible formats, you can do this:
    [source,ruby]
    match => [ "logdate", "MMM dd YYY HH:mm:ss",
    "MMM d YYY HH:mm:ss", "ISO8601" ]

    The above will match a syslog (rfc3164) or `iso8601` timestamp.

    There are a few special exceptions. The following format literals exist
    to help you save time and ensure correctness of date parsing.

    * `ISO8601` - should parse any valid ISO8601 timestamp, such as
    `2011-04-19T03:44:01.103Z`
    * `UNIX` - will parse *float or int* value expressing unix time in seconds since epoch like 1326149001.132 as well as 1326149001
    * `UNIX_MS` - will parse **int** value expressing unix time in milliseconds since epoch like 1366125117000
    * `TAI64N` - will parse tai64n time values

    For example, if you have a field `logdate`, with a value that looks like
    `Aug 13 2010 00:03:44`, you would use this configuration:
    [source,ruby]
    filter {
    date {
    match => [ "logdate", "MMM dd YYYY HH:mm:ss" ]
    }
    }

    If your field is nested in your structure, you can use the nested
    syntax `[foo][bar]` to match its value. For more information, please refer to
    <<logstash-config-field-references>>
    Other less common date units, such as era (G), century \(C), am/pm (a), and # more, can be learned about on the
    http://www.joda.org/joda-time/key_format.html[joda-time documentation].

    [[plugins-filters-date-periodic_flush]]
    ===== `periodic_flush`
    @@ -358,3 +355,4 @@ Canonical ID is good as it takes care of daylight saving time for you
    For example, `America/Los_Angeles` or `Europe/Paris` are valid IDs.
    This field can be dynamic and include parts of the event using the `%{field}` syntax


  3. wiibaa created this gist Mar 8, 2016.
    360 changes: 360 additions & 0 deletions generated-date.asciidoc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,360 @@
    [[plugins-filters-date]]
    === date



    The date filter is used for parsing dates from fields, and then using that
    date or timestamp as the logstash timestamp for the event.

    For example, syslog events usually have timestamps like this:
    [source,ruby]
    "Apr 17 09:32:01"

    You would use the date format `MMM dd HH:mm:ss` to parse this.

    The date filter is especially important for sorting events and for
    backfilling old data. If you don't get the date correct in your
    event, then searching for them later will likely sort out of order.

    In the absence of this filter, logstash will choose a timestamp based on the
    first time it sees the event (at input time), if the timestamp is not already
    set in the event. For example, with file input, the timestamp is set to the
    time of each read.

    &nbsp;

    ==== Synopsis

    This plugin supports the following configuration options:


    Required configuration options:

    [source,json]
    --------------------------
    date {
    }
    --------------------------



    Available configuration options:

    [cols="<,<,<,<m",options="header",]
    |=======================================================================
    |Setting |Input type|Required|Default value
    | <<plugins-filters-date-add_field>> |<<hash,hash>>|No|`{}`
    | <<plugins-filters-date-add_tag>> |<<array,array>>|No|`[]`
    | <<plugins-filters-date-enable_metric>> |<<boolean,boolean>>|No|`true`
    | <<plugins-filters-date-id>> |<<string,string>>|No|
    | <<plugins-filters-date-locale>> |<<string,string>>|No|
    | <<plugins-filters-date-match>> |<<array,array>>|No|`[]`
    | <<plugins-filters-date-periodic_flush>> |<<boolean,boolean>>|No|`false`
    | <<plugins-filters-date-remove_field>> |<<array,array>>|No|`[]`
    | <<plugins-filters-date-remove_tag>> |<<array,array>>|No|`[]`
    | <<plugins-filters-date-tag_on_failure>> |<<array,array>>|No|`["_dateparsefailure"]`
    | <<plugins-filters-date-target>> |<<string,string>>|No|`"@timestamp"`
    | <<plugins-filters-date-timezone>> |<<string,string>>|No|
    |=======================================================================



    ==== Details

    &nbsp;

    [[plugins-filters-date-add_field]]
    ===== `add_field`

    * Value type is <<hash,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:
    [source,ruby]
    filter {
    date {
    add_field => { "foo_%{somefield}" => "Hello world, from %{host}" }
    }
    }
    [source,ruby]
    # You can also add multiple fields at once:
    filter {
    date {
    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.

    [[plugins-filters-date-add_tag]]
    ===== `add_tag`

    * Value type is <<array,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:
    [source,ruby]
    filter {
    date {
    add_tag => [ "foo_%{somefield}" ]
    }
    }
    [source,ruby]
    # You can also add multiple tags at once:
    filter {
    date {
    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).

    [[plugins-filters-date-enable_metric]]
    ===== `enable_metric`

    * Value type is <<boolean,boolean>>
    * Default value is `true`



    [[plugins-filters-date-id]]
    ===== `id`

    * Value type is <<string,string>>
    * There is no default value for this setting.



    [[plugins-filters-date-locale]]
    ===== `locale`

    * Value type is <<string,string>>
    * There is no default value for this setting.

    Specify a locale to be used for date parsing using either IETF-BCP47 or POSIX language tag.
    Simple examples are `en`,`en-US` for BCP47 or `en_US` for POSIX.

    The locale is mostly necessary to be set for parsing month names (pattern with `MMM`) and
    weekday names (pattern with `EEE`).

    If not specified, the platform default will be used but for non-english platform default
    an english parser will also be used as a fallback mechanism.

    [[plugins-filters-date-match]]
    ===== `match`

    * Value type is <<array,array>>
    * Default value is `[]`

    The syntax used for parsing date and time text uses letters to indicate the
    kind of time value (month, minute, etc), and a repetition of letters to
    indicate the form of that value (2-digit month, full month name, etc).

    Here's what you can use to parse dates and times:

    [horizontal]
    y:: year
    The full year number, such as 2015.
    +
    Special cases:
    yy::: 2-digit year, such as 15 for the year 2015.

    M:: month of the year
    M::: Single-digit month. `1` for January.
    MM::: Two-digit month; zero-padded. `01` for January.
    MMM::: Abbreviated month text. `Jan` for January. Note: The language used depends on your locale. See the `locale` setting for how to change the language.
    MMMM::: Full month text, `January`. Note: The language used depends on your locale.

    d:: day of the month
    d::: single-digit day. `1` for the 1st of the month.
    dd::: two-digit day. `01` for the 1st of the month.

    H:: hour of the day (24-hour clock)
    H::: hour. `0` for midnight.
    HH::: two-digit hour, zero-padded if needed. Example: `00` for midnight

    m:: minutes of the hour (60 minutes per hour)
    m::: minutes. `0`
    mm::: two-digit minutes, zero-padded if needed. Example: `00

    s:: seconds of the minute (60 seconds per minute)
    s::: seconds. `0`
    ss::: two-digit seconds, zero-padded if needed. Example: `00`

    S:: fraction of a second
    Maximum precision is milliseconds (`SSS`). Beyond that, zeroes are appended.
    S::: tenths of a second `0` for a subsecond value `012`
    SS::: hundredths of a second `01` for a subsecond value `01`
    SSS::: thousandths of a second `012` for a subsecond value `012`

    Z:: time zone offset or identity
    Z::: Timezone offset structured as HHmm (hour and minutes offset from Zulu/UTC). Example: -0700
    ZZ::: Timezone offset structured as HH:mm (colon in between hour and minute offsets). Example: -07:00
    ZZZ::: Timezone identity, such as "America/Los_Angeles"

    z:: time zone description or abbreviation
    z, zz, zzz::: Time zone abbreviation. Examples: PDT, CEST, GMT, UTC.
    zzzz::; Time zone text description. Examples: Pacific Standard Time

    w:: week of the year
    w::: week.
    ww::: two-digit week, zero-padded if needed. Example: `01`

    D:: day of the year
    The number of the day of the year.

    e:: day of the week (number)

    E:: day of the week (text)
    E, EE, EEE:: Abbreviated day of the week (Mon, Tue, Wed, Thu, Fri, Sat, Sun). The actual language of this will depend on your locale.
    EEEE:: The full text day of the week (Monday, Tuesday, ...). The actual language of this will depend on your locale.

    For non-formatting syntax, you'll need to put single-quote characters around the value. For example, if you were parsing ISO8601 time, "2015-01-01T01:12:23" that little "T" isn't a valid time format, and you want to say "literally, a T", your format would be this: "yyyy-MM-dd'T'HH:mm:ss"

    Other less common date units, such as era (G), century (C), am/pm (a), and # more, can be learned about on the
    http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html[joda-time # DateTimeFormat] docs

    An array with field name first, and format patterns following, `[ field,
    formats... ]`

    If your time field has multiple possible formats, you can do this:
    [source,ruby]
    match => [ "logdate", "MMM dd YYY HH:mm:ss",
    "MMM d YYY HH:mm:ss", "ISO8601" ]

    The above will match a syslog (rfc3164) or `iso8601` timestamp.

    There are a few special exceptions. The following format literals exist
    to help you save time and ensure correctness of date parsing.

    * `ISO8601` - should parse any valid ISO8601 timestamp, such as
    `2011-04-19T03:44:01.103Z`
    * `UNIX` - will parse *float or int* value expressing unix time in seconds since epoch like 1326149001.132 as well as 1326149001
    * `UNIX_MS` - will parse **int** value expressing unix time in milliseconds since epoch like 1366125117000
    * `TAI64N` - will parse tai64n time values

    For example, if you have a field `logdate`, with a value that looks like
    `Aug 13 2010 00:03:44`, you would use this configuration:
    [source,ruby]
    filter {
    date {
    match => [ "logdate", "MMM dd YYYY HH:mm:ss" ]
    }
    }

    If your field is nested in your structure, you can use the nested
    syntax `[foo][bar]` to match its value. For more information, please refer to
    <<logstash-config-field-references>>

    [[plugins-filters-date-periodic_flush]]
    ===== `periodic_flush`

    * Value type is <<boolean,boolean>>
    * Default value is `false`

    Call the filter flush method at regular interval.
    Optional.

    [[plugins-filters-date-remove_field]]
    ===== `remove_field`

    * Value type is <<array,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:
    [source,ruby]
    filter {
    date {
    remove_field => [ "foo_%{somefield}" ]
    }
    }
    [source,ruby]
    # You can also remove multiple fields at once:
    filter {
    date {
    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.

    [[plugins-filters-date-remove_tag]]
    ===== `remove_tag`

    * Value type is <<array,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:
    [source,ruby]
    filter {
    date {
    remove_tag => [ "foo_%{somefield}" ]
    }
    }
    [source,ruby]
    # You can also remove multiple tags at once:
    filter {
    date {
    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.

    [[plugins-filters-date-tag_on_failure]]
    ===== `tag_on_failure`

    * Value type is <<array,array>>
    * Default value is `["_dateparsefailure"]`

    Append values to the `tags` field when there has been no
    successful match

    [[plugins-filters-date-target]]
    ===== `target`

    * Value type is <<string,string>>
    * Default value is `"@timestamp"`

    Store the matching timestamp into the given target field. If not provided,
    default to updating the `@timestamp` field of the event.

    [[plugins-filters-date-timezone]]
    ===== `timezone`

    * Value type is <<string,string>>
    * There is no default value for this setting.

    Specify a time zone canonical ID to be used for date parsing.
    The valid IDs are listed on the http://joda-time.sourceforge.net/timezones.html[Joda.org available time zones page].
    This is useful in case the time zone cannot be extracted from the value,
    and is not the platform default.
    If this is not specified the platform default will be used.
    Canonical ID is good as it takes care of daylight saving time for you
    For example, `America/Los_Angeles` or `Europe/Paris` are valid IDs.
    This field can be dynamic and include parts of the event using the `%{field}` syntax