Skip to main content

Auto Timestamp

Date and Time Cribl Compatible

Synopsis

Tries an ordered list of regex / strptime rules against src_field, parses the first rule that both matches and falls within the configured bounds, and writes the resulting instant to dst_field. auto_timestamp is the native implementation of Cribl's Auto Timestamp function.

Schema

- auto_timestamp:
timestamps:
- regex: <string>
strptime: <string>
src_field: <ident>
dst_field: <ident>
time_expression: <script>
max_len: <integer>
default_time: <string>
earliest_date_allowed: <string>
latest_date_allowed: <string>
default_timezone: <string>
filter: <script>
tag: <string>
description: <text>
if: <script>
disabled: <boolean>
ignore_failure: <boolean>
on_failure: <processor[]>
on_success: <processor[]>

Configuration

FieldRequiredDefaultDescription
timestampsYOrdered list of regex / strptime rules. Tried in order; the first rule that both matches and parses within bounds wins.
src_fieldN_rawLog entry field read as the source text.
dst_fieldN_timeLog entry field the resolved instant is written to.
time_expressionNtime.getTime() / 1000JavaScript expression evaluated against a time Date binding. Left at its default, the processor takes a fast path that writes plain epoch seconds without any JavaScript evaluation.
max_lenN150Truncates src_field (by rune count) before any rule is tried.
default_timeNOnly the exact value now (case-insensitive, trimmed) writes the current time when no rule matched. Any other value, including leaving it unset, leaves dst_field untouched.
earliest_date_allowedNRelative offset only (e.g. -420weeks), never an absolute date. An unparseable value is silently ignored — no lower bound is applied.
latest_date_allowedNRelative offset only (e.g. +1week), never an absolute date. An unparseable value is silently ignored — no upper bound is applied.
default_timezoneNIANA time zone name that re-anchors a parsed wall-clock time. An unresolvable zone is silently ignored, and the field is skipped entirely when the winning rule's strptime format already carries absolute offset/epoch information.
filterNCribl-style JavaScript truthiness expression evaluated after if. A falsy result silently skips the processor. Distinct from if, which uses the native expression language.
tagNIdentifier for this processor instance.
descriptionNExplanatory note.
ifNCondition that must be true for the processor to run.
disabledNfalseWhen true, the processor is skipped.
ignore_failureNfalseContinue pipeline processing if the processor fails.
on_failureNProcessors to run when this processor fails.
on_successNProcessors to run when this processor passes an event through.

Timestamps

FieldRequiredDefaultDescription
regexYPattern used to locate the timestamp substring within src_field. Either a bare pattern (applied with no flags) or a /pattern/flags delimited literal. Supported flags: i, m, s, u — a g flag, if present, has no effect, since only the first match is ever used. Uses capture group 1 (JS/left-to-right numbering) when the pattern has one, otherwise the whole match.
strptimeYC/d3-style format string (e.g. %a %b %d %H:%M:%S %Y, %Y-%m-%d, %s) used to parse the text regex located.

Details

auto_timestamp is the native implementation of Cribl's Auto Timestamp function. timestamps is tried in declaration order against src_field (truncated to max_len runes first): for each rule, regex must match and the text it locates must parse under strptime and fall within earliest_date_allowed/latest_date_allowed. The first rule that satisfies all three wins and stops the search; every other rule is left untried.

A rule whose regex doesn't match src_field, whose matched text doesn't parse under strptime, or whose parsed time falls outside the configured bounds is not a processor failure — it is simply not a match, and the next rule in timestamps is tried. Only a genuinely malformed regex spec, a missing or non-string src_field, or a time_expression compile/evaluation failure fails the processor (see below).

earliest_date_allowed and latest_date_allowed accept relative offsets only, never absolute dates: a leading + or - sign, one or more digits, optional whitespace, then one of week, weeks, day, days, hour, hours (e.g. -420weeks, +1 week). Each bound is evaluated independently against the current time at the moment the processor runs; a value that doesn't match this grammar (including an absolute date string) is silently ignored, imposing no constraint on that side rather than raising an error.

If no rule in timestamps matches within bounds, default_time decides the outcome: only the value now, compared case-insensitively after trimming whitespace, writes the current time to dst_field. Any other value — an absolute date, a typo, or leaving the field unset entirely — leaves dst_field untouched, with no error raised.

default_timezone re-anchors a parsed wall-clock reading into the named IANA zone. strptime always parses in UTC, so the parsed year/month/day/hour/minute/second digits are, by default, treated as UTC; setting default_timezone reinterprets those same digits as local time in the given zone instead, producing a different absolute instant. An unresolvable zone name is silently ignored, leaving the UTC-parsed instant unchanged. default_timezone is skipped entirely — regardless of whether it resolves — when the winning rule's strptime format contains %z, %Z, %s, or %Q: each of these directives already pins the parse to a genuine absolute instant (an explicit offset or an epoch value), so re-anchoring it into another zone would silently shift the timestamp rather than leave an already-unambiguous instant alone.

time_expression controls how the resolved instant is written to dst_field. The fast path — writing plain epoch seconds as a number, with no JavaScript involved — triggers only when time_expression is left empty or set to the exact literal time.getTime() / 1000 (trimmed of leading/trailing whitespace only; an equivalent but differently-spaced expression such as time.getTime()/1000 does not qualify). Any other value is compiled and evaluated as a JavaScript expression against a time binding — a genuine JS Date object constructed from the resolved instant — and whatever the expression returns is written to dst_field verbatim, whether that's a number, a string, or any other JS value. A time_expression that fails to compile or evaluate fails the processor.

filter provides the same Cribl-style JavaScript truthiness gate available on other Cribl-compatible processors such as Rewrite. It is evaluated after if; a falsy result skips the processor entirely without an error, leaving the event unmodified. filter is not a universal field available on every processor. time_expression shares its underlying JavaScript expression engine with Eval, though each processor maintains its own compiled-expression cache.

A missing or non-string src_field fails the processor with an error of the form auto_timestamp: source field "<field>": <error> or auto_timestamp: source field "<field>" is not a string. A malformed regex spec in any rule fails with auto_timestamp: regex "<pattern>": <error>. A time_expression compile or evaluation failure fails with auto_timestamp: time_expression "<expr>": <error>.

Examples

Basic Timestamp Extraction

Locating a ctime-style timestamp inside a raw log line and parsing it with a matching strptime format...

{
"_raw": "Log line: Mon Jan 02 15:04:05 2006 end"
}
- auto_timestamp:
timestamps:
- regex: "\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4}"
strptime: "%a %b %d %H:%M:%S %Y"

The rule matches and parses; time_expression is left at its default, so the fast path writes plain epoch seconds to _time...

{
"_raw": "Log line: Mon Jan 02 15:04:05 2006 end",
"_time": 1136214245
}

Silently Skipped default_time Value

Setting default_time to a value other than the exact literal now when no rule matches...

{
"_raw": "no timestamp in here at all"
}
- auto_timestamp:
timestamps:
- regex: "\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4}"
strptime: "%a %b %d %H:%M:%S %Y"
default_time: none

No rule matches and default_time isn't now, so _time is never written — this is not a processor failure...

{
"_raw": "no timestamp in here at all"
}

Relative Date Bounds Reject an Out-of-Range Match

Bounding matches to within a week of now using relative offsets — the 2006 date in _raw falls far outside that window...

{
"_raw": "Log line: Mon Jan 02 15:04:05 2006 end"
}
- auto_timestamp:
timestamps:
- regex: "\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4}"
strptime: "%a %b %d %H:%M:%S %Y"
earliest_date_allowed: "-1weeks"
latest_date_allowed: "+1week"
default_time: none

The rule matches and parses, but the result falls outside the bounds — treated as a non-match, not a failure — and default_time isn't now, so _time is left unset...

{
"_raw": "Log line: Mon Jan 02 15:04:05 2006 end"
}

Custom time_expression

Extracting just the year from the parsed instant with a custom time_expression against the time Date binding...

{
"_raw": "Log line: Mon Jan 02 15:04:05 2006 end"
}
- auto_timestamp:
timestamps:
- regex: "\\w{3} \\w{3} \\d{2} \\d{2}:\\d{2}:\\d{2} \\d{4}"
strptime: "%a %b %d %H:%M:%S %Y"
time_expression: "time.getUTCFullYear()"

Since time_expression differs from the default, it's compiled and evaluated as JavaScript; the expression's return value is written to _time verbatim...

{
"_raw": "Log line: Mon Jan 02 15:04:05 2006 end",
"_time": 2006
}

default_timezone Re-anchors a Timezone-less Timestamp

Parsing a timestamp with no timezone information, then re-anchoring its wall-clock digits as local time in Europe/Amsterdam...

{
"_raw": "2016-04-25 12:02:01"
}
- auto_timestamp:
timestamps:
- regex: "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}"
strptime: "%Y-%m-%d %H:%M:%S"
default_timezone: "Europe/Amsterdam"
time_expression: "time.toISOString()"

strptime parses the digits as UTC by default; default_timezone reinterprets them as Amsterdam local time (CEST, UTC+2 in April), shifting the resolved instant back to 10:02:01 UTC...

{
"_raw": "2016-04-25 12:02:01",
"_time": "2016-04-25T10:02:01.000Z"
}

Epoch Directive Ignores default_timezone

Parsing an epoch-seconds value with %s while default_timezone is also set...

{
"_raw": "1752148800"
}
- auto_timestamp:
timestamps:
- regex: "\\d+"
strptime: "%s"
default_timezone: "America/New_York"

%s already pins the parse to an absolute instant, so default_timezone is skipped entirely; the epoch value passes through unchanged on the fast path...

{
"_raw": "1752148800",
"_time": 1752148800
}