VRL function reference
Here you’ll find a comprehensive list of all built-in VRL functions. Functions are categorized by their purpose and sorted alphabetically for easy discovery. To use these functions in Vector, see the documentation on function call expressions and Vector’s remap transform.
Array functions
append
infallible pureitems array to the end of the value array.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The initial array. | yes | |
| items | array | The items to append. | yes |
Examples
Append to an array
append([1, 2], [3, 4])[1,2,3,4]chunks
fallible purevalue into slices of length chunk_size bytes.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The array of bytes to split. | yes | |
| chunk_size | integer | The desired length of each chunk in bytes. This may be constrained by the host platform architecture. | yes |
Errors
Thechunks function is fallible, which means that
error handling is required for these errors:chunk_size must be at least 1 byte.chunk_size is too large.Examples
Split a string into chunks
chunks("abcdefgh", 4)["abcd","efgh"]Chunks do not respect unicode code point boundaries
chunks("ab你好", 4)["ab�","�好"]pop
infallible purevalue array.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The target array. | yes |
Examples
Pop an item from an array
pop([1, 2, 3])[1,2]push
infallible pureitem to the end of the value array.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The target array. | yes | |
| item | any | The item to push. | yes |
Examples
Push an item onto an array
push([1, 2], 3)[1,2,3]Empty array
push([], "bar")["bar"]zip
fallible pureIterate over several arrays in parallel, producing a new array containing arrays of items from each source.
The resulting array will be as long as the shortest input array, with all the remaining elements dropped.
This function is modeled from the zip function in Python,
but similar methods can be found in Ruby
and Rust.
If a single parameter is given, it must contain an array of all the input arrays.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| array_0 | array | The first array of elements, or the array of input arrays if no other parameter is present. | yes | |
| array_1 | array | The second array of elements. If not present, the first parameter contains all the arrays. | no |
Errors
Thezip function is fallible, which means that
error handling is required for these errors:array_0 and array_1 must be arrays.Examples
Merge two arrays
zip([1, 2, 3], [4, 5, 6, 7])[[1,4],[2,5],[3,6]]Merge three arrays
zip([[1, 2], [3, 4], [5, 6]])[[1,3,5],[2,4,6]]Merge an array of three arrays into an array of 3-tuples
zip([["a", "b", "c"], [1, null, true], [4, 5, 6]])[["a",1,4],["b",null,5],["c",true,6]]Merge two array parameters
zip([1, 2, 3, 4], [5, 6, 7])[[1,5],[2,6],[3,7]]Codec functions
decode_base16
fallible purevalue (a Base16 string) into its original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Base16 data to decode. | yes |
Errors
Thedecode_base16 function is fallible, which means that
error handling is required for these errors:value isn’t a valid encoded Base16 string.Examples
Decode Base16 data
decode_base16!("736F6D6520737472696E672076616C7565")some string valueDecode longer Base16 data
decode_base16!("796f752068617665207375636365737366756c6c79206465636f646564206d65")you have successfully decoded medecode_base64
fallible purevalue (a Base64 string) into its original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Base64 data to decode. | yes | |
| charset | string | The character set to use when decoding the data. | standard | no |
Errors
Thedecode_base64 function is fallible, which means that
error handling is required for these errors:value isn’t a valid encoded Base64 string.Examples
Decode Base64 data (default)
decode_base64!("eW91IGhhdmUgc3VjY2Vzc2Z1bGx5IGRlY29kZWQgbWU=")you have successfully decoded meDecode Base64 data (URL safe)
decode_base64!("eW91IGNhbid0IG1ha2UgeW91ciBoZWFydCBmZWVsIHNvbWV0aGluZyBpdCB3b24ndA==", charset: "url_safe")you can't make your heart feel something it won'tdecode_charset
fallible purevalue (a non-UTF8 string) to a UTF8 string using the specified
character set.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The non-UTF8 string to decode. | yes | |
| from_charset | string | The character set to use when decoding the data. | yes |
Errors
Thedecode_charset function is fallible, which means that
error handling is required for these errors:from_charset isn’t a valid character set.Examples
Decode EUC-KR string
decode_charset!(decode_base64!("vsiz58fPvLy/5A=="), "euc-kr")안녕하세요Decode EUC-JP string
decode_charset!(decode_base64!("pLOk86TLpMGkzw=="), "euc-jp")こんにちはDecode GB2312 string
decode_charset!(decode_base64!("xOO6ww=="), "gb2312")你好decode_gzip
fallible purevalue (a Gzip string) into its original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Gzip data to decode. | yes |
Errors
Thedecode_gzip function is fallible, which means that
error handling is required for these errors:value isn’t a valid encoded Gzip string.Examples
Decode Gzip data
decode_gzip!(decode_base64!("H4sIAB8BymMAAyvISU0sTlVISU3OT0lVyE0FAJsZ870QAAAA"))please decode medecode_lz4
fallible purevalue (an lz4 string) into its original string. buf_size is the size of the buffer to decode into, this must be equal to or larger than the uncompressed size.
If prepended_size is set to true, it expects the original uncompressed size to be prepended to the compressed data.
prepended_size is useful for some implementations of lz4 that require the original size to be known before decoding.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The lz4 block data to decode. | yes | |
| buf_size | integer | The size of the buffer to decode into, this must be equal to or larger than the uncompressed size. | 1000000 | no |
| prepended_size | boolean | Some implementations of lz4 require the original uncompressed size to be prepended to the compressed data. | false | no |
Errors
Thedecode_lz4 function is fallible, which means that
error handling is required for these errors:value unable to decode value with lz4 frame decoder.value unable to decode value with lz4 block decoder.value unable to decode because the output is too large for the buffer.value unable to decode because the prepended size is not a valid integer.Examples
LZ4 block with prepended size
decode_lz4!(decode_base64!("LAAAAPAdVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIDEzIGxhenkgZG9ncy4="), prepended_size: true)The quick brown fox jumps over 13 lazy dogs.Decode Lz4 data without prepended size.
decode_lz4!(decode_base64!("BCJNGGBAgiwAAIBUaGUgcXVpY2sgYnJvd24gZm94IGp1bXBzIG92ZXIgMTMgbGF6eSBkb2dzLgAAAAA="))The quick brown fox jumps over 13 lazy dogs.decode_mime_q
fallible purevalue with their original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string with encoded-words to decode. | yes |
Errors
Thedecode_mime_q function is fallible, which means that
error handling is required for these errors:value has invalid encoded encoded-word string.Examples
Decode single encoded-word
decode_mime_q!("=?utf-8?b?SGVsbG8sIFdvcmxkIQ==?=")Hello, World!Embedded
decode_mime_q!("From: =?utf-8?b?SGVsbG8sIFdvcmxkIQ==?= <=?utf-8?q?hello=5Fworld=40example=2ecom?=>")From: Hello, World! <hello_world@example.com>Without charset
decode_mime_q!("?b?SGVsbG8sIFdvcmxkIQ==")Hello, World!decode_percent
infallible purevalue like a URL.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to decode. | yes |
Examples
Percent decode a value
decode_percent("foo%20bar%3F")foo bar?decode_punycode
fallible purevalue, such as an internationalized domain name (IDN). This function assumes that the value passed is meant to be used in IDN context and that it is either a domain name or a part of it.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to decode. | yes | |
| validate | boolean | If enabled, checks if the input string is a valid domain name. | true | no |
Errors
Thedecode_punycode function is fallible, which means that
error handling is required for these errors:value is not valid punycodeExamples
Decode a punycode encoded internationalized domain name
decode_punycode!("www.xn--caf-dma.com")www.café.comDecode an ASCII only string
decode_punycode!("www.cafe.com")www.cafe.comIgnore validation
decode_punycode!("xn--8hbb.xn--fiba.xn--8hbf.xn--eib.", validate: false)١٠.٦٦.٣٠.٥.decode_snappy
fallible purevalue (a Snappy string) into its original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Snappy data to decode. | yes |
Errors
Thedecode_snappy function is fallible, which means that
error handling is required for these errors:value isn’t a valid encoded Snappy string.Examples
Decode Snappy data
decode_snappy!(decode_base64!("LKxUaGUgcXVpY2sgYnJvd24gZm94IGp1bXBzIG92ZXIgMTMgbGF6eSBkb2dzLg=="))The quick brown fox jumps over 13 lazy dogs.decode_zlib
fallible purevalue (a Zlib string) into its original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Zlib data to decode. | yes |
Errors
Thedecode_zlib function is fallible, which means that
error handling is required for these errors:value isn’t a valid encoded Zlib string.Examples
Decode Zlib data
decode_zlib!(decode_base64!("eJxLzUvOT0mNz00FABI5A6A="))encode_medecode_zstd
fallible purevalue (a Zstandard string) into its original string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Zstandard data to decode. | yes |
Errors
Thedecode_zstd function is fallible, which means that
error handling is required for these errors:value isn’t a valid encoded Zstd string.Examples
Decode Zstd data
decode_zstd!(decode_base64!("KLUv/QBY/QEAYsQOFKClbQBedqXsb96EWDax/f/F/z+gNU4ZTInaUeAj82KqPFjUzKqhcfDqAIsLvAsnY1bI/N2mHzDixRQA"))you_have_successfully_decoded_me.congratulations.you_are_breathtaking.encode_base16
infallible purevalue to Base16.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes |
Examples
Encode to Base16
encode_base16("some string value")736f6d6520737472696e672076616c7565encode_base64
infallible purevalue to Base64.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| padding | boolean | Whether the Base64 output is padded. | true | no |
| charset | string | The character set to use when encoding the data. | standard | no |
Examples
Encode to Base64 (default)
encode_base64("please encode me")cGxlYXNlIGVuY29kZSBtZQ==Encode to Base64 (without padding)
encode_base64("please encode me, no padding though", padding: false)cGxlYXNlIGVuY29kZSBtZSwgbm8gcGFkZGluZyB0aG91Z2gEncode to Base64 (URL safe)
encode_base64("please encode me, but safe for URLs", charset: "url_safe")cGxlYXNlIGVuY29kZSBtZSwgYnV0IHNhZmUgZm9yIFVSTHM=Encode to Base64 (without padding and URL safe)
encode_base64("some string value", padding: false, charset: "url_safe")c29tZSBzdHJpbmcgdmFsdWUencode_charset
fallible purevalue (a UTF8 string) to a non-UTF8 string using the specified
character set.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The UTF8 string to encode. | yes | |
| to_charset | string | The character set to use when encoding the data. | yes |
Errors
Theencode_charset function is fallible, which means that
error handling is required for these errors:to_charset isn’t a valid character set.Examples
Encode UTF8 string to EUC-KR
encode_base64(encode_charset!("안녕하세요", "euc-kr"))vsiz58fPvLy/5A==Encode UTF8 string to EUC-JP
encode_base64(encode_charset!("こんにちは", "euc-jp"))pLOk86TLpMGkzw==Encode UTF8 string to GB2312
encode_base64(encode_charset!("你好", "gb2312"))xOO6ww==encode_gzip
infallible purevalue to Gzip.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| compression_level | integer | The default compression level. | 6 | no |
Examples
Encode to Gzip
encode_base64(encode_gzip("please encode me"))H4sIAAAAAAAA/yvISU0sTlVIzUvOT0lVyE0FAI4R4vcQAAAAencode_json
infallible purevalue to JSON.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to convert to a JSON string. | yes | |
| pretty | boolean | Whether to pretty print the JSON string or not. | false | no |
Examples
Encode object to JSON
encode_json({"field": "value", "another": [1,2,3]})s'{"another":[1,2,3],"field":"value"}'Encode object to as pretty-printed JSON
encode_json({"field": "value", "another": [1,2,3]}, true){
"another": [
1,
2,
3
],
"field": "value"
}encode_key_value
fallible purevalue into key-value format with customizable delimiters. Default delimiters match the logfmt format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The value to convert to a string. | yes | |
| fields_ordering | array | The ordering of fields to preserve. Any fields not in this list are listed unordered, after all ordered fields. | [] | no |
| key_value_delimiter | string | The string that separates the key from the value. | = | no |
| field_delimiter | string | The string that separates each key-value pair. | | no |
| flatten_boolean | boolean | Whether to encode key-value with a boolean value as a standalone key if true and nothing if false. | false | no |
Notices
This function has special behavior that you should be aware of.fields_ordering is specified then the function is fallible else it is infallible.Errors
Theencode_key_value function is fallible, which means that
error handling is required for these errors:fields_ordering contains a non-string element.Examples
Encode with default delimiters (no ordering)
encode_key_value(
{
"ts": "2021-06-05T17:20:00Z",
"msg": "This is a message",
"lvl": "info"
}
)
lvl=info msg="This is a message" ts=2021-06-05T17:20:00ZEncode with default delimiters (fields ordering)
encode_key_value!(
{
"ts": "2021-06-05T17:20:00Z",
"msg": "This is a message",
"lvl": "info",
"log_id": 12345
},
["ts", "lvl", "msg"]
)
ts=2021-06-05T17:20:00Z lvl=info msg="This is a message" log_id=12345Encode with default delimiters (nested fields)
encode_key_value(
{
"agent": {"name": "foo"},
"log": {"file": {"path": "my.log"}},
"event": "log"
}
)
agent.name=foo event=log log.file.path=my.logEncode with default delimiters (nested fields ordering)
encode_key_value!(
{
"agent": {"name": "foo"},
"log": {"file": {"path": "my.log"}},
"event": "log"
},
["event", "log.file.path", "agent.name"])
event=log log.file.path=my.log agent.name=fooEncode with custom delimiters (no ordering)
encode_key_value(
{"ts": "2021-06-05T17:20:00Z", "msg": "This is a message", "lvl": "info"},
field_delimiter: ",",
key_value_delimiter: ":"
)
lvl:info,msg:"This is a message",ts:2021-06-05T17:20:00ZEncode with custom delimiters and flatten boolean
encode_key_value(
{"ts": "2021-06-05T17:20:00Z", "msg": "This is a message", "lvl": "info", "beta": true, "dropped": false},
field_delimiter: ",",
key_value_delimiter: ":",
flatten_boolean: true
)
beta,lvl:info,msg:"This is a message",ts:2021-06-05T17:20:00Zencode_logfmt
fallible purevalue to logfmt.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The value to convert to a logfmt string. | yes | |
| fields_ordering | array | The ordering of fields to preserve. Any fields not in this list are listed unordered, after all ordered fields. | [] | no |
Notices
This function has special behavior that you should be aware of.fields_ordering is specified then the function is fallible else it is infallible.Errors
Theencode_logfmt function is fallible, which means that
error handling is required for these errors:fields_ordering contains a non-string element.Examples
Encode to logfmt (no ordering)
encode_logfmt({"ts": "2021-06-05T17:20:00Z", "msg": "This is a message", "lvl": "info"})lvl=info msg="This is a message" ts=2021-06-05T17:20:00ZEncode to logfmt (fields ordering)
encode_logfmt!({"ts": "2021-06-05T17:20:00Z", "msg": "This is a message", "lvl": "info", "log_id": 12345}, ["ts", "lvl", "msg"])ts=2021-06-05T17:20:00Z lvl=info msg="This is a message" log_id=12345Encode to logfmt (nested fields)
encode_logfmt({"agent": {"name": "foo"}, "log": {"file": {"path": "my.log"}}, "event": "log"})agent.name=foo event=log log.file.path=my.logEncode to logfmt (nested fields ordering)
encode_logfmt!({"agent": {"name": "foo"}, "log": {"file": {"path": "my.log"}}, "event": "log"}, ["event", "log.file.path", "agent.name"])event=log log.file.path=my.log agent.name=fooencode_lz4
infallible purevalue to Lz4. This function compresses the
input string into an lz4 block. If prepend_size is set to true, it prepends the
original uncompressed size to the compressed data. This is useful for some
implementations of lz4 that require the original size to be known before decoding.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| prepend_size | boolean | Whether to prepend the original size to the compressed data. | true | no |
Examples
Encode to Lz4
encode_base64(encode_lz4!("The quick brown fox jumps over 13 lazy dogs.", true))LAAAAPAdVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIDEzIGxhenkgZG9ncy4=encode_percent
infallible purevalue with percent encoding to safely be used in URLs.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| ascii_set | string | The ASCII set to use when encoding the data. | NON_ALPHANUMERIC | no |
Examples
Percent encode all non-alphanumeric characters (default)
encode_percent("foo bar?")foo%20bar%3FPercent encode only control characters
encode_percent("foo \tbar", ascii_set: "CONTROLS")foo %09barPercent encode special characters
encode_percent("foo@bar?")foo%40bar%3Fencode_proto
fallible purevalue into a protocol buffer payload.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The object to convert to a protocol buffer payload. | yes | |
| desc_file | string | The path to the protobuf descriptor set file. Must be a literal string. This file is the output of protoc -o | yes | |
| message_type | string | The name of the message type to use for serializing. Must be a literal string. | yes |
Errors
Theencode_proto function is fallible, which means that
error handling is required for these errors:desc_file file does not exist.message_type message type does not exist in the descriptor file.Examples
Encode to proto
encode_base64(encode_proto!({ "name": "someone", "phones": [{"number": "123456"}]}, "test_protobuf.desc", "test_protobuf.v1.Person"))Cgdzb21lb25lIggKBjEyMzQ1Ng==encode_punycode
fallible purevalue to punycode. Useful for internationalized domain names (IDN). This function assumes that the value passed is meant to be used in IDN context and that it is either a domain name or a part of it.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| validate | boolean | Whether to validate the input string to check if it is a valid domain name. | true | no |
Errors
Theencode_punycode function is fallible, which means that
error handling is required for these errors:value can not be encoded to punycodeExamples
Encode an internationalized domain name
encode_punycode!("www.café.com")www.xn--caf-dma.comEncode an internationalized domain name with mixed case
encode_punycode!("www.CAFé.com")www.xn--caf-dma.comEncode an ASCII only string
encode_punycode!("www.cafe.com")www.cafe.comIgnore validation
encode_punycode!("xn--8hbb.xn--fiba.xn--8hbf.xn--eib.", validate: false)xn--8hbb.xn--fiba.xn--8hbf.xn--eib.encode_snappy
fallible purevalue to Snappy.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes |
Errors
Theencode_snappy function is fallible, which means that
error handling is required for these errors:value cannot be encoded into a Snappy string.Examples
Encode to Snappy
encode_base64(encode_snappy!("The quick brown fox jumps over 13 lazy dogs."))LKxUaGUgcXVpY2sgYnJvd24gZm94IGp1bXBzIG92ZXIgMTMgbGF6eSBkb2dzLg==encode_zlib
infallible purevalue to Zlib.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| compression_level | integer | The default compression level. | 6 | no |
Examples
Encode to Zlib
encode_base64(encode_zlib("please encode me"))eJwryElNLE5VSM1Lzk9JVchNBQA0RQX7encode_zstd
infallible purevalue to Zstandard.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to encode. | yes | |
| compression_level | integer | The default compression level. | 3 | no |
Examples
Encode to Zstd
encode_base64(encode_zstd("please encode me"))KLUv/QBYgQAAcGxlYXNlIGVuY29kZSBtZQ==Coerce functions
to_bool
fallible purevalue into a boolean.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to convert to a Boolean. | yes |
Errors
Theto_bool function is fallible, which means that
error handling is required for these errors:value is not a supported boolean representation.Examples
Coerce to a Boolean (string)
to_bool!("yes")trueCoerce to a Boolean (float)
to_bool(0.0)falseCoerce to a Boolean (int)
to_bool(0)falseCoerce to a Boolean (null)
to_bool(null)falseCoerce to a Boolean (Boolean)
to_bool(true)trueInteger (other)
to_bool(2)trueFloat (other)
to_bool(5.6)trueFalse
to_bool(false)falseTrue string
to_bool!(s'true')trueY string
to_bool!(s'y')trueNon-zero integer string
to_bool!(s'1')trueFalse string
to_bool!(s'false')falseNo string
to_bool!(s'no')falseN string
to_bool!(s'n')falseInvalid string
to_bool!(s'foobar')function call error for "to_bool" at (0:19): Invalid boolean value "foobar"Timestamp
to_bool!(t'2020-01-01T00:00:00Z')function call error for "to_bool" at (0:33): unable to coerce timestamp into booleanArray
to_bool!([])function call error for "to_bool" at (0:12): unable to coerce array into booleanObject
to_bool!({})function call error for "to_bool" at (0:12): unable to coerce object into booleanRegex
to_bool!(r'foo')function call error for "to_bool" at (0:16): unable to coerce regex into booleanto_float
fallible purevalue into a float.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to convert to a float. Must be convertible to a float, otherwise an error is raised. | yes |
Errors
Theto_float function is fallible, which means that
error handling is required for these errors:value is not a supported float representation.Examples
Coerce to a float
to_float!("3.145")3.145Coerce to a float (timestamp)
to_float(t'2020-12-30T22:20:53.824727Z')1609366853.824727Integer
to_float(5)5Float
to_float(5.6)5.6True
to_float(true)1False
to_float(false)0Null
to_float(null)0Invalid string
to_float!(s'foobar')function call error for "to_float" at (0:20): Invalid floating point number "foobar": invalid float literalArray
to_float!([])function call error for "to_float" at (0:13): unable to coerce array into floatObject
to_float!({})function call error for "to_float" at (0:13): unable to coerce object into floatRegex
to_float!(r'foo')function call error for "to_float" at (0:17): unable to coerce regex into floatto_int
fallible purevalue into an integer.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to convert to an integer. | yes |
Errors
Theto_int function is fallible, which means that
error handling is required for these errors:value is a string but the text is not an integer.value is not a string, int, or timestamp.Examples
Coerce to an int (string)
to_int!("2")2Coerce to an int (timestamp)
to_int(t'2020-12-30T22:20:53.824727Z')1609366853Integer
to_int(5)5Float
to_int(5.6)5True
to_int(true)1False
to_int(false)0Null
to_int(null)0Invalid string
to_int!(s'foobar')function call error for "to_int" at (0:18): Invalid integer "foobar": invalid digit found in stringArray
to_int!([])function call error for "to_int" at (0:11): unable to coerce array into integerObject
to_int!({})function call error for "to_int" at (0:11): unable to coerce object into integerRegex
to_int!(r'foo')function call error for "to_int" at (0:15): unable to coerce regex into integerto_regex
fallible purevalue into a regex.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The value to convert to a regex. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theto_regex function is fallible, which means that
error handling is required for these errors:value is not a string.Examples
Coerce to a regex
to_regex!("^foo$")r'^foo$'to_string
fallible purevalue into a string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to convert to a string. | yes |
Errors
Theto_string function is fallible, which means that
error handling is required for these errors:value is not an integer, float, boolean, string, timestamp, or null.Examples
Coerce to a string (Boolean)
to_string(true)s'true'Coerce to a string (int)
to_string(52)s'52'Coerce to a string (float)
to_string(52.2)s'52.2'String
to_string(s'foo')fooFalse
to_string(false)s'false'Null
to_string(null)Timestamp
to_string(t'2020-01-01T00:00:00Z')2020-01-01T00:00:00ZArray
to_string!([])function call error for "to_string" at (0:14): unable to coerce array into stringObject
to_string!({})function call error for "to_string" at (0:14): unable to coerce object into stringRegex
to_string!(r'foo')function call error for "to_string" at (0:18): unable to coerce regex into stringConvert functions
from_unix_timestamp
infallible pureConverts the value integer from a Unix timestamp to a VRL timestamp.
Converts from the number of seconds since the Unix epoch by default. To convert from milliseconds or nanoseconds, set the unit argument to milliseconds or nanoseconds.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer | The Unix timestamp to convert. | yes | |
| unit | string | The time unit. | seconds | no |
Examples
Convert from a Unix timestamp (seconds)
from_unix_timestamp!(5)t'1970-01-01T00:00:05Z'Convert from a Unix timestamp (milliseconds)
from_unix_timestamp!(5000, unit: "milliseconds")t'1970-01-01T00:00:05Z'Convert from a Unix timestamp (microseconds)
from_unix_timestamp!(5000, unit: "microseconds")t'1970-01-01T00:00:00.005Z'Convert from a Unix timestamp (nanoseconds)
from_unix_timestamp!(5000, unit: "nanoseconds")t'1970-01-01T00:00:00.000005Z'to_syslog_facility
fallible purevalue, a Syslog facility code, into its corresponding Syslog keyword. For example, 0 into "kern", 1 into "user", etc.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer | The facility code. | yes |
Errors
Theto_syslog_facility function is fallible, which means that
error handling is required for these errors:value is not a valid Syslog facility code.Examples
Coerce to a Syslog facility
to_syslog_facility!(4)authinvalid
to_syslog_facility!(500)function call error for "to_syslog_facility" at (0:24): facility code 500 not validto_syslog_facility_code
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Syslog facility keyword to convert. | yes |
Errors
Theto_syslog_facility_code function is fallible, which means that
error handling is required for these errors:value is not a valid Syslog facility keyword.Examples
Coerce to Syslog facility code
to_syslog_facility_code!("authpriv")10invalid
to_syslog_facility_code!(s'foobar')function call error for "to_syslog_facility_code" at (0:35): syslog facility 'foobar' not validto_syslog_level
fallible purevalue, a Syslog severity level, into its corresponding keyword, i.e. 0 into "emerg", 1 into "alert", etc.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer | The severity level. | yes |
Errors
Theto_syslog_level function is fallible, which means that
error handling is required for these errors:value isn’t a valid Syslog severity level.Examples
Coerce to a Syslog level
to_syslog_level!(5)noticeinvalid
to_syslog_level!(500)function call error for "to_syslog_level" at (0:21): severity level 500 not validto_syslog_severity
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The Syslog level keyword to convert. | yes |
Errors
Theto_syslog_severity function is fallible, which means that
error handling is required for these errors:value is not a valid Syslog level keyword.Examples
Coerce to Syslog severity
to_syslog_severity!("alert")1invalid
to_syslog_severity!(s'foobar')function call error for "to_syslog_severity" at (0:30): syslog level foobar not validto_unix_timestamp
fallible pureConverts the value timestamp into a Unix timestamp.
Returns the number of seconds since the Unix epoch by default. To return the number in milliseconds or nanoseconds, set the unit argument to milliseconds or nanoseconds.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | timestamp | The timestamp to convert into a Unix timestamp. | yes | |
| unit | string | The time unit. | seconds | no |
Errors
Theto_unix_timestamp function is fallible, which means that
error handling is required for these errors:value cannot be represented in nanoseconds. Result is too large or too small for a 64 bit integer.Examples
Convert to a Unix timestamp (seconds)
to_unix_timestamp(t'2021-01-01T00:00:00+00:00')1609459200Convert to a Unix timestamp (milliseconds)
to_unix_timestamp(t'2021-01-01T00:00:00Z', unit: "milliseconds")1609459200000Convert to a Unix timestamp (microseconds)
to_unix_timestamp(t'2021-01-01T00:00:00Z', unit: "microseconds")1609459200000000Convert to a Unix timestamp (nanoseconds)
to_unix_timestamp(t'2021-01-01T00:00:00Z', unit: "nanoseconds")1609459200000000000Debug functions
assert
fallible impurecondition, which must be a Boolean expression. The program is aborted with message if the condition evaluates to false.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| condition | boolean | The condition to check. | yes | |
| message | string | An optional custom error message. If the equality assertion fails, message is
appended to the default message prefix. See the examples below
for a fully formed log message sample. | no |
Notices
This function has special behavior that you should be aware of.assert function should be used in a standalone fashion and only when you want
to abort the program. You should avoid it in logical expressions and other situations
in which you want the program to continue if the condition evaluates to false.Errors
Theassert function is fallible, which means that
error handling is required for these errors:condition evaluates to false.Examples
Assertion (true) - with message
assert!("foo" == "foo", message: "\"foo\" must be \"foo\"!")trueAssertion (false) - with message
assert!("foo" == "bar", message: "\"foo\" must be \"foo\"!")function call error for "assert" at (0:60): "foo" must be "foo"!Assertion (false) - simple
assert!(false)function call error for "assert" at (0:14): assertion failedassert_eq
infallible impureleft and right, have the same value. The program is aborted with message if they do not have the same value.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| left | any | The value to check for equality against right. | yes | |
| right | any | The value to check for equality against left. | yes | |
| message | string | An optional custom error message. If the equality assertion fails, message is
appended to the default message prefix. See the examples
below for a fully formed log message sample. | no |
Notices
This function has special behavior that you should be aware of.assert_eq function should be used in a standalone fashion and only when you want
to abort the program. You should avoid it in logical expressions and other situations in
which you want the program to continue if the condition evaluates to false.Examples
Successful assertion
assert_eq!(1, 1)trueUnsuccessful assertion
assert_eq!(127, [1, 2, 3])function call error for "assert_eq" at (0:26): assertion failed: 127 == [1, 2, 3]Unsuccessful assertion with custom log message
assert_eq!(1, 0, message: "Unequal integers")function call error for "assert_eq" at (0:45): Unequal integerslog
infallible impureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to log. | yes | |
| level | string | The log level. | info | no |
| rate_limit_secs | integer | Specifies that the log message is output no more than once per the given number of seconds.
Use a value of 0 to turn rate limiting off. | 1 | no |
Examples
Log a message
log("Hello, World!", level: "info", rate_limit_secs: 60)Log an error
. = { "field": "not an integer" }
_, err = to_int(.field)
if err != null {
log(err, level: "error")
}
Enrichment functions
find_enrichment_table_records
infallible pureSearches an enrichment table for rows that match the provided condition.
For file enrichment tables, this condition needs to be a VRL object in which
the key-value pairs indicate a field to search mapped to a value to search in that field.
This function returns the rows that match the provided condition(s). All fields need to
match for rows to be returned; if any fields do not match, then no rows are returned.
There are currently three forms of search criteria:
Exact match search. The given field must match the value exactly. Case sensitivity can be specified using the
case_sensitiveargument. An exact match search can use an index directly into the dataset, which should make this search fairly “cheap” from a performance perspective.Wildcard match search. The given fields specified by the exact match search may also be matched exactly to the value provided to the
wildcardparameter. A wildcard match search can also use an index directly into the dataset.Date range search. The given field must be greater than or equal to the
fromdate and/or less than or equal to thetodate. A date range search involves sequentially scanning through the rows that have been located using any exact match criteria. This can be an expensive operation if there are many rows returned by any exact match criteria. Therefore, use date ranges as the only criteria when the enrichment data set is very small.
For geoip and mmdb enrichment tables, this condition needs to be a VRL object with a single key-value pair
whose value needs to be a valid IP address. Example: {"ip": .ip }. If a return field is expected
and without a value, null is used. This table can return the following fields:
ISP databases:
autonomous_system_numberautonomous_system_organizationisporganization
City databases:
city_namecontinent_codecountry_codecountry_nameregion_coderegion_namemetro_codelatitudelongitudepostal_codetimezone
Connection-Type databases:
connection_type
To use this function, you need to update your configuration to
include an
enrichment_tables
parameter.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| table | string | The enrichment table to search. | yes | |
| condition | object | The condition to search on. Since the condition is used at boot time to create indices into the data, these conditions must be statically defined. | yes | |
| select | array | A subset of fields from the enrichment table to return. If not specified, all fields are returned. | no | |
| case_sensitive | boolean | Whether text fields need to match cases exactly. | true | no |
| wildcard | string | Value to use for wildcard matching in the search. | no |
Examples
Exact match
find_enrichment_table_records!(
"test",
{"surname": "Smith"}
)
[{"firstname":"Bob","id":1,"surname":"Smith"},{"firstname":"Fred","id":2,"surname":"Smith"}]Case insensitive match
find_enrichment_table_records!(
"test",
{"surname": "smith"},
case_sensitive: false
)
[{"firstname":"Bob","id":1,"surname":"Smith"},{"firstname":"Fred","id":2,"surname":"Smith"}]Wildcard match
find_enrichment_table_records!(
"test",
{"firstname": "Bob"},
wildcard: "fred",
case_sensitive: false
)
[{"firstname":"Bob","id":1,"surname":"Smith"},{"firstname":"Fred","id":2,"surname":"Smith"}]Date range search
find_enrichment_table_records!(
"test",
{
"surname": "Smith",
"date_of_birth": {
"from": t'1985-01-01T00:00:00Z',
"to": t'1985-12-31T00:00:00Z'
}
}
)
[{"firstname":"Bob","id":1,"surname":"Smith"},{"firstname":"Fred","id":2,"surname":"Smith"}]get_enrichment_table_record
fallible pureSearches an enrichment table for a row that matches the provided condition. A single row must be matched. If no rows are found or more than one row is found, an error is returned.
For file enrichment tables, this condition needs to be a VRL object in which
the key-value pairs indicate a field to search mapped to a value to search in that field.
This function returns the rows that match the provided condition(s). All fields need to
match for rows to be returned; if any fields do not match, then no rows are returned.
There are currently three forms of search criteria:
Exact match search. The given field must match the value exactly. Case sensitivity can be specified using the
case_sensitiveargument. An exact match search can use an index directly into the dataset, which should make this search fairly “cheap” from a performance perspective.Wildcard match search. The given fields specified by the exact match search may also be matched exactly to the value provided to the
wildcardparameter. A wildcard match search can also use an index directly into the dataset.Date range search. The given field must be greater than or equal to the
fromdate and/or less than or equal to thetodate. A date range search involves sequentially scanning through the rows that have been located using any exact match criteria. This can be an expensive operation if there are many rows returned by any exact match criteria. Therefore, use date ranges as the only criteria when the enrichment data set is very small.
For geoip and mmdb enrichment tables, this condition needs to be a VRL object with a single key-value pair
whose value needs to be a valid IP address. Example: {"ip": .ip }. If a return field is expected
and without a value, null is used. This table can return the following fields:
ISP databases:
autonomous_system_numberautonomous_system_organizationisporganization
City databases:
city_namecontinent_codecountry_codecountry_nameregion_coderegion_namemetro_codelatitudelongitudepostal_codetimezone
Connection-Type databases:
connection_type
To use this function, you need to update your configuration to
include an
enrichment_tables
parameter.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| table | string | The enrichment table to search. | yes | |
| condition | object | The condition to search on. Since the condition is used at boot time to create indices into the data, these conditions must be statically defined. | yes | |
| select | array | A subset of fields from the enrichment table to return. If not specified, all fields are returned. | no | |
| case_sensitive | boolean | Whether the text fields match the case exactly. | true | no |
| wildcard | string | Value to use for wildcard matching in the search. | no |
Errors
Theget_enrichment_table_record function is fallible, which means that
error handling is required for these errors:Examples
Exact match
get_enrichment_table_record!("test", {"id": 1}){
"firstname": "Bob",
"id": 1,
"surname": "Smith"
}Case insensitive match
get_enrichment_table_record!(
"test",
{"surname": "bob", "firstname": "John"},
case_sensitive: false
)
{
"firstname": "Bob",
"id": 1,
"surname": "Smith"
}Date range search
get_enrichment_table_record!(
"test",
{
"surname": "Smith",
"date_of_birth": {
"from": t'1985-01-01T00:00:00Z',
"to": t'1985-12-31T00:00:00Z'
}
}
)
{
"firstname": "Bob",
"id": 1,
"surname": "Smith"
}Enumerate functions
compact
infallible purevalue by removing empty values, where empty values are defined using the available parameters.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The object or array to compact. | yes | |
| recursive | boolean | Whether the compaction be recursive. | true | no |
| null | boolean | Whether null should be treated as an empty value. | true | no |
| string | boolean | Whether an empty string should be treated as an empty value. | true | no |
| object | boolean | Whether an empty object should be treated as an empty value. | true | no |
| array | boolean | Whether an empty array should be treated as an empty value. | true | no |
| nullish | boolean | Tests whether the value is “nullish” as defined by the is_nullish function. | false | no |
Examples
Compact an object with default parameters
compact({"field1": 1, "field2": "", "field3": [], "field4": null}){
"field1": 1
}Compact an array with default parameters
compact(["foo", "bar", "", null, [], "buzz"])["foo","bar","buzz"]Compact an array using nullish
compact(["-", " ", "\n", null, true], nullish: true)[true]Compact a complex object with default parameters
compact({ "a": {}, "b": null, "c": [null], "d": "", "e": "-", "f": true }){
"e": "-",
"f": true
}Compact a complex object using null: false
compact({ "a": {}, "b": null, "c": [null], "d": "", "e": "-", "f": true }, null: false){
"b": null,
"c": [
null
],
"e": "-",
"f": true
}filter
infallible pureFilter elements from a collection.
This function currently does not support recursive iteration.
The function uses the function closure syntax to allow reading the key-value or index-value combination for each item in the collection.
The same scoping rules apply to closure blocks as they do for regular blocks. This means that any variable defined in parent scopes is accessible, and mutations to those variables are preserved, but any new variables instantiated in the closure block are unavailable outside of the block.
See the examples below to learn about the closure syntax.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The array or object to filter. | yes |
Examples
Filter elements
. = { "tags": ["foo", "bar", "foo", "baz"] }
filter(array(.tags)) -> |_index, value| {
value != "foo"
}
["bar","baz"]Filter object
filter({ "a": 1, "b": 2 }) -> |key, _value| { key == "a" }{
"a": 1
}Filter array
filter([1, 2]) -> |_index, value| { value < 2 }[1]flatten
infallible purevalue into a single-level representation.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The array or object to flatten. | yes | |
| separator | string | The separator to join nested keys | . | no |
Examples
Flatten array
flatten([1, [2, 3, 4], [5, [6, 7], 8], 9])[1,2,3,4,5,6,7,8,9]Flatten object
flatten({
"parent1": {
"child1": 1,
"child2": 2
},
"parent2": {
"child3": 3
}
})
{
"parent1.child1": 1,
"parent1.child2": 2,
"parent2.child3": 3
}Flatten object with custom separator
flatten({ "foo": { "bar": true }}, "_"){
"foo_bar": true
}for_each
infallible pureIterate over a collection.
This function currently does not support recursive iteration.
The function uses the “function closure syntax” to allow reading the key/value or index/value combination for each item in the collection.
The same scoping rules apply to closure blocks as they do for regular blocks. This means that any variable defined in parent scopes is accessible, and mutations to those variables are preserved, but any new variables instantiated in the closure block are unavailable outside of the block.
See the examples below to learn about the closure syntax.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The array or object to iterate. | yes |
Examples
Tally elements
.tags = ["foo", "bar", "foo", "baz"]
tally = {}
for_each(array(.tags)) -> |_index, value| {
count = int(get!(tally, [value])) ?? 0
tally = set!(tally, [value], count + 1)
}
tally
{
"bar": 1,
"baz": 1,
"foo": 2
}Iterate over an object
count = 0
for_each({ "a": 1, "b": 2 }) -> |_key, value| {
count = count + value
}
count
3Iterate over an array
count = 0
for_each([1, 2, 3]) -> |index, value| {
count = count + index + value
}
count
9includes
infallible purevalue array includes the specified item.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The array. | yes | |
| item | any | The item to check. | yes |
Examples
Array includes
includes(["apple", "orange", "banana"], "banana")trueIncludes boolean
includes([1, true], true)trueDoesn’t include
includes(["foo", "bar"], "baz")falsekeys
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The object to extract keys from. | yes |
Examples
Get keys from the object
keys({
"key1": "val1",
"key2": "val2"
})
["key1","key2"]length
infallible pureReturns the length of the value.
- If
valueis an array, returns the number of elements. - If
valueis an object, returns the number of top-level keys. - If
valueis a string, returns the number of bytes in the string. If you want the number of characters, seestrlen.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string object array | The array or object. | yes |
Examples
Length (object)
length({
"portland": "Trail Blazers",
"seattle": "Supersonics"
})
2Length (nested object)
length({
"home": {
"city": "Portland",
"state": "Oregon"
},
"name": "Trail Blazers",
"mascot": {
"name": "Blaze the Trail Cat"
}
})
3Length (array)
length(["Trail Blazers", "Supersonics", "Grizzlies"])3Length (string)
length("The Planet of the Apes Musical")30map_keys
infallible pureMap the keys within an object.
If recursive is enabled, the function iterates into nested
objects, using the following rules:
- Iteration starts at the root.
- For every nested object type:
- First return the key of the object type itself.
- Then recurse into the object, and loop back to item (1) in this list.
- Any mutation done on a nested object before recursing into it, are preserved.
- For every nested array type:
- First return the key of the array type itself.
- Then find all objects within the array, and apply item (2) to each individual object.
The above rules mean that map_keys with
recursive enabled finds all keys in the target,
regardless of whether nested objects are nested inside arrays.
The function uses the function closure syntax to allow reading the key for each item in the object.
The same scoping rules apply to closure blocks as they do for regular blocks. This means that any variable defined in parent scopes is accessible, and mutations to those variables are preserved, but any new variables instantiated in the closure block are unavailable outside of the block.
See the examples below to learn about the closure syntax.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The object to iterate. | yes | |
| recursive | boolean | Whether to recursively iterate the collection. | false | no |
Examples
Upcase keys
. = {
"foo": "foo",
"bar": "bar",
"baz": {"nested key": "val"}
}
map_keys(.) -> |key| { upcase(key) }
{
"BAR": "bar",
"BAZ": {
"nested key": "val"
},
"FOO": "foo"
}De-dot keys
. = {
"labels": {
"app.kubernetes.io/name": "mysql"
}
}
map_keys(., recursive: true) -> |key| { replace(key, ".", "_") }
{
"labels": {
"app_kubernetes_io/name": "mysql"
}
}Recursively map object keys
val = {
"a": 1,
"b": [{ "c": 2 }, { "d": 3 }],
"e": { "f": 4 }
}
map_keys(val, recursive: true) -> |key| { upcase(key) }
{
"A": 1,
"B": [
{
"C": 2
},
{
"D": 3
}
],
"E": {
"F": 4
}
}map_values
infallible pureMap the values within a collection.
If recursive is enabled, the function iterates into nested
collections, using the following rules:
- Iteration starts at the root.
- For every nested collection type:
- First return the collection type itself.
- Then recurse into the collection, and loop back to item (1) in the list
- Any mutation done on a collection before recursing into it, are preserved.
The function uses the function closure syntax to allow mutating the value for each item in the collection.
The same scoping rules apply to closure blocks as they do for regular blocks, meaning, any variable defined in parent scopes are accessible, and mutations to those variables are preserved, but any new variables instantiated in the closure block are unavailable outside of the block.
Check out the examples below to learn about the closure syntax.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The object or array to iterate. | yes | |
| recursive | boolean | Whether to recursively iterate the collection. | false | no |
Examples
Upcase values
. = {
"foo": "foo",
"bar": "bar"
}
map_values(.) -> |value| { upcase(value) }
{
"bar": "BAR",
"foo": "FOO"
}Recursively map object values
val = {
"a": 1,
"b": [{ "c": 2 }, { "d": 3 }],
"e": { "f": 4 }
}
map_values(val, recursive: true) -> |value| {
if is_integer(value) { int!(value) + 1 } else { value }
}
{
"a": 2,
"b": [
{
"c": 3
},
{
"d": 4
}
],
"e": {
"f": 5
}
}match_array
infallible purevalue array matches the pattern. By default, it checks that at least one element matches, but can be set to determine if all the elements match.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The array. | yes | |
| pattern | regex | The regular expression pattern to match against. | yes | |
| all | boolean | Whether to match on all elements of value. | false | no |
Examples
Match at least one element
match_array(["foobar", "bazqux"], r'foo')trueMatch all elements
match_array(["foo", "foobar", "barfoo"], r'foo', all: true)trueNo matches
match_array(["bazqux", "xyz"], r'foo')falseNot all elements match
match_array(["foo", "foobar", "baz"], r'foo', all: true)falsestrlen
infallible pureReturns the number of UTF-8 characters in value. This differs from
length which counts the number of bytes of a string.
Note: This is the count of Unicode scalar values which can sometimes differ from Unicode code points.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string. | yes |
Examples
Count Unicode scalar values
strlen("ñandú")5tally
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The array of strings to count occurrences for. | yes |
Examples
tally
tally!(["foo", "bar", "foo", "baz"]){
"bar": 1,
"baz": 1,
"foo": 2
}tally_value
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| array | array | The array to search through. | yes | |
| value | any | The value to count occurrences of in the array. | yes |
Examples
count matching values
tally_value(["foo", "bar", "foo", "baz"], "foo")2unflatten
infallible purevalue into a nested representation.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The array or object to unflatten. | yes | |
| separator | string | The separator to split flattened keys. | . | no |
| recursive | boolean | Whether to recursively unflatten the object values. | true | no |
Examples
Unflatten
unflatten({
"foo.bar.baz": true,
"foo.bar.qux": false,
"foo.quux": 42
})
{
"foo": {
"bar": {
"baz": true,
"qux": false
},
"quux": 42
}
}Unflatten recursively
unflatten({
"flattened.parent": {
"foo.bar": true,
"foo.baz": false
}
})
{
"flattened": {
"parent": {
"foo": {
"bar": true,
"baz": false
}
}
}
}Unflatten non-recursively
unflatten({
"flattened.parent": {
"foo.bar": true,
"foo.baz": false
}
}, recursive: false)
{
"flattened": {
"parent": {
"foo.bar": true,
"foo.baz": false
}
}
}Ignore inconsistent keys values
unflatten({
"a": 3,
"a.b": 2,
"a.c": 4
})
{
"a": {
"b": 2,
"c": 4
}
}Unflatten with custom separator
unflatten({ "foo_bar": true }, "_"){
"foo": {
"bar": true
}
}unique
infallible pureReturns the unique values for an array.
The first occurrence of each element is kept.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The array to return unique elements from. | yes |
Examples
Unique
unique(["foo", "bar", "foo", "baz"])["foo","bar","baz"]values
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The object to extract values from. | yes |
Examples
Get values from the object
values({"key1": "val1", "key2": "val2"})["val1","val2"]Get values from a complex object
values({"key1": "val1", "key2": [1, 2, 3], "key3": {"foo": "bar"}})["val1",[1,2,3],{"foo":"bar"}]Event functions
get_secret
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| key | string | The name of the secret. | yes |
Examples
Get the Datadog API key from the event metadata
get_secret("datadog_api_key")secret valueGet a non existent secret
get_secret("i_dont_exist")remove_secret
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| key | string | The name of the secret to remove. | yes |
Examples
Remove the datadog api key
remove_secret("datadog_api_key")set_secret
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| key | string | The name of the secret. | yes | |
| secret | string | The secret value. | yes |
Examples
Set the datadog api key
set_secret("datadog_api_key", "secret-value")set_semantic_meaning
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| target | any | The path of the value that is assigned a meaning. | yes | |
| meaning | string | The name of the meaning to assign. | yes |
Notices
This function has special behavior that you should be aware of.Examples
Sets custom field semantic meaning
set_semantic_meaning(.foo, "bar")Path functions
del
infallible impureRemoves the field specified by the static path from the target.
For dynamic path deletion, see the remove function.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| target | any | The path of the field to delete | yes | |
| compact | boolean | After deletion, if compact is true and there is an empty object or array left,
the empty object or array is also removed, cascading up to the root. This only
applies to the path being deleted, and any parent paths. | false | no |
Notices
This function has special behavior that you should be aware of.del function modifies the current event in place and returns the value of the deleted field.Examples
Delete a field
. = { "foo": "bar" }
del(.foo)
barRename a field
. = { "old": "foo" }
.new = del(.old)
.
{
"new": "foo"
}Returns null for unknown field
del({"foo": "bar"}.baz)External target
. = { "foo": true, "bar": 10 }
del(.foo)
.
{
"bar": 10
}Delete field from variable
var = { "foo": true, "bar": 10 }
del(var.foo)
var
{
"bar": 10
}Delete object field
var = { "foo": {"nested": true}, "bar": 10 }
del(var.foo.nested, false)
var
{
"bar": 10,
"foo": {}
}Compact object field
var = { "foo": {"nested": true}, "bar": 10 }
del(var.foo.nested, true)
var
{
"bar": 10
}exists
infallible pureChecks whether the path exists for the target.
This function distinguishes between a missing path
and a path with a null value. A regular path lookup,
such as .foo, cannot distinguish between the two cases
since it always returns null if the path doesn’t exist.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| field | any | The path of the field to check. | yes |
Examples
Exists (field)
. = { "field": 1 }
exists(.field)
trueExists (array element)
. = { "array": [1, 2, 3] }
exists(.array[2])
trueDoes not exist (field)
exists({ "foo": "bar"}.baz)falseget
fallible pureDynamically get the value of a given path.
If you know the path you want to look up, use
static paths such as .foo.bar[1] to get the value of that
path. However, if you do not know the path names,
use the dynamic get function to get the requested value.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The object or array to query. | yes | |
| path | array | An array of path segments to look for the value. | yes |
Errors
Theget function is fallible, which means that
error handling is required for these errors:path segment must be a string or an integer.Examples
Single-segment top-level field
get!(value: {"foo": "bar"}, path: ["foo"])barReturns null for unknown field
get!(value: {"foo": "bar"}, path: ["baz"])Multi-segment nested field
get!(value: {"foo": { "bar": true }}, path: ["foo", "bar"])trueArray indexing
get!(value: [92, 42], path: [0])92Array indexing (negative)
get!(value: ["foo", "bar", "baz"], path: [-2])barNested indexing
get!(value: {"foo": { "bar": [92, 42] }}, path: ["foo", "bar", 1])42External target
{ "foo": true }get!(value: ., path: ["foo"])trueVariable
var = { "foo": true }
get!(value: var, path: ["foo"])
trueMissing index
get!(value: {"foo": { "bar": [92, 42] }}, path: ["foo", "bar", 1, -1])Invalid indexing
get!(value: [42], path: ["foo"])Invalid segment type
get!(value: {"foo": { "bar": [92, 42] }}, path: ["foo", true])function call error for "get" at (0:62): path segment must be either string or integer, not booleanremove
fallible pureDynamically remove the value for a given path.
If you know the path you want to remove, use
the del function and static paths such as del(.foo.bar[1])
to remove the value at that path. The del function returns the
deleted value, and is more performant than remove.
However, if you do not know the path names, use the dynamic
remove function to remove the value at the provided path.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The object or array to remove data from. | yes | |
| path | array | An array of path segments to remove the value from. | yes | |
| compact | boolean | After deletion, if compact is true, any empty objects or
arrays left are also removed. | false | no |
Errors
Theremove function is fallible, which means that
error handling is required for these errors:path segment must be a string or an integer.Examples
Single-segment top-level field
remove!(value: { "foo": "bar" }, path: ["foo"]){}Remove unknown field
remove!(value: {"foo": "bar"}, path: ["baz"]){
"foo": "bar"
}Multi-segment nested field
remove!(value: { "foo": { "bar": "baz" } }, path: ["foo", "bar"]){
"foo": {}
}Array indexing
remove!(value: ["foo", "bar", "baz"], path: [-2])["foo","baz"]Compaction
remove!(value: { "foo": { "bar": [42], "baz": true } }, path: ["foo", "bar", 0], compact: true){
"foo": {
"baz": true
}
}Compact object
remove!(value: {"foo": { "bar": true }}, path: ["foo", "bar"], compact: true){}Compact array
remove!(value: {"foo": [42], "bar": true }, path: ["foo", 0], compact: true){
"bar": true
}External target
{ "foo": true }remove!(value: ., path: ["foo"]){}Variable
var = { "foo": true }
remove!(value: var, path: ["foo"])
{}Missing index
remove!(value: {"foo": { "bar": [92, 42] }}, path: ["foo", "bar", 1, -1]){
"foo": {
"bar": [
92,
42
]
}
}Invalid indexing
remove!(value: [42], path: ["foo"])[42]Invalid segment type
remove!(value: {"foo": { "bar": [92, 42] }}, path: ["foo", true])function call error for "remove" at (0:65): path segment must be either string or integer, not booleanset
fallible pureDynamically insert data into the path of a given object or array.
If you know the path you want to assign a value to,
use static path assignments such as .foo.bar[1] = true for
improved performance and readability. However, if you do not
know the path names, use the dynamic set function to
insert the data into the object or array.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object array | The object or array to insert data into. | yes | |
| path | array | An array of path segments to insert the value into. | yes | |
| data | any | The data to be inserted. | yes |
Errors
Theset function is fallible, which means that
error handling is required for these errors:path segment must be a string or an integer.Examples
Single-segment top-level field
set!(value: { "foo": "bar" }, path: ["foo"], data: "baz"){
"foo": "baz"
}Multi-segment nested field
set!(value: { "foo": { "bar": "baz" } }, path: ["foo", "bar"], data: "qux"){
"foo": {
"bar": "qux"
}
}Array
set!(value: ["foo", "bar", "baz"], path: [-2], data: 42)["foo",42,"baz"]Nested fields
set!(value: {}, path: ["foo", "bar"], data: "baz"){
"foo": {
"bar": "baz"
}
}Nested indexing
set!(value: {"foo": { "bar": [] }}, path: ["foo", "bar", 1], data: "baz"){
"foo": {
"bar": [
null,
"baz"
]
}
}External target
{ "foo": true }set!(value: ., path: ["bar"], data: "baz"){
"bar": "baz",
"foo": true
}Variable
var = { "foo": true }
set!(value: var, path: ["bar"], data: "baz")
{
"bar": "baz",
"foo": true
}Invalid indexing
set!(value: [], path: ["foo"], data: "baz"){
"foo": "baz"
}Invalid segment type
set!({"foo": { "bar": [92, 42] }}, ["foo", true], "baz")function call error for "set" at (0:56): path segment must be either string or integer, not booleanCryptography functions
decrypt
fallible pureDecrypts a string with a symmetric encryption algorithm.
Supported Algorithms:
- AES-256-CFB (key = 32 bytes, iv = 16 bytes)
- AES-192-CFB (key = 24 bytes, iv = 16 bytes)
- AES-128-CFB (key = 16 bytes, iv = 16 bytes)
- AES-256-OFB (key = 32 bytes, iv = 16 bytes)
- AES-192-OFB (key = 24 bytes, iv = 16 bytes)
- AES-128-OFB (key = 16 bytes, iv = 16 bytes)
- AES-128-SIV (key = 32 bytes, iv = 16 bytes)
- AES-256-SIV (key = 64 bytes, iv = 16 bytes)
- Deprecated - AES-256-CTR (key = 32 bytes, iv = 16 bytes)
- Deprecated - AES-192-CTR (key = 24 bytes, iv = 16 bytes)
- Deprecated - AES-128-CTR (key = 16 bytes, iv = 16 bytes)
- AES-256-CTR-LE (key = 32 bytes, iv = 16 bytes)
- AES-192-CTR-LE (key = 24 bytes, iv = 16 bytes)
- AES-128-CTR-LE (key = 16 bytes, iv = 16 bytes)
- AES-256-CTR-BE (key = 32 bytes, iv = 16 bytes)
- AES-192-CTR-BE (key = 24 bytes, iv = 16 bytes)
- AES-128-CTR-BE (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-PKCS7 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-PKCS7 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-PKCS7 (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-ANSIX923 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-ANSIX923 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-ANSIX923 (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-ISO7816 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-ISO7816 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-ISO7816 (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-ISO10126 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-ISO10126 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-ISO10126 (key = 16 bytes, iv = 16 bytes)
- CHACHA20-POLY1305 (key = 32 bytes, iv = 12 bytes)
- XCHACHA20-POLY1305 (key = 32 bytes, iv = 24 bytes)
- XSALSA20-POLY1305 (key = 32 bytes, iv = 24 bytes)
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| ciphertext | string | The string in raw bytes (not encoded) to decrypt. | yes | |
| algorithm | string | The algorithm to use. | yes | |
| key | string | The key in raw bytes (not encoded) for decryption. The length must match the algorithm requested. | yes | |
| iv | string | The IV in raw bytes (not encoded) for decryption. The length must match the algorithm requested.
A new IV should be generated for every message. You can use random_bytes to generate a cryptographically secure random value.
The value should match the one used during encryption. | yes |
Errors
Thedecrypt function is fallible, which means that
error handling is required for these errors:algorithm is not a supported algorithm.key length does not match the key size required for the algorithm specified.iv length does not match the iv size required for the algorithm specified.Examples
Decrypt value using AES-256-CFB
iv = "0123456789012345"
key = "01234567890123456789012345678912"
ciphertext = decode_base64!("c/dIOA==")
decrypt!(ciphertext, "AES-256-CFB", key: key, iv: iv)
dataDecrypt value using AES-128-CBC-PKCS7
iv = decode_base64!("fVEIRkIiczCRWNxaarsyxA==")
key = "16_byte_keyxxxxx"
ciphertext = decode_base64!("5fLGcu1VHdzsPcGNDio7asLqE1P43QrVfPfmP4i4zOU=")
decrypt!(ciphertext, "AES-128-CBC-PKCS7", key: key, iv: iv)
super_secret_messageencrypt
fallible pureEncrypts a string with a symmetric encryption algorithm.
Supported Algorithms:
- AES-256-CFB (key = 32 bytes, iv = 16 bytes)
- AES-192-CFB (key = 24 bytes, iv = 16 bytes)
- AES-128-CFB (key = 16 bytes, iv = 16 bytes)
- AES-256-OFB (key = 32 bytes, iv = 16 bytes)
- AES-192-OFB (key = 24 bytes, iv = 16 bytes)
- AES-128-OFB (key = 16 bytes, iv = 16 bytes)
- AES-128-SIV (key = 32 bytes, iv = 16 bytes)
- AES-256-SIV (key = 64 bytes, iv = 16 bytes)
- Deprecated - AES-256-CTR (key = 32 bytes, iv = 16 bytes)
- Deprecated - AES-192-CTR (key = 24 bytes, iv = 16 bytes)
- Deprecated - AES-128-CTR (key = 16 bytes, iv = 16 bytes)
- AES-256-CTR-LE (key = 32 bytes, iv = 16 bytes)
- AES-192-CTR-LE (key = 24 bytes, iv = 16 bytes)
- AES-128-CTR-LE (key = 16 bytes, iv = 16 bytes)
- AES-256-CTR-BE (key = 32 bytes, iv = 16 bytes)
- AES-192-CTR-BE (key = 24 bytes, iv = 16 bytes)
- AES-128-CTR-BE (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-PKCS7 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-PKCS7 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-PKCS7 (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-ANSIX923 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-ANSIX923 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-ANSIX923 (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-ISO7816 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-ISO7816 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-ISO7816 (key = 16 bytes, iv = 16 bytes)
- AES-256-CBC-ISO10126 (key = 32 bytes, iv = 16 bytes)
- AES-192-CBC-ISO10126 (key = 24 bytes, iv = 16 bytes)
- AES-128-CBC-ISO10126 (key = 16 bytes, iv = 16 bytes)
- CHACHA20-POLY1305 (key = 32 bytes, iv = 12 bytes)
- XCHACHA20-POLY1305 (key = 32 bytes, iv = 24 bytes)
- XSALSA20-POLY1305 (key = 32 bytes, iv = 24 bytes)
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| plaintext | string | The string to encrypt. | yes | |
| algorithm | string | The algorithm to use. | yes | |
| key | string | The key in raw bytes (not encoded) for encryption. The length must match the algorithm requested. | yes | |
| iv | string | The IV in raw bytes (not encoded) for encryption. The length must match the algorithm requested.
A new IV should be generated for every message. You can use random_bytes to generate a cryptographically secure random value. | yes |
Errors
Theencrypt function is fallible, which means that
error handling is required for these errors:algorithm is not a supported algorithm.key length does not match the key size required for the algorithm specified.iv length does not match the iv size required for the algorithm specified.Examples
Encrypt value using AES-256-CFB
iv = "0123456789012345" # typically you would call random_bytes(16)
key = "01234567890123456789012345678912"
encrypted_message = encrypt!("data", "AES-256-CFB", key: key, iv: iv)
encode_base64(encrypted_message)
c/dIOA==Encrypt value using AES-128-CBC-PKCS7
iv = "1234567890123456" # typically you would call random_bytes(16)
key = "16_byte_keyxxxxx"
encrypted_message = encrypt!("super secret message", "AES-128-CBC-PKCS7", key: key, iv: iv)
encode_base64(encrypted_message)
GBw8Mu00v0Kc38+/PvsVtGgWuUJ+ZNLgF8Opy8ohIYE=hmac
infallible pureCalculates a HMAC of the value using the given key.
The hashing algorithm used can be optionally specified.
For most use cases, the resulting bytestream should be encoded into a hex or base64 string using either encode_base16 or encode_base64.
This function is infallible if either the default algorithm value or a recognized-valid compile-time
algorithm string literal is used. Otherwise, it is fallible.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the HMAC for. | yes | |
| key | string | The string to use as the cryptographic key. | yes | |
| algorithm | string | The hashing algorithm to use. | SHA-256 | no |
Examples
Calculate message HMAC (defaults: SHA-256), encoding to a base64 string
encode_base64(hmac("Hello there", "super-secret-key"))eLGE8YMviv85NPXgISRUZxstBNSU47JQdcXkUWcClmI=Calculate message HMAC using SHA-224, encoding to a hex-encoded string
encode_base16(hmac("Hello there", "super-secret-key", algorithm: "SHA-224"))42fccbc2b7d22a143b92f265a8046187558a94d11ddbb30622207e90Calculate message HMAC using SHA1, encoding to a base64 string
encode_base64(hmac("Hello there", "super-secret-key", algorithm: "SHA1"))MiyBIHO8Set9+6crALiwkS0yFPE=Calculate message HMAC using a variable hash algorithm
.hash_algo = "SHA-256"
hmac_bytes, err = hmac("Hello there", "super-secret-key", algorithm: .hash_algo)
if err == null {
.hmac = encode_base16(hmac_bytes)
}
78b184f1832f8aff3934f5e0212454671b2d04d494e3b25075c5e45167029662md5
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the hash for. | yes |
Examples
Create md5 hash
md5("foo")acbd18db4cc2f85cedef654fccc4a4d8seahash
infallible purevalue.
Note: Due to limitations in the underlying VRL data types, this function converts the unsigned 64-bit integer SeaHash result to a signed 64-bit integer. Results higher than the signed 64-bit integer maximum value wrap around to negative values.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the hash for. | yes |
Examples
Calculate seahash
seahash("foobar")5348458858952426000Calculate negative seahash
seahash("bar")-2796170501982571500sha1
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the hash for. | yes |
Examples
Calculate sha1 hash
sha1("foo")0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33sha2
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the hash for. | yes | |
| variant | string | The variant of the algorithm to use. | SHA-512/256 | no |
Examples
Calculate sha2 hash using default variant
sha2("foobar")d014c752bc2be868e16330f47e0c316a5967bcbc9c286a457761d7055b9214ceCalculate sha2 hash with SHA-512/224
sha2("foo", variant: "SHA-512/224")d68f258d37d670cfc1ec1001a0394784233f88f056994f9a7e5e99beCalculate sha2 hash with SHA-384
sha2("foobar", "SHA-384")3c9c30d9f665e74d515c842960d4a451c83a0125fd3de7392d7b37231af10c72ea58aedfcdf89a5765bf902af93ecf06sha3
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the hash for. | yes | |
| variant | string | The variant of the algorithm to use. | SHA3-512 | no |
Examples
Calculate sha3 hash using default variant
sha3("foobar")ff32a30c3af5012ea395827a3e99a13073c3a8d8410a708568ff7e6eb85968fccfebaea039bc21411e9d43fdb9a851b529b9960ffea8679199781b8f45ca85e2Calculate sha3 hash with SHA3-224
sha3("foo", variant: "SHA3-224")f4f6779e153c391bbd29c95e72b0708e39d9166c7cea51d1f10ef58aCalculate sha3 hash with SHA3-384
sha3("foobar", "SHA3-384")0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8IP functions
decrypt_ip
fallible pureDecrypts an IP address that was previously encrypted, restoring the original IP address.
Supported Modes:
- AES128 - Decrypts an IP address that was scrambled using AES-128 encryption. Can transform between IPv4 and IPv6.
- PFX (Prefix-preserving) - Decrypts an IP address that was encrypted with prefix-preserving mode, where network hierarchy was maintained.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| ip | string | The encrypted IP address to decrypt (v4 or v6). | yes | |
| key | string | The decryption key in raw bytes (not encoded). Must be the same key that was used for encryption. For AES128 mode, the key must be exactly 16 bytes. For PFX mode, the key must be exactly 32 bytes. | yes | |
| mode | string | The decryption mode to use. Must match the mode used for encryption: either aes128 or pfx. | yes |
Notices
This function has special behavior that you should be aware of.aes128 mode implements the ipcrypt-deterministic algorithm from the IPCrypt
specification, while the pfx mode implements the ipcrypt-pfx algorithm. This
function reverses the encryption performed by encrypt_ip - the same key and algorithm
that were used for encryption must be used for decryption.Errors
Thedecrypt_ip function is fallible, which means that
error handling is required for these errors:ip is not a valid IP address.mode is not a supported mode (must be aes128 or pfx).key length does not match the requirements for the specified mode (16 bytes for aes128, 32 bytes for pfx).Examples
Decrypt IPv4 address with AES128
decrypt_ip!("72b9:a747:f2e9:72af:76ca:5866:6dcf:c3b0", "sixteen byte key", "aes128")192.168.1.1Decrypt IPv6 address with AES128
decrypt_ip!("c0e6:eb35:6887:f554:4c65:8ace:17ca:6c6a", "sixteen byte key", "aes128")2001:db8::1Decrypt IPv4 address with prefix-preserving mode
decrypt_ip!("33.245.248.61", "thirty-two bytes key for pfx use", "pfx")192.168.1.1Decrypt IPv6 address with prefix-preserving mode
decrypt_ip!("88bd:d2bf:8865:8c4d:84b:44f6:6077:72c9", "thirty-two bytes key for ipv6pfx", "pfx")2001:db8::1Round-trip encryption and decryption
original_ip = "192.168.1.100"
key = "sixteen byte key"
mode = "aes128"
encrypted = encrypt_ip!(original_ip, key, mode)
decrypt_ip!(encrypted, key, mode)
192.168.1.100encrypt_ip
fallible pureEncrypts an IP address, transforming it into a different valid IP address.
Supported Modes:
- AES128 - Scrambles the entire IP address using AES-128 encryption. Can transform between IPv4 and IPv6.
- PFX (Prefix-preserving) - Maintains network hierarchy by ensuring that IP addresses within the same network are encrypted to addresses that also share a common network. This preserves prefix relationships while providing confidentiality.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| ip | string | The IP address to encrypt (v4 or v6). | yes | |
| key | string | The encryption key in raw bytes (not encoded). For AES128 mode, the key must be exactly 16 bytes. For PFX mode, the key must be exactly 32 bytes. | yes | |
| mode | string | The encryption mode to use. Must be either aes128 or pfx. | yes |
Notices
This function has special behavior that you should be aware of.aes128 mode implements the ipcrypt-deterministic algorithm from the IPCrypt
specification, while the pfx mode implements the ipcrypt-pfx algorithm. Both modes
provide deterministic encryption where the same input IP address encrypted with the
same key will always produce the same encrypted output.Errors
Theencrypt_ip function is fallible, which means that
error handling is required for these errors:ip is not a valid IP address.mode is not a supported mode (must be aes128 or pfx).key length does not match the requirements for the specified mode (16 bytes for aes128, 32 bytes for pfx).Examples
Encrypt IPv4 address with AES128
encrypt_ip!("192.168.1.1", "sixteen byte key", "aes128")72b9:a747:f2e9:72af:76ca:5866:6dcf:c3b0Encrypt IPv6 address with AES128
encrypt_ip!("2001:db8::1", "sixteen byte key", "aes128")c0e6:eb35:6887:f554:4c65:8ace:17ca:6c6aEncrypt IPv4 address with prefix-preserving mode
encrypt_ip!("192.168.1.1", "thirty-two bytes key for pfx use", "pfx")33.245.248.61Encrypt IPv6 address with prefix-preserving mode
encrypt_ip!("2001:db8::1", "thirty-two bytes key for ipv6pfx", "pfx")88bd:d2bf:8865:8c4d:84b:44f6:6077:72c9ip_aton
fallible pureConverts IPv4 address in numbers-and-dots notation into network-order bytes represented as an integer.
This behavior mimics inet_aton.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address to convert to binary. | yes |
Errors
Theip_aton function is fallible, which means that
error handling is required for these errors:value is not a valid IPv4 address.Examples
IPv4 to integer
ip_aton!("1.2.3.4")16909060ip_cidr_contains
fallible pureip is contained in the block referenced by the cidr.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| cidr | string array | The CIDR mask (v4 or v6). | yes | |
| value | string | The IP address (v4 or v6). | yes |
Errors
Theip_cidr_contains function is fallible, which means that
error handling is required for these errors:cidr is not a valid CIDR.ip is not a valid IP address.Examples
IPv4 contains CIDR
ip_cidr_contains!("192.168.0.0/16", "192.168.10.32")trueIPv4 is private
ip_cidr_contains!(["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"], "192.168.10.32")trueIPv6 contains CIDR
ip_cidr_contains!("2001:4f8:4:ba::/64", "2001:4f8:4:ba:2e0:81ff:fe22:d1f1")trueNot in range
ip_cidr_contains!("192.168.0.0/24", "192.168.10.32")falseInvalid address
ip_cidr_contains!("192.168.0.0/24", "INVALID")function call error for "ip_cidr_contains" at (0:46): unable to parse IP address: invalid IP address syntaxip_ntoa
fallible pureConverts numeric representation of IPv4 address in network-order bytes to numbers-and-dots notation.
This behavior mimics inet_ntoa.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer | The integer representation of an IPv4 address. | yes |
Errors
Theip_ntoa function is fallible, which means that
error handling is required for these errors:value cannot fit in an unsigned 32-bit integer.Examples
Integer to IPv4
ip_ntoa!(16909060)1.2.3.4ip_ntop
fallible pureConverts IPv4 and IPv6 addresses from binary to text form.
This behavior mimics inet_ntop.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The binary data to convert from. For IPv4 addresses, it must be 4 bytes (32 bits) long. For IPv6 addresses, it must be 16 bytes (128 bits) long. | yes |
Notices
This function has special behavior that you should be aware of.decode_base64 or decode_percent can still be used correctly.Errors
Theip_ntop function is fallible, which means that
error handling is required for these errors:value must be of length 4 or 16 bytes.Examples
Convert IPv4 address from bytes after decoding from Base64
ip_ntop!(decode_base64!("wKgAAQ=="))192.168.0.1Convert IPv6 address from bytes after decoding from Base64
ip_ntop!(decode_base64!("IAENuIWjAAAAAIouA3BzNA=="))2001:db8:85a3::8a2e:370:7334ip_pton
fallible pureConverts IPv4 and IPv6 addresses from text to binary form.
- The binary form of IPv4 addresses is 4 bytes (32 bits) long.
- The binary form of IPv6 addresses is 16 bytes (128 bits) long.
This behavior mimics inet_pton.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address (v4 or v6) to convert to binary form. | yes |
Notices
This function has special behavior that you should be aware of.encode_base64 or encode_percent can still process it correctly.Errors
Theip_pton function is fallible, which means that
error handling is required for these errors:value is not a valid IP (v4 or v6) address in text form.Examples
Convert IPv4 address to bytes and encode to Base64
encode_base64(ip_pton!("192.168.0.1"))wKgAAQ==Convert IPv6 address to bytes and encode to Base64
encode_base64(ip_pton!("2001:db8:85a3::8a2e:370:7334"))IAENuIWjAAAAAIouA3BzNA==ip_subnet
fallible pureip using the supplied subnet.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address (v4 or v6). | yes | |
| subnet | string | The subnet to extract from the IP address. This can be either a prefix length like /8 or a net mask
like 255.255.0.0. The net mask can be either an IPv4 or IPv6 address. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theip_subnet function is fallible, which means that
error handling is required for these errors:ip is not a valid IP address.subnet is not a valid subnet.Examples
IPv4 subnet
ip_subnet!("192.168.10.32", "255.255.255.0")192.168.10.0IPv6 subnet
ip_subnet!("2404:6800:4003:c02::64", "/32")2404:6800::Subnet /1
ip_subnet!("192.168.0.1", "/1")128.0.0.0ip_to_ipv6
fallible pureip to an IPv6 address.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address to convert to IPv6. | yes |
Errors
Theip_to_ipv6 function is fallible, which means that
error handling is required for these errors:ip is not a valid IP address.Examples
IPv4 to IPv6
ip_to_ipv6!("192.168.10.32")::ffff:192.168.10.32ipv6_to_ipv4
fallible pureip to an IPv4 address. ip is returned unchanged if it’s already an IPv4 address. If ip is
currently an IPv6 address then it needs to be IPv4 compatible, otherwise an error is thrown.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IPv4-mapped IPv6 address to convert. | yes |
Errors
Theipv6_to_ipv4 function is fallible, which means that
error handling is required for these errors:ip is not a valid IP address.ip is an IPv6 address that is not compatible with IPv4.Examples
IPv6 to IPv4
ipv6_to_ipv4!("::ffff:192.168.0.1")192.168.0.1is_ipv4
infallible pureCheck if the string is a valid IPv4 address or not.
An IPv4-mapped or IPv4-compatible IPv6 address is not considered valid for the purpose of this function.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address to check | yes |
Examples
Valid IPv4 address
is_ipv4("10.0.102.37")trueValid IPv6 address
is_ipv4("2001:0db8:85a3:0000:0000:8a2e:0370:7334")falseArbitrary string
is_ipv4("foobar")falseis_ipv6
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address to check | yes |
Examples
Valid IPv6 address
is_ipv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334")trueValid IPv4 address
is_ipv6("10.0.102.37")falseArbitrary string
is_ipv6("foobar")falseMap functions
haversine
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| latitude1 | float | Latitude of the first point. | yes | |
| longitude1 | float | Longitude of the first point. | yes | |
| latitude2 | float | Latitude of the second point. | yes | |
| longitude2 | float | Longitude of the second point. | yes | |
| measurement_unit | string | Measurement system to use for resulting distance. | no |
Examples
Haversine in kilometers
haversine(0.0, 0.0, 10.0, 10.0){
"bearing": 44.561,
"distance": 1568.5227233
}Haversine in miles
haversine(0.0, 0.0, 10.0, 10.0, measurement_unit: "miles"){
"bearing": 44.561,
"distance": 974.6348468
}Metrics functions
aggregate_vector_metrics
infallible pureAggregates internal Vector metrics, using one of 4 aggregation functions, filtering by name and optionally by tags. Returns the aggregated value. Only includes counter and gauge metrics.
Internal Vector metrics functions work with a snapshot of the metrics. The interval at which the snapshot is updated is controlled through the metrics_storage_refresh_period global option. Higher values can reduce performance impact of that process, but may cause stale metrics data in the snapshot.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| function | string | The metric name to search. | yes | |
| key | string | The metric name to aggregate. | yes | |
| tags | object | Tags to filter the results on. Values in this object support wildcards (’*’) to match on parts of the tag value. | { } | no |
Examples
Sum vector internal metrics matching the name
aggregate_vector_metrics("sum", "utilization")0.5Sum vector internal metrics matching the name and tags
aggregate_vector_metrics("sum", "utilization", tags: {"component_id": "test"})0.5Average of vector internal metrics matching the name
aggregate_vector_metrics("avg", "utilization")0.5Max of vector internal metrics matching the name
aggregate_vector_metrics("max", "utilization")0.5Min of vector internal metrics matching the name
aggregate_vector_metrics("max", "utilization")0.5find_vector_metrics
infallible pureSearches internal Vector metrics by name and optionally by tags. Returns all matching metrics.
Internal Vector metrics functions work with a snapshot of the metrics. The interval at which the snapshot is updated is controlled through the metrics_storage_refresh_period global option. Higher values can reduce performance impact of that process, but may cause stale metrics data in the snapshot.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| key | string | The metric name to search. | yes | |
| tags | object | Tags to filter the results on. Values in this object support wildcards (’*’) to match on parts of the tag value. | { } | no |
Examples
Find vector internal metrics matching the name
find_vector_metrics("utilization")[{"kind":"absolute","name":"utilization","tags":{"component_id":["test"]},"type":"gauge","value":0.5}]Find vector internal metrics matching the name and tags
find_vector_metrics("utilization", tags: {"component_id": "test"})[{"kind":"absolute","name":"utilization","tags":{"component_id":["test"]},"type":"gauge","value":0.5}]get_vector_metric
infallible pureSearches internal Vector metrics by name and optionally by tags. Returns the first matching metric.
Internal Vector metrics functions work with a snapshot of the metrics. The interval at which the snapshot is updated is controlled through the metrics_storage_refresh_period global option. Higher values can reduce performance impact of that process, but may cause stale metrics data in the snapshot.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| key | string | The metric name to search. | yes | |
| tags | object | Tags to filter the results on. Values in this object support wildcards (’*’) to match on parts of the tag value. | { } | no |
Examples
Get a vector internal metric matching the name
get_vector_metric("utilization"){
"kind": "absolute",
"name": "utilization",
"tags": {
"component_id": [
"test"
]
},
"type": "gauge",
"value": 0.5
}Get a vector internal metric matching the name and tags
get_vector_metric("utilization", tags: {"component_id": "test"}){
"kind": "absolute",
"name": "utilization",
"tags": {
"component_id": [
"test"
]
},
"type": "gauge",
"value": 0.5
}Number functions
abs
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer float | The number to calculate the absolute value. | yes |
Examples
Computes the absolute value of an integer
abs(-42)42Computes the absolute value of a float
abs(-42.2)42.2Computes the absolute value of a positive integer
abs(10)10ceil
infallible purevalue up to the specified precision.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer float | The number to round up. | yes | |
| precision | integer | The number of decimal places to round to. | 0 | no |
Examples
Round a number up (without precision)
ceil(4.345)5Round a number up (with precision)
ceil(4.345, precision: 2)4.35Round an integer up (noop)
ceil(5)5floor
infallible purevalue down to the specified precision.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer float | The number to round down. | yes | |
| precision | integer | The number of decimal places to round to. | 0 | no |
Examples
Round a number down (without precision)
floor(9.8)9Round a number down (with precision)
floor(4.345, precision: 2)4.34format_int
fallible purevalue into a string representation using the given base/radix.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer | The number to format. | yes | |
| base | integer | The base to format the number in. Must be between 2 and 36 (inclusive). | 10 | no |
Errors
Theformat_int function is fallible, which means that
error handling is required for these errors:Examples
Format as a hexadecimal integer
format_int!(42, 16)2aFormat as a negative hexadecimal integer
format_int!(-42, 16)-2aFormat as a decimal integer (default base)
format_int!(42)42format_number
infallible purevalue into a string representation of the number.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer float | The number to format as a string. | yes | |
| scale | integer | The number of decimal places to display. | no | |
| decimal_separator | string | The character to use between the whole and decimal parts of the number. | . | no |
| grouping_separator | string | The character to use between each thousands part of the number. | no |
Examples
Format a number (3 decimals)
format_number(1234567.89, 3, decimal_separator: ".", grouping_separator: ",")1,234,567.890Format a number with European-style separators
format_number(4672.4, decimal_separator: ",", grouping_separator: "_")4_672,4Format a number with a middle dot separator
format_number(4321.09, 3, decimal_separator: "·")4321·090mod
fallible purevalue divided by modulus.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer float | The value the modulus is applied to. | yes | |
| modulus | integer float | The modulus value. | yes |
Errors
Themod function is fallible, which means that
error handling is required for these errors:value is not an integer or float.modulus is not an integer or float.modulus is equal to 0.Examples
Calculate the remainder of two integers
mod(5, 2)1round
infallible purevalue to the specified precision.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | integer float | The number to round. | yes | |
| precision | integer | The number of decimal places to round to. | 0 | no |
Examples
Round a number (without precision)
round(4.345)4Round a number (with precision)
round(4.345, precision: 2)4.35Round up
round(5.5)6Round down
round(5.45)5Object functions
match_datadog_query
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | object | The object. | yes | |
| query | string | The Datadog Search Syntax query. | yes |
Examples
OR query
match_datadog_query({"message": "contains this and that"}, "this OR that")trueAND query
match_datadog_query({"message": "contains only this"}, "this AND that")falseAttribute wildcard
match_datadog_query({"name": "foobar"}, "@name:foo*")trueTag range
match_datadog_query({"tags": ["a:x", "b:y", "c:z"]}, s'b:["x" TO "z"]')truemerge
infallible purefrom object into the to object.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| to | object | The object to merge into. | yes | |
| from | object | The object to merge from. | yes | |
| deep | boolean | A deep merge is performed if true, otherwise only top-level fields are merged. | false | no |
Examples
Object merge (shallow)
merge(
{
"parent1": {
"child1": 1,
"child2": 2
},
"parent2": {
"child3": 3
}
},
{
"parent1": {
"child2": 4,
"child5": 5
}
}
)
{
"parent1": {
"child2": 4,
"child5": 5
},
"parent2": {
"child3": 3
}
}Object merge (deep)
merge(
{
"parent1": {
"child1": 1,
"child2": 2
},
"parent2": {
"child3": 3
}
},
{
"parent1": {
"child2": 4,
"child5": 5
}
},
deep: true
)
{
"parent1": {
"child1": 1,
"child2": 4,
"child5": 5
},
"parent2": {
"child3": 3
}
}object_from_array
fallible pureIterate over either one array of arrays or a pair of arrays and create an object out of all the key-value pairs contained in them.
With one array of arrays, any entries with no value use null instead.
Any keys that are null skip the corresponding value.
If a single parameter is given, it must contain an array of all the input arrays.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| values | array | The first array of elements, or the array of input arrays if no other parameter is present. | yes | |
| keys | array | The second array of elements. If not present, the first parameter must contain all the arrays. | no |
Errors
Theobject_from_array function is fallible, which means that
error handling is required for these errors:values and keys must be arrays.keys is not present, values must contain only arrays.Examples
Create an object from one array
object_from_array([["one", 1], [null, 2], ["two", 3]]){
"one": 1,
"two": 3
}Create an object from separate key and value arrays
object_from_array([1, 2, 3], keys: ["one", null, "two"]){
"one": 1,
"two": 3
}Create an object from a separate arrays of keys and values
object_from_array(values: [1, null, true], keys: ["a", "b", "c"]){
"a": 1,
"b": null,
"c": true
}unnest
fallible pureUnnest an array field from an object to create an array of objects using that field; keeping all other fields.
Assigning the array result of this to . results in multiple events being emitted from remap. See the
remap transform docs for more details.
This is also referred to as explode in some languages.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| path | array | The path of the field to unnest. | yes |
Errors
Theunnest function is fallible, which means that
error handling is required for these errors:Examples
Unnest an array field
. = {"hostname": "localhost", "messages": ["message 1", "message 2"]}
. = unnest(.messages)
[{"hostname":"localhost","messages":"message 1"},{"hostname":"localhost","messages":"message 2"}]Unnest a nested array field
. = {"hostname": "localhost", "event": {"messages": ["message 1", "message 2"]}}
. = unnest(.event.messages)
[{"event":{"messages":"message 1"},"hostname":"localhost"},{"event":{"messages":"message 2"},"hostname":"localhost"}]Parse functions
parse_apache_log
fallible purecommon,
combined, or the default error format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| format | string | The format to use for parsing the log. | yes | |
| timestamp_format | string | The date/time format to use for encoding the timestamp. The time is parsed in local time if the timestamp does not specify a timezone. | %d/%b/%Y:%T %z | no |
Notices
This function has special behavior that you should be aware of.-. These fields are omitted in the result.Errors
Theparse_apache_log function is fallible, which means that
error handling is required for these errors:value does not match the specified format.timestamp_format is not a valid format string.value fails to parse using the provided timestamp_format.Examples
Parse using Apache log format (common)
parse_apache_log!(s'127.0.0.1 bob frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326', format: "common"){
"host": "127.0.0.1",
"identity": "bob",
"message": "GET /apache_pb.gif HTTP/1.0",
"method": "GET",
"path": "/apache_pb.gif",
"protocol": "HTTP/1.0",
"size": 2326,
"status": 200,
"timestamp": "2000-10-10T20:55:36Z",
"user": "frank"
}Parse using Apache log format (combined)
parse_apache_log!(
s'127.0.0.1 bob frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.seniorinfomediaries.com/vertical/channels/front-end/bandwidth" "Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/1945-10-12 Firefox/37.0"',
"combined",
)
{
"agent": "Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/1945-10-12 Firefox/37.0",
"host": "127.0.0.1",
"identity": "bob",
"message": "GET /apache_pb.gif HTTP/1.0",
"method": "GET",
"path": "/apache_pb.gif",
"protocol": "HTTP/1.0",
"referrer": "http://www.seniorinfomediaries.com/vertical/channels/front-end/bandwidth",
"size": 2326,
"status": 200,
"timestamp": "2000-10-10T20:55:36Z",
"user": "frank"
}Parse using Apache log format (error)
parse_apache_log!(
s'[01/Mar/2021:12:00:19 +0000] [ab:alert] [pid 4803:tid 3814] [client 147.159.108.175:24259] I will bypass the haptic COM bandwidth, that should matrix the CSS driver!',
"error"
)
{
"client": "147.159.108.175",
"message": "I will bypass the haptic COM bandwidth, that should matrix the CSS driver!",
"module": "ab",
"pid": 4803,
"port": 24259,
"severity": "alert",
"thread": "3814",
"timestamp": "2021-03-01T12:00:19Z"
}parse_aws_alb_log
fallible purevalue in the Elastic Load Balancer Access format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | Access log of the Application Load Balancer. | yes | |
| strict_mode | boolean | When set to false, the parser ignores any newly added or trailing fields in AWS ALB logs instead of failing. Defaults to true to preserve strict parsing behavior. | true | no |
Errors
Theparse_aws_alb_log function is fallible, which means that
error handling is required for these errors:value is not a properly formatted AWS ALB log.Examples
Parse AWS ALB log
parse_aws_alb_log!(
"http 2018-11-30T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 - 0.000 0.001 0.000 200 200 34 366 \"GET http://www.example.com:80/ HTTP/1.1\" \"curl/7.46.0\" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 \"Root=1-58337364-23a8c76965a2ef7629b185e3\" \"-\" \"-\" 0 2018-11-30T22:22:48.364000Z \"forward\" \"-\" \"-\" \"-\" \"-\" \"-\" \"-\""
)
{
"actions_executed": "forward",
"chosen_cert_arn": null,
"classification": null,
"classification_reason": null,
"client_host": "192.168.131.39:2817",
"domain_name": null,
"elb": "app/my-loadbalancer/50dc6c495c0c9188",
"elb_status_code": "200",
"error_reason": null,
"matched_rule_priority": "0",
"received_bytes": 34,
"redirect_url": null,
"request_creation_time": "2018-11-30T22:22:48.364000Z",
"request_method": "GET",
"request_processing_time": 0,
"request_protocol": "HTTP/1.1",
"request_url": "http://www.example.com:80/",
"response_processing_time": 0,
"sent_bytes": 366,
"ssl_cipher": null,
"ssl_protocol": null,
"target_group_arn": "arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067",
"target_host": null,
"target_port_list": [],
"target_processing_time": 0.001,
"target_status_code": "200",
"target_status_code_list": [],
"timestamp": "2018-11-30T22:23:00.186641Z",
"trace_id": "Root=1-58337364-23a8c76965a2ef7629b185e3",
"traceability_id": null,
"type": "http",
"user_agent": "curl/7.46.0"
}Parse AWS ALB log with trailing fields (non-strict mode)
parse_aws_alb_log!(
"http 2018-11-30T22:23:00.186641Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 - 0.000 0.001 0.000 200 200 34 366 \"GET http://www.example.com:80/ HTTP/1.1\" \"curl/7.46.0\" - - arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067 \"Root=1-58337364-23a8c76965a2ef7629b185e3\" \"-\" \"-\" 0 2018-11-30T22:22:48.364000Z \"forward\" \"-\" \"-\" \"-\" \"-\" \"-\" \"-\" TID_12345 \"-\" \"-\" \"-\"",
strict_mode: false
)
{
"actions_executed": "forward",
"chosen_cert_arn": null,
"classification": null,
"classification_reason": null,
"client_host": "192.168.131.39:2817",
"domain_name": null,
"elb": "app/my-loadbalancer/50dc6c495c0c9188",
"elb_status_code": "200",
"error_reason": null,
"matched_rule_priority": "0",
"received_bytes": 34,
"redirect_url": null,
"request_creation_time": "2018-11-30T22:22:48.364000Z",
"request_method": "GET",
"request_processing_time": 0,
"request_protocol": "HTTP/1.1",
"request_url": "http://www.example.com:80/",
"response_processing_time": 0,
"sent_bytes": 366,
"ssl_cipher": null,
"ssl_protocol": null,
"target_group_arn": "arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067",
"target_host": null,
"target_port_list": [],
"target_processing_time": 0.001,
"target_status_code": "200",
"target_status_code_list": [],
"timestamp": "2018-11-30T22:23:00.186641Z",
"trace_id": "Root=1-58337364-23a8c76965a2ef7629b185e3",
"traceability_id": "TID_12345",
"type": "http",
"user_agent": "curl/7.46.0"
}parse_aws_cloudwatch_log_subscription_message
fallible pureaws_kinesis_firehose source.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string representation of the message to parse. | yes |
Errors
Theparse_aws_cloudwatch_log_subscription_message function is fallible, which means that
error handling is required for these errors:value is not a properly formatted AWS CloudWatch Log subscription message.Examples
Parse AWS Cloudwatch Log subscription message
parse_aws_cloudwatch_log_subscription_message!(s'{
"messageType": "DATA_MESSAGE",
"owner": "111111111111",
"logGroup": "test",
"logStream": "test",
"subscriptionFilters": [
"Destination"
],
"logEvents": [
{
"id": "35683658089614582423604394983260738922885519999578275840",
"timestamp": 1600110569039,
"message": "{\"bytes\":26780,\"datetime\":\"14/Sep/2020:11:45:41-0400\",\"host\":\"157.130.216.193\",\"method\":\"PUT\",\"protocol\":\"HTTP/1.0\",\"referer\":\"https://www.principalcross-platform.io/markets/ubiquitous\",\"request\":\"/expedite/convergence\",\"source_type\":\"stdin\",\"status\":301,\"user-identifier\":\"-\"}"
}
]
}')
{
"log_events": [
{
"id": "35683658089614582423604394983260738922885519999578275840",
"message": "{\"bytes\":26780,\"datetime\":\"14/Sep/2020:11:45:41-0400\",\"host\":\"157.130.216.193\",\"method\":\"PUT\",\"protocol\":\"HTTP/1.0\",\"referer\":\"https://www.principalcross-platform.io/markets/ubiquitous\",\"request\":\"/expedite/convergence\",\"source_type\":\"stdin\",\"status\":301,\"user-identifier\":\"-\"}",
"timestamp": "2020-09-14T19:09:29.039Z"
}
],
"log_group": "test",
"log_stream": "test",
"message_type": "DATA_MESSAGE",
"owner": "111111111111",
"subscription_filters": [
"Destination"
]
}parse_aws_vpc_flow_log
fallible purevalue in the VPC Flow Logs format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | VPC Flow Log. | yes | |
| format | string | VPC Flow Log format. | no |
Errors
Theparse_aws_vpc_flow_log function is fallible, which means that
error handling is required for these errors:value is not a properly formatted AWS VPC Flow log.Examples
Parse AWS VPC Flow log (default format)
parse_aws_vpc_flow_log!("2 123456789010 eni-1235b8ca123456789 - - - - - - - 1431280876 1431280934 - NODATA"){
"account_id": "123456789010",
"action": null,
"bytes": null,
"dstaddr": null,
"dstport": null,
"end": 1431280934,
"interface_id": "eni-1235b8ca123456789",
"log_status": "NODATA",
"packets": null,
"protocol": null,
"srcaddr": null,
"srcport": null,
"start": 1431280876,
"version": 2
}Parse AWS VPC Flow log (custom format)
parse_aws_vpc_flow_log!(
"- eni-1235b8ca123456789 10.0.1.5 10.0.0.220 10.0.1.5 203.0.113.5",
"instance_id interface_id srcaddr dstaddr pkt_srcaddr pkt_dstaddr"
)
{
"dstaddr": "10.0.0.220",
"instance_id": null,
"interface_id": "eni-1235b8ca123456789",
"pkt_dstaddr": "203.0.113.5",
"pkt_srcaddr": "10.0.1.5",
"srcaddr": "10.0.1.5"
}Parse AWS VPC Flow log including v5 fields
parse_aws_vpc_flow_log!(
"5 52.95.128.179 10.0.0.71 80 34210 6 1616729292 1616729349 IPv4 14 15044 123456789012 vpc-abcdefab012345678 subnet-aaaaaaaa012345678 i-0c50d5961bcb2d47b eni-1235b8ca123456789 ap-southeast-2 apse2-az3 - - ACCEPT 19 52.95.128.179 10.0.0.71 S3 - - ingress OK",
format: "version srcaddr dstaddr srcport dstport protocol start end type packets bytes account_id vpc_id subnet_id instance_id interface_id region az_id sublocation_type sublocation_id action tcp_flags pkt_srcaddr pkt_dstaddr pkt_src_aws_service pkt_dst_aws_service traffic_path flow_direction log_status"
)
{
"account_id": "123456789012",
"action": "ACCEPT",
"az_id": "apse2-az3",
"bytes": 15044,
"dstaddr": "10.0.0.71",
"dstport": 34210,
"end": 1616729349,
"flow_direction": "ingress",
"instance_id": "i-0c50d5961bcb2d47b",
"interface_id": "eni-1235b8ca123456789",
"log_status": "OK",
"packets": 14,
"pkt_dst_aws_service": null,
"pkt_dstaddr": "10.0.0.71",
"pkt_src_aws_service": "S3",
"pkt_srcaddr": "52.95.128.179",
"protocol": 6,
"region": "ap-southeast-2",
"srcaddr": "52.95.128.179",
"srcport": 80,
"start": 1616729292,
"sublocation_id": null,
"sublocation_type": null,
"subnet_id": "subnet-aaaaaaaa012345678",
"tcp_flags": 19,
"traffic_path": null,
"type": "IPv4",
"version": 5,
"vpc_id": "vpc-abcdefab012345678"
}parse_bytes
fallible purevalue into a human-readable bytes format specified by unit and base.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string of the duration with either binary or SI unit. | yes | |
| unit | string | The output units for the byte. | yes | |
| base | string | The base for the byte, either 2 or 10. | 2 | no |
Errors
Theparse_bytes function is fallible, which means that
error handling is required for these errors:value is not a properly formatted bytes.Examples
Parse bytes (kilobytes)
parse_bytes!("1024KiB", unit: "MiB")1Parse kilobytes in default binary units
parse_bytes!("1KiB", unit: "B")1024Parse bytes in SI unit (terabytes)
parse_bytes!("4TB", unit: "MB", base: "10")4000000Parse gigabytes in decimal units
parse_bytes!("1GB", unit: "B", base: "10")1000000000Parse bytes in ambiguous unit (gigabytes)
parse_bytes!("1GB", unit: "B", base: "2")1073741824Parse gigabytes in ambiguous decimal units
parse_bytes!("1GB", unit: "MB", base: "2")1024parse_cbor
fallible purevalue as CBOR.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The CBOR payload to parse. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_cbor function is fallible, which means that
error handling is required for these errors:value is not a valid CBOR-formatted payload.Examples
Parse CBOR
parse_cbor!(decode_base64!("oWVmaWVsZGV2YWx1ZQ==")){
"field": "value"
}array
parse_cbor!(decode_base64!("gvUA"))[true,0]string
parse_cbor!(decode_base64!("ZWhlbGxv"))hellointeger
parse_cbor!(decode_base64!("GCo="))42float
parse_cbor!(decode_base64!("+0BFEKPXCj1x"))42.13boolean
parse_cbor!(decode_base64!("9A=="))falseparse_cef
fallible purevalue in CEF (Common Event Format) format. Ignores everything up to CEF header. Empty values are returned as empty strings. Surrounding quotes are removed from values.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| translate_custom_fields | boolean | Toggles translation of custom field pairs to key:value. | false | no |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_cef function is fallible, which means that
error handling is required for these errors:value is not a properly formatted CEF string.Examples
Parse output generated by PTA
parse_cef!(
"CEF:0|CyberArk|PTA|12.6|1|Suspected credentials theft|8|suser=mike2@prod1.domain.com shost=prod1.domain.com src=1.1.1.1 duser=andy@dev1.domain.com dhost=dev1.domain.com dst=2.2.2.2 cs1Label=ExtraData cs1=None cs2Label=EventID cs2=52b06812ec3500ed864c461e deviceCustomDate1Label=detectionDate deviceCustomDate1=1388577900000 cs3Label=PTAlink cs3=https://1.1.1.1/incidents/52b06812ec3500ed864c461e cs4Label=ExternalLink cs4=None"
)
{
"cefVersion": "0",
"cs1": "None",
"cs1Label": "ExtraData",
"cs2": "52b06812ec3500ed864c461e",
"cs2Label": "EventID",
"cs3": "https://1.1.1.1/incidents/52b06812ec3500ed864c461e",
"cs3Label": "PTAlink",
"cs4": "None",
"cs4Label": "ExternalLink",
"deviceCustomDate1": "1388577900000",
"deviceCustomDate1Label": "detectionDate",
"deviceEventClassId": "1",
"deviceProduct": "PTA",
"deviceVendor": "CyberArk",
"deviceVersion": "12.6",
"dhost": "dev1.domain.com",
"dst": "2.2.2.2",
"duser": "andy@dev1.domain.com",
"name": "Suspected credentials theft",
"severity": "8",
"shost": "prod1.domain.com",
"src": "1.1.1.1",
"suser": "mike2@prod1.domain.com"
}Ignore syslog header
parse_cef!(
"Sep 29 08:26:10 host CEF:1|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232"
)
{
"cefVersion": "1",
"deviceEventClassId": "100",
"deviceProduct": "threatmanager",
"deviceVendor": "Security",
"deviceVersion": "1.0",
"dst": "2.1.2.2",
"name": "worm successfully stopped",
"severity": "10",
"spt": "1232",
"src": "10.0.0.1"
}Translate custom fields
parse_cef!(
"CEF:0|Dev|firewall|2.2|1|Connection denied|5|c6a1=2345:0425:2CA1:0000:0000:0567:5673:23b5 c6a1Label=Device IPv6 Address",
translate_custom_fields: true
)
{
"Device IPv6 Address": "2345:0425:2CA1:0000:0000:0567:5673:23b5",
"cefVersion": "0",
"deviceEventClassId": "1",
"deviceProduct": "firewall",
"deviceVendor": "Dev",
"deviceVersion": "2.2",
"name": "Connection denied",
"severity": "5"
}Parse CEF with only header
parse_cef!("CEF:1|Security|threatmanager|1.0|100|worm successfully stopped|10|"){
"cefVersion": "1",
"deviceEventClassId": "100",
"deviceProduct": "threatmanager",
"deviceVendor": "Security",
"deviceVersion": "1.0",
"name": "worm successfully stopped",
"severity": "10"
}Parse CEF with empty value
parse_cef!("CEF:0|CyberArk|PTA|12.6|1|Suspected credentials theft||suser=mike2@prod1.domain.com shost= src=1.1.1.1"){
"cefVersion": "0",
"deviceEventClassId": "1",
"deviceProduct": "PTA",
"deviceVendor": "CyberArk",
"deviceVersion": "12.6",
"name": "Suspected credentials theft",
"severity": "",
"shost": "",
"src": "1.1.1.1",
"suser": "mike2@prod1.domain.com"
}Parse CEF with escapes
parse_cef!(s'CEF:0|security|threatmanager|1.0|100|Detected a \| in message. No action needed.|10|src=10.0.0.1 msg=Detected a threat.\n No action needed act=blocked a \= dst=1.1.1.1'){
"act": "blocked a =",
"cefVersion": "0",
"deviceEventClassId": "100",
"deviceProduct": "threatmanager",
"deviceVendor": "security",
"deviceVersion": "1.0",
"dst": "1.1.1.1",
"msg": "Detected a threat.\n No action needed",
"name": "Detected a | in message. No action needed.",
"severity": "10",
"src": "10.0.0.1"
}parse_common_log
fallible purevalue using the Common Log Format (CLF).Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| timestamp_format | string | The date/time format to use for encoding the timestamp. | %d/%b/%Y:%T %z | no |
Notices
This function has special behavior that you should be aware of.-. These fields are omitted in the result.Errors
Theparse_common_log function is fallible, which means that
error handling is required for these errors:value does not match the Common Log Format.timestamp_format is not a valid format string.value fails to parse using the provided timestamp_format.Examples
Parse using Common Log Format (with default timestamp format)
parse_common_log!(s'127.0.0.1 bob frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326'){
"host": "127.0.0.1",
"identity": "bob",
"message": "GET /apache_pb.gif HTTP/1.0",
"method": "GET",
"path": "/apache_pb.gif",
"protocol": "HTTP/1.0",
"size": 2326,
"status": 200,
"timestamp": "2000-10-10T20:55:36Z",
"user": "frank"
}Parse using Common Log Format (with custom timestamp format)
parse_common_log!(
s'127.0.0.1 bob frank [2000-10-10T20:55:36Z] "GET /apache_pb.gif HTTP/1.0" 200 2326',
"%+"
)
{
"host": "127.0.0.1",
"identity": "bob",
"message": "GET /apache_pb.gif HTTP/1.0",
"method": "GET",
"path": "/apache_pb.gif",
"protocol": "HTTP/1.0",
"size": 2326,
"status": 200,
"timestamp": "2000-10-10T20:55:36Z",
"user": "frank"
}parse_csv
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| delimiter | string | The field delimiter to use when parsing. Must be a single-byte utf8 character. | , | no |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_csv function is fallible, which means that
error handling is required for these errors:value is not a valid CSV string.Examples
Parse a single CSV formatted row
parse_csv!(s'foo,bar,"foo "", bar"')["foo","bar","foo \", bar"]Parse a single CSV formatted row with custom delimiter
parse_csv!("foo bar", delimiter: " ")["foo","bar"]parse_dnstap
fallible purevalue as base64 encoded DNSTAP data.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The base64 encoded representation of the DNSTAP data to parse. | yes | |
| lowercase_hostnames | boolean | Whether to turn all hostnames found in resulting data lowercase, for consistency. | false | no |
Errors
Theparse_dnstap function is fallible, which means that
error handling is required for these errors:value is not a valid base64 encoded string.valueExamples
Parse dnstap query message
parse_dnstap!("ChVqYW1lcy1WaXJ0dWFsLU1hY2hpbmUSC0JJTkQgOS4xNi4zGgBy5wEIAxACGAEiEAAAAAAAAAAAAAAAAAAAAAAqECABBQJwlAAAAAAAAAAAADAw8+0CODVA7+zq9wVNMU3WNlI2kwIAAAABAAAAAAABCWZhY2Vib29rMQNjb20AAAEAAQAAKQIAAACAAAAMAAoACOxjCAG9zVgzWgUDY29tAGAAbQAAAAByZLM4AAAAAQAAAAAAAQJoNQdleGFtcGxlA2NvbQAABgABAAApBNABAUAAADkADwA1AAlubyBTRVAgbWF0Y2hpbmcgdGhlIERTIGZvdW5kIGZvciBkbnNzZWMtZmFpbGVkLm9yZy54AQ=="){
"dataType": "Message",
"dataTypeId": 1,
"extraInfo": "",
"messageType": "ResolverQuery",
"messageTypeId": 3,
"queryZone": "com.",
"requestData": {
"fullRcode": 0,
"header": {
"aa": false,
"ad": false,
"anCount": 0,
"arCount": 1,
"cd": false,
"id": 37634,
"nsCount": 0,
"opcode": 0,
"qdCount": 1,
"qr": 0,
"ra": false,
"rcode": 0,
"rd": false,
"tc": false
},
"opt": {
"do": true,
"ednsVersion": 0,
"extendedRcode": 0,
"options": [
{
"optCode": 10,
"optName": "Cookie",
"optValue": "7GMIAb3NWDM="
}
],
"udpPayloadSize": 512
},
"question": [
{
"class": "IN",
"domainName": "facebook1.com.",
"questionType": "A",
"questionTypeId": 1
}
],
"rcodeName": "NoError"
},
"responseAddress": "2001:502:7094::30",
"responseData": {
"fullRcode": 16,
"header": {
"aa": false,
"ad": false,
"anCount": 0,
"arCount": 1,
"cd": false,
"id": 45880,
"nsCount": 0,
"opcode": 0,
"qdCount": 1,
"qr": 0,
"ra": false,
"rcode": 16,
"rd": false,
"tc": false
},
"opt": {
"do": false,
"ede": [
{
"extraText": "no SEP matching the DS found for dnssec-failed.org.",
"infoCode": 9,
"purpose": "DNSKEY Missing"
}
],
"ednsVersion": 1,
"extendedRcode": 1,
"udpPayloadSize": 1232
},
"question": [
{
"class": "IN",
"domainName": "h5.example.com.",
"questionType": "SOA",
"questionTypeId": 6
}
],
"rcodeName": "BADVERS"
},
"responsePort": 53,
"serverId": "james-Virtual-Machine",
"serverVersion": "BIND 9.16.3",
"socketFamily": "INET6",
"socketProtocol": "UDP",
"sourceAddress": "::",
"sourcePort": 46835,
"time": 1593489007920014000,
"timePrecision": "ns",
"timestamp": "2020-06-30T03:50:07.920014129Z"
}parse_duration
fallible purevalue into a human-readable duration format specified by unit.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string of the duration. | yes | |
| unit | string | The output units for the duration. | yes |
Errors
Theparse_duration function is fallible, which means that
error handling is required for these errors:value is not a properly formatted duration.Examples
Parse duration (milliseconds)
parse_duration!("1005ms", unit: "s")1.005Parse multiple durations (seconds & milliseconds)
parse_duration!("1s 1ms", unit: "ms")1001parse_etld
fallible purevalue representing domain name.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The domain string. | yes | |
| plus_parts | integer | Can be provided to get additional parts of the domain name. When 1 is passed, eTLD+1 will be returned, which represents a domain registrable by a single organization. Higher numbers will return subdomains. | 0 | no |
| psl | string | Can be provided to use a different public suffix list. By default, https://publicsuffix.org/list/public_suffix_list.dat is used. | no |
Errors
Theparse_etld function is fallible, which means that
error handling is required for these errors:valueExamples
Parse eTLD
parse_etld!("sub.sussex.ac.uk"){
"etld": "ac.uk",
"etld_plus": "ac.uk",
"known_suffix": true
}Parse eTLD+1
parse_etld!("sub.sussex.ac.uk", plus_parts: 1){
"etld": "ac.uk",
"etld_plus": "sussex.ac.uk",
"known_suffix": true
}Parse eTLD with unknown suffix
parse_etld!("vector.acmecorp"){
"etld": "acmecorp",
"etld_plus": "acmecorp",
"known_suffix": false
}Parse eTLD with custom PSL
parse_etld!("vector.acmecorp", psl: "lib/tests/tests/functions/custom_public_suffix_list.dat"){
"etld": "acmecorp",
"etld_plus": "acmecorp",
"known_suffix": false
}parse_glog
fallible purevalue using the glog (Google Logging Library) format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes |
Errors
Theparse_glog function is fallible, which means that
error handling is required for these errors:value does not match the glog format.Examples
Parse using glog
parse_glog!("I20210131 14:48:54.411655 15520 main.c++:9] Hello world!"){
"file": "main.c++",
"id": 15520,
"level": "info",
"line": 9,
"message": "Hello world!",
"timestamp": "2021-01-31T14:48:54.411655Z"
}parse_grok
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| pattern | string | The Grok pattern. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_grok function is fallible, which means that
error handling is required for these errors:value fails to parse using the provided pattern.Examples
Parse using Grok
value = "2020-10-02T23:22:12.223222Z info Hello world"
pattern = "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:level} %{GREEDYDATA:message}"
parse_grok!(value, pattern)
{
"level": "info",
"message": "Hello world",
"timestamp": "2020-10-02T23:22:12.223222Z"
}parse_groks
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| patterns | array | The Grok patterns, which are tried in order until the first match. | yes | |
| aliases | object | The shared set of grok aliases that can be referenced in the patterns to simplify them. | { } | no |
| alias_sources | array | Path to the file containing aliases in a JSON format. | [] | no |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_groks function is fallible, which means that
error handling is required for these errors:value fails to parse using the provided pattern.patterns is not an array.aliases is not an object.alias_sources is not a string array or doesn’t point to a valid file.Examples
Parse using multiple Grok patterns
parse_groks!(
"2020-10-02T23:22:12.223222Z info Hello world",
patterns: [
"%{common_prefix} %{_status} %{_message}",
"%{common_prefix} %{_message}",
],
aliases: {
"common_prefix": "%{_timestamp} %{_loglevel}",
"_timestamp": "%{TIMESTAMP_ISO8601:timestamp}",
"_loglevel": "%{LOGLEVEL:level}",
"_status": "%{POSINT:status}",
"_message": "%{GREEDYDATA:message}"
}
)
{
"level": "info",
"message": "Hello world",
"timestamp": "2020-10-02T23:22:12.223222Z"
}Parse using aliases from file
parse_groks!(
"username=foo",
patterns: [ "%{PATTERN_A}" ],
alias_sources: [ "tests/data/grok/aliases.json" ]
)
# aliases.json contents:
# {
# "PATTERN_A": "%{PATTERN_B}",
# "PATTERN_B": "username=%{USERNAME:username}"
# }
{
"username": "foo"
}parse_influxdb
fallible purevalue as an InfluxDB line protocol string, producing a list of Vector-compatible metrics.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string representation of the InfluxDB line protocol to parse. | yes |
Notices
This function has special behavior that you should be aware of.log_to_metric transform with the option all_metrics set to
true to convert the metric-shaped log events to metric events so real metrics
are produced.gauge. Each metric name is prefixed
with the measurement field, followed by an underscore (_), and then the
field key field.string is the only type that is not supported as a field value, due to limitations
of Vector’s metric model.Errors
Theparse_influxdb function is fallible, which means that
error handling is required for these errors:value is not a valid InfluxDB line protocol string.string.NaN field value.Examples
Parse InfluxDB line protocol
parse_influxdb!("cpu,host=A,region=us-west usage_system=64i,usage_user=10u,temperature=50.5,on=true,sleep=false 1590488773254420000")[{"gauge":{"value":64},"kind":"absolute","name":"cpu_usage_system","tags":{"host":"A","region":"us-west"},"timestamp":"2020-05-26T10:26:13.254420Z"},{"gauge":{"value":10},"kind":"absolute","name":"cpu_usage_user","tags":{"host":"A","region":"us-west"},"timestamp":"2020-05-26T10:26:13.254420Z"},{"gauge":{"value":50.5},"kind":"absolute","name":"cpu_temperature","tags":{"host":"A","region":"us-west"},"timestamp":"2020-05-26T10:26:13.254420Z"},{"gauge":{"value":1},"kind":"absolute","name":"cpu_on","tags":{"host":"A","region":"us-west"},"timestamp":"2020-05-26T10:26:13.254420Z"},{"gauge":{"value":0},"kind":"absolute","name":"cpu_sleep","tags":{"host":"A","region":"us-west"},"timestamp":"2020-05-26T10:26:13.254420Z"}]parse_int
fallible purevalue representing a number in an optional base/radix to an integer.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| base | integer | The base the number is in. Must be between 2 and 36 (inclusive). If unspecified, the string prefix is used to determine the base: “0b”, 8 for “0” or “0o”, 16 for “0x”, and 10 otherwise. | no |
Errors
Theparse_int function is fallible, which means that
error handling is required for these errors:Examples
Parse decimal
parse_int!("-42")-42Parse binary
parse_int!("0b1001")9Parse octal
parse_int!("0o42")34Parse hexadecimal
parse_int!("0x2a")42Parse explicit base
parse_int!("2a", 17)44parse_json
fallible pureParses the provided value as JSON.
Only JSON types are returned. If you need to convert a string into a timestamp,
consider the parse_timestamp function.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string representation of the JSON to parse. | yes | |
| max_depth | integer | Number of layers to parse for nested JSON-formatted documents. The value must be in the range of 1 to 128. | no | |
| lossy | boolean | Whether to parse the JSON in a lossy manner. Replaces invalid UTF-8 characters
with the Unicode character � (U+FFFD) if set to true, otherwise returns an error
if there are any invalid UTF-8 characters present. | true | no |
Notices
This function has special behavior that you should be aware of.string into a timestamp,
consider the parse_timestamp function.Errors
Theparse_json function is fallible, which means that
error handling is required for these errors:value is not a valid JSON-formatted payload.Examples
Parse JSON
parse_json!(s'{"key": "val"}'){
"key": "val"
}Parse JSON array
parse_json!("[true, 0]")[true,0]Parse JSON string
parse_json!(s'"hello"')helloParse JSON integer
parse_json!("42")42Parse JSON float
parse_json!("42.13")42.13Parse JSON boolean
parse_json!("false")falseInvalid JSON value
parse_json!("{ INVALID }")function call error for "parse_json" at (0:26): unable to parse json: key must be a string at line 1 column 3Parse JSON with max_depth
parse_json!(s'{"first_level":{"second_level":"finish"}}', max_depth: 1){
"first_level": "{\"second_level\":\"finish\"}"
}parse_key_value
fallible pureParses the value in key-value format. Also known as logfmt.
- Keys and values can be wrapped with
". "characters can be escaped using\.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| key_value_delimiter | string | The string that separates the key from the value. | = | no |
| field_delimiter | string | The string that separates each key-value pair. | | no |
| whitespace | string | Defines the acceptance of unnecessary whitespace surrounding the configured key_value_delimiter. | lenient | no |
| accept_standalone_key | boolean | Whether a standalone key should be accepted, the resulting object associates such keys with the boolean value true. | true | no |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_key_value function is fallible, which means that
error handling is required for these errors:value is not a properly formatted key-value string.Examples
Parse simple key value pairs
parse_key_value!("zork=zook zonk=nork"){
"zonk": "nork",
"zork": "zook"
}Parse logfmt log
parse_key_value!(
"@timestamp=\"Sun Jan 10 16:47:39 EST 2021\" level=info msg=\"Stopping all fetchers\" tag#production=stopping_fetchers id=ConsumerFetcherManager-1382721708341 module=kafka.consumer.ConsumerFetcherManager"
)
{
"@timestamp": "Sun Jan 10 16:47:39 EST 2021",
"id": "ConsumerFetcherManager-1382721708341",
"level": "info",
"module": "kafka.consumer.ConsumerFetcherManager",
"msg": "Stopping all fetchers",
"tag#production": "stopping_fetchers"
}Parse comma delimited log
parse_key_value!(
"path:\"/cart_link\", host:store.app.com, fwd: \"102.30.171.16\", dyno: web.1, connect:0ms, service:87ms, status:304, bytes:632, protocol:https",
field_delimiter: ",",
key_value_delimiter: ":"
)
{
"bytes": "632",
"connect": "0ms",
"dyno": "web.1",
"fwd": "102.30.171.16",
"host": "store.app.com",
"path": "/cart_link",
"protocol": "https",
"service": "87ms",
"status": "304"
}Parse comma delimited log with standalone keys
parse_key_value!(
"env:prod,service:backend,region:eu-east1,beta",
field_delimiter: ",",
key_value_delimiter: ":",
)
{
"beta": true,
"env": "prod",
"region": "eu-east1",
"service": "backend"
}Parse duplicate keys
parse_key_value!(
"at=info,method=GET,path=\"/index\",status=200,tags=dev,tags=dummy",
field_delimiter: ",",
key_value_delimiter: "=",
)
{
"at": "info",
"method": "GET",
"path": "/index",
"status": "200",
"tags": [
"dev",
"dummy"
]
}Parse with strict whitespace
parse_key_value!(s'app=my-app ip=1.2.3.4 user= msg=hello-world', whitespace: "strict"){
"app": "my-app",
"ip": "1.2.3.4",
"msg": "hello-world",
"user": ""
}parse_klog
fallible purevalue using the klog format used by Kubernetes components.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_klog function is fallible, which means that
error handling is required for these errors:value does not match the klog format.Examples
Parse using klog
parse_klog!("I0505 17:59:40.692994 28133 klog.go:70] hello from klog"){
"file": "klog.go",
"id": 28133,
"level": "info",
"line": 70,
"message": "hello from klog",
"timestamp": "2026-05-05T17:59:40.692994Z"
}parse_linux_authorization
fallible pure/var/log/auth.log (for Debian-based systems) or /var/log/secure (for RedHat-based systems) according to Syslog format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The text containing the message to parse. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_linux_authorization function is fallible, which means that
error handling is required for these errors:value is not a properly formatted Syslog message.Examples
Parse Linux authorization event
parse_linux_authorization!(
s'Mar 23 01:49:58 localhost sshd[1111]: Accepted publickey for eng from 10.1.1.1 port 8888 ssh2: RSA SHA256:foobar'
)
{
"appname": "sshd",
"hostname": "localhost",
"message": "Accepted publickey for eng from 10.1.1.1 port 8888 ssh2: RSA SHA256:foobar",
"procid": 1111,
"timestamp": "2026-03-23T01:49:58Z"
}parse_logfmt
fallible pureParses the value in logfmt.
- Keys and values can be wrapped using the
"character. "characters can be escaped by the\character.- As per this logfmt specification, the
parse_logfmtfunction accepts standalone keys and assigns them a Boolean value oftrue.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes |
Errors
Theparse_logfmt function is fallible, which means that
error handling is required for these errors:value is not a properly formatted key-value stringExamples
Parse simple logfmt log
parse_logfmt!("zork=zook zonk=nork"){
"zonk": "nork",
"zork": "zook"
}Parse logfmt log
parse_logfmt!(
"@timestamp=\"Sun Jan 10 16:47:39 EST 2021\" level=info msg=\"Stopping all fetchers\" tag#production=stopping_fetchers id=ConsumerFetcherManager-1382721708341 module=kafka.consumer.ConsumerFetcherManager"
)
{
"@timestamp": "Sun Jan 10 16:47:39 EST 2021",
"id": "ConsumerFetcherManager-1382721708341",
"level": "info",
"module": "kafka.consumer.ConsumerFetcherManager",
"msg": "Stopping all fetchers",
"tag#production": "stopping_fetchers"
}Parse logfmt log with standalone key
parse_logfmt!("zork=zook plonk zonk=nork"){
"plonk": true,
"zonk": "nork",
"zork": "zook"
}parse_nginx_log
fallible purecombined, ingress_upstreaminfo, main or error format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| format | string | The format to use for parsing the log. | yes | |
| timestamp_format | string | The date/time format to use for encoding the timestamp. The time is parsed
in local time if the timestamp doesn’t specify a timezone. The default format is %d/%b/%Y:%T %z for
combined logs and %Y/%m/%d %H:%M:%S for error logs. | %d/%b/%Y:%T %z | no |
Notices
This function has special behavior that you should be aware of.-. These fields are
omitted in the result.ingress_upstreaminfo format the following fields may be safely omitted
in the log message: remote_addr, remote_user, http_referer, http_user_agent,
proxy_alternative_upstream_name, upstream_addr, upstream_response_length,
upstream_response_time, upstream_status.Errors
Theparse_nginx_log function is fallible, which means that
error handling is required for these errors:value does not match the specified format.timestamp_format is not a valid format string.value fails to parse using the provided timestamp_format.Examples
Parse via Nginx log format (combined)
parse_nginx_log!(
s'172.17.0.1 - alice [01/Apr/2021:12:02:31 +0000] "POST /not-found HTTP/1.1" 404 153 "http://localhost/somewhere" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" "2.75"',
"combined",
)
{
"agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36",
"client": "172.17.0.1",
"compression": "2.75",
"referer": "http://localhost/somewhere",
"request": "POST /not-found HTTP/1.1",
"size": 153,
"status": 404,
"timestamp": "2021-04-01T12:02:31Z",
"user": "alice"
}Parse via Nginx log format (error)
parse_nginx_log!(
s'2021/04/01 13:02:31 [error] 31#31: *1 open() "/usr/share/nginx/html/not-found" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "POST /not-found HTTP/1.1", host: "localhost:8081"',
"error"
)
{
"cid": 1,
"client": "172.17.0.1",
"host": "localhost:8081",
"message": "open() \"/usr/share/nginx/html/not-found\" failed (2: No such file or directory)",
"pid": 31,
"request": "POST /not-found HTTP/1.1",
"server": "localhost",
"severity": "error",
"tid": 31,
"timestamp": "2021-04-01T13:02:31Z"
}Parse via Nginx log format (ingress_upstreaminfo)
parse_nginx_log!(
s'0.0.0.0 - bob [18/Mar/2023:15:00:00 +0000] "GET /some/path HTTP/2.0" 200 12312 "https://10.0.0.1/some/referer" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" 462 0.050 [some-upstream-service-9000] [some-other-upstream-5000] 10.0.50.80:9000 19437 0.049 200 752178adb17130b291aefd8c386279e7',
"ingress_upstreaminfo"
)
{
"body_bytes_size": 12312,
"http_referer": "https://10.0.0.1/some/referer",
"http_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
"proxy_alternative_upstream_name": "some-other-upstream-5000",
"proxy_upstream_name": "some-upstream-service-9000",
"remote_addr": "0.0.0.0",
"remote_user": "bob",
"req_id": "752178adb17130b291aefd8c386279e7",
"request": "GET /some/path HTTP/2.0",
"request_length": 462,
"request_time": 0.05,
"status": 200,
"timestamp": "2023-03-18T15:00:00Z",
"upstream_addr": "10.0.50.80:9000",
"upstream_response_length": 19437,
"upstream_response_time": 0.049,
"upstream_status": 200
}Parse via Nginx log format (main)
parse_nginx_log!(
s'172.24.0.3 - alice [31/Dec/2024:17:32:06 +0000] "GET / HTTP/1.1" 200 615 "https://domain.tld/path" "curl/8.11.1" "1.2.3.4, 10.10.1.1"',
"main"
)
{
"body_bytes_size": 615,
"http_referer": "https://domain.tld/path",
"http_user_agent": "curl/8.11.1",
"http_x_forwarded_for": "1.2.3.4, 10.10.1.1",
"remote_addr": "172.24.0.3",
"remote_user": "alice",
"request": "GET / HTTP/1.1",
"status": 200,
"timestamp": "2024-12-31T17:32:06Z"
}parse_proto
fallible purevalue as a protocol buffer payload.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The protocol buffer payload to parse. | yes | |
| desc_file | string | The path to the protobuf descriptor set file. Must be a literal string. This file is the output of protoc -o | yes | |
| message_type | string | The name of the message type to use for serializing. Must be a literal string. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_proto function is fallible, which means that
error handling is required for these errors:value is not a valid proto payload.desc_file file does not exist.message_type message type does not exist in the descriptor file.Examples
Parse proto
parse_proto!(decode_base64!("Cgdzb21lb25lIggKBjEyMzQ1Ng=="), "test_protobuf.desc", "test_protobuf.v1.Person"){
"name": "someone",
"phones": [
{
"number": "123456"
}
]
}parse_query_string
infallible purevalue as a query string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes |
Notices
This function has special behavior that you should be aware of.Examples
Parse simple query string
parse_query_string("foo=1&bar=2"){
"bar": "2",
"foo": "1"
}Parse query string
parse_query_string("foo=%2B1&bar=2&bar=3&xyz"){
"bar": [
"2",
"3"
],
"foo": "+1",
"xyz": ""
}Parse Ruby on Rails’ query string
parse_query_string("?foo%5b%5d=1&foo%5b%5d=2"){
"foo[]": [
"1",
"2"
]
}parse_regex
fallible pureParses the value using the provided Regex pattern.
This function differs from the parse_regex_all function in that it returns only the first match.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to search. | yes | |
| pattern | regex | The regular expression pattern to search against. | yes | |
| numeric_groups | boolean | If true, the index of each group in the regular expression is also captured. Index 0
contains the whole match. | false | no |
Notices
This function has special behavior that you should be aware of.parse_regex function, see if a VRL
parse_* function already exists
for your format. If not, we recommend
opening an issue
to request support for the desired format.Errors
Theparse_regex function is fallible, which means that
error handling is required for these errors:value fails to parse using the provided pattern.Examples
Parse using Regex (with capture groups)
parse_regex!("first group and second group.", r'(?P<number>.*?) group'){
"number": "first"
}Parse using Regex (without capture groups)
parse_regex!("first group and second group.", r'(\w+) group', numeric_groups: true){
"0": "first group",
"1": "first"
}Parse using Regex with simple match
parse_regex!("8.7.6.5 - zorp", r'^(?P<host>[\w\.]+) - (?P<user>[\w]+)'){
"host": "8.7.6.5",
"user": "zorp"
}Parse using Regex with all numeric groups
parse_regex!("8.7.6.5 - zorp", r'^(?P<host>[\w\.]+) - (?P<user>[\w]+)', numeric_groups: true){
"0": "8.7.6.5 - zorp",
"1": "8.7.6.5",
"2": "zorp",
"host": "8.7.6.5",
"user": "zorp"
}Parse using Regex with variables
variable = r'^(?P<host>[\w\.]+) - (?P<user>[\w]+)';
parse_regex!("8.7.6.5 - zorp", variable)
{
"host": "8.7.6.5",
"user": "zorp"
}parse_regex_all
fallible pureParses the value using the provided Regex pattern.
This function differs from the parse_regex function in that it returns all matches, not just the first.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The string to search. | yes | |
| pattern | regex | The regular expression pattern to search against. | yes | |
| numeric_groups | boolean | If true, the index of each group in the regular expression is also captured. Index 0
contains the whole match. | false | no |
Notices
This function has special behavior that you should be aware of.parse_regex function, see if a VRL
parse_* function already exists
for your format. If not, we recommend
opening an issue
to request support for the desired format.Errors
Theparse_regex_all function is fallible, which means that
error handling is required for these errors:value is not a string.pattern is not a regex.Examples
Parse using Regex (all matches)
parse_regex_all!("first group and second group.", r'(?P<number>\w+) group', numeric_groups: true)[{"0":"first group","1":"first","number":"first"},{"0":"second group","1":"second","number":"second"}]Parse using Regex (simple match)
parse_regex_all!("apples and carrots, peaches and peas", r'(?P<fruit>[\w\.]+) and (?P<veg>[\w]+)')[{"fruit":"apples","veg":"carrots"},{"fruit":"peaches","veg":"peas"}]Parse using Regex (all numeric groups)
parse_regex_all!("apples and carrots, peaches and peas", r'(?P<fruit>[\w\.]+) and (?P<veg>[\w]+)', numeric_groups: true)[{"0":"apples and carrots","1":"apples","2":"carrots","fruit":"apples","veg":"carrots"},{"0":"peaches and peas","1":"peaches","2":"peas","fruit":"peaches","veg":"peas"}]Parse using Regex with variables
variable = r'(?P<fruit>[\w\.]+) and (?P<veg>[\w]+)';
parse_regex_all!("apples and carrots, peaches and peas", variable)
[{"fruit":"apples","veg":"carrots"},{"fruit":"peaches","veg":"peas"}]parse_ruby_hash
fallible purevalue as ruby hash.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string representation of the ruby hash to parse. | yes |
Notices
This function has special behavior that you should be aware of.string into a timestamp,
consider the parse_timestamp function.Errors
Theparse_ruby_hash function is fallible, which means that
error handling is required for these errors:value is not a valid ruby hash formatted payload.Examples
Parse ruby hash
parse_ruby_hash!(s'{ "test" => "value", "testNum" => 0.2, "testObj" => { "testBool" => true, "testNull" => nil } }'){
"test": "value",
"testNum": 0.2,
"testObj": {
"testBool": true,
"testNull": null
}
}parse_syslog
fallible purevalue in Syslog format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The text containing the Syslog message to parse. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_syslog function is fallible, which means that
error handling is required for these errors:value is not a properly formatted Syslog message.Examples
Parse Syslog log (5424)
parse_syslog!(s'<13>1 2020-03-13T20:45:38.119Z dynamicwireless.name non 2426 ID931 [exampleSDID@32473 iut="3" eventSource= "Application" eventID="1011"] Try to override the THX port, maybe it will reboot the neural interface!'){
"appname": "non",
"exampleSDID@32473": {
"eventID": "1011",
"eventSource": "Application",
"iut": "3"
},
"facility": "user",
"hostname": "dynamicwireless.name",
"message": "Try to override the THX port, maybe it will reboot the neural interface!",
"msgid": "ID931",
"procid": 2426,
"severity": "notice",
"timestamp": "2020-03-13T20:45:38.119Z",
"version": 1
}parse_timestamp
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string timestamp | The text of the timestamp. | yes | |
| format | string | The strptime format. | yes | |
| timezone | string | The TZ database format. By default, this function parses the timestamp by global timezone option.
This argument overwrites the setting and is useful for parsing timestamps without a specified timezone, such as 16/10/2019 12:00:00. | no |
Errors
Theparse_timestamp function is fallible, which means that
error handling is required for these errors:value fails to parse using the provided format.value fails to parse using the provided timezone.Examples
Parse timestamp
parse_timestamp!("10-Oct-2020 16:00+00:00", format: "%v %R %:z")t'2020-10-10T16:00:00Z'Parse timestamp with timezone
parse_timestamp!("16/10/2019 12:00:00", format: "%d/%m/%Y %H:%M:%S", timezone: "Asia/Taipei")t'2019-10-16T04:00:00Z'parse_tokens
fallible pureParses the value in token format. A token is considered to be one of the following:
- A word surrounded by whitespace.
- Text delimited by double quotes:
"..". Quotes can be included in the token if they are escaped by a backslash (\). - Text delimited by square brackets:
[..]. Closing square brackets can be included in the token if they are escaped by a backslash (\).
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to tokenize. | yes |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_tokens function is fallible, which means that
error handling is required for these errors:value is not a properly formatted tokenized string.Examples
Parse tokens
parse_tokens(s'A sentence "with \"a\" sentence inside" and [some brackets]')["A","sentence","with \\\"a\\\" sentence inside","and","some brackets"]parse_url
fallible purevalue in URL format.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The text of the URL. | yes | |
| default_known_ports | boolean | If true and the port number is not specified in the input URL
string (or matches the default port for the scheme), it is
populated from well-known ports for the following schemes:
http, https, ws, wss, and ftp. | false | no |
Errors
Theparse_url function is fallible, which means that
error handling is required for these errors:value is not a properly formatted URL.Examples
Parse URL
parse_url!("ftp://foo:bar@example.com:4343/foobar?hello=world#123"){
"fragment": "123",
"host": "example.com",
"password": "bar",
"path": "/foobar",
"port": 4343,
"query": {
"hello": "world"
},
"scheme": "ftp",
"username": "foo"
}Parse URL with default port
parse_url!("https://example.com", default_known_ports: true){
"fragment": null,
"host": "example.com",
"password": "",
"path": "/",
"port": 443,
"query": {},
"scheme": "https",
"username": ""
}parse_user_agent
infallible pureParses the provided value as a user agent, which has
a loosely defined format.
Parses on the basis of best effort. Returned schema depends only on the configured mode,
so if the function fails to parse a field it will set it to null.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes | |
| mode | string | Determines performance and reliability characteristics. | fast | no |
Notices
This function has special behavior that you should be aware of.null.Examples
Fast mode
parse_user_agent(
"Mozilla Firefox 1.0.1 Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.7.6) Gecko/20050223 Firefox/1.0.1"
)
{
"browser": {
"family": "Firefox",
"version": "1.0.1"
},
"device": {
"category": "pc"
},
"os": {
"family": "Linux",
"version": null
}
}Reliable mode
parse_user_agent(
"Mozilla/4.0 (compatible; MSIE 7.66; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
mode: "reliable")
{
"browser": {
"family": "Internet Explorer",
"version": "7.66"
},
"device": {
"category": "pc"
},
"os": {
"family": "Windows XP",
"version": "NT 5.1"
}
}Enriched mode
parse_user_agent(
"Opera/9.80 (J2ME/MIDP; Opera Mini/4.3.24214; iPhone; CPU iPhone OS 4_2_1 like Mac OS X; AppleWebKit/24.783; U; en) Presto/2.5.25 Version/10.54",
mode: "enriched"
)
{
"browser": {
"family": "Opera Mini",
"major": "4",
"minor": "3",
"patch": "24214",
"version": "10.54"
},
"device": {
"brand": "Apple",
"category": "smartphone",
"family": "iPhone",
"model": "iPhone"
},
"os": {
"family": "iOS",
"major": "4",
"minor": "2",
"patch": "1",
"patch_minor": null,
"version": "4.2.1"
}
}parse_xml
fallible purevalue as XML.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string representation of the XML document to parse. | yes | |
| trim | boolean | Remove excess whitespace between XML elements. | true | no |
| include_attr | boolean | Include XML tag attributes in the returned object. | true | no |
| attr_prefix | string | String prefix to use for XML tag attribute keys. | @ | no |
| text_key | string | Key name to use for expanded text nodes. | text | no |
| always_use_text_key | boolean | Always return text nodes as {"<text_key>": "value"}. | false | no |
| parse_bool | boolean | Parse “true” and “false” as boolean. | true | no |
| parse_null | boolean | Parse “null” as null. | true | no |
| parse_number | boolean | Parse numbers as integers/floats. | true | no |
Notices
This function has special behavior that you should be aware of.Errors
Theparse_xml function is fallible, which means that
error handling is required for these errors:value is not a valid XML document.Examples
Parse XML
value = s'<book category="CHILDREN"><title lang="en">Harry Potter</title><author>J K. Rowling</author><year>2005</year></book>';
parse_xml!(value, text_key: "value", parse_number: false)
{
"book": {
"@category": "CHILDREN",
"author": "J K. Rowling",
"title": {
"@lang": "en",
"value": "Harry Potter"
},
"year": "2005"
}
}Random functions
random_bool
infallible pureFunction spec
Examples
Random boolean
is_boolean(random_bool())truerandom_bytes
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| length | integer | The number of bytes to generate. Must not be larger than 64k. | yes |
Errors
Therandom_bytes function is fallible, which means that
error handling is required for these errors:length is negative.length is larger than the maximum value (64k).Examples
Generate random base 64 encoded bytes
encode_base64(random_bytes(16))LNu0BBgUbh7XAlXbjSOomQ==Generate 16 random bytes
length(random_bytes(16))16random_float
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| min | float | Minimum value (inclusive). | yes | |
| max | float | Maximum value (exclusive). | yes |
Errors
Therandom_float function is fallible, which means that
error handling is required for these errors:max is not greater than min.Examples
Random float from 0.0 to 10.0, not including 10.0
f = random_float(0.0, 10.0)
f >= 0 && f < 10
truerandom_int
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| min | integer | Minimum value (inclusive). | yes | |
| max | integer | Maximum value (exclusive). | yes |
Errors
Therandom_int function is fallible, which means that
error handling is required for these errors:max is not greater than min.Examples
Random integer from 0 to 10, not including 10
i = random_int(0, 10)
i >= 0 && i < 10
trueuuid_from_friendly_id
fallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | A string that is a Friendly ID | yes |
Errors
Theuuid_from_friendly_id function is fallible, which means that
error handling is required for these errors:value is a string but the text uses characters outside of class [0-9A-Za-z].value is a base62 encoding of an integer, but the integer is greater than or equal to 2^128.Examples
Convert a Friendly ID to a UUID
uuid_from_friendly_id!("3s87yEvnmkiPBMHsj8bwwc")7f41deed-d5e2-8b5e-7a13-ab4ff93cfad2uuid_v4
infallible pureFunction spec
Examples
Create a UUIDv4
uuid_v4()1d262f4f-199b-458d-879f-05fd0a5f0683uuid_v7
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| timestamp | timestamp | The timestamp used to generate the UUIDv7. | `now()` | no |
Examples
Create a UUIDv7 with implicit now()
uuid_v7()0135ddb4-a444-794c-a7a2-088f260104c0Create a UUIDv7 with explicit now()
uuid_v7(now())0135ddb4-a444-794c-a7a2-088f260104c0Create a UUIDv7 with custom timestamp
uuid_v7(t'2020-12-30T22:20:53.824727Z')0176b5bd-5d19-794c-a7a2-088f260104c0String functions
basename
fallible purepath. This is similar to the Unix basename command. If the path ends in a directory separator, the function returns the name of the directory.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The path from which to extract the basename. | yes |
Errors
Thebasename function is fallible, which means that
error handling is required for these errors:value is not a valid string.Examples
Extract basename from file path
basename!("/usr/local/bin/vrl")vrlExtract basename from file path with extension
basename!("/home/user/file.txt")file.txtExtract basename from directory path
basename!("/home/user/")userRoot directory has no basename
basename!("/")camelcase
infallible purevalue string, and turns it into camelCase. Optionally, you can pass in the existing case of the function, or else an attempt is made to determine the case automatically.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to camelCase. | yes | |
| original_case | string | Optional hint on the original case type. Must be one of: kebab-case, camelCase, PascalCase, SCREAMING_SNAKE, snake_case | no |
Examples
camelCase a string without specifying original case
camelcase("input-string")inputStringcamelcase a snake_case string
camelcase("foo_bar_baz", "snake_case")fooBarBazcamelcase specifying the wrong original case (noop)
camelcase("foo_bar_baz", "kebab-case")foo_bar_bazcommunity_id
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| source_ip | string | The source IP address. | yes | |
| destination_ip | string | The destination IP address. | yes | |
| protocol | integer | The protocol number. | yes | |
| source_port | integer | The source port or ICMP type. | no | |
| destination_port | integer | The destination port or ICMP code. | no | |
| seed | integer | The custom seed number. | no |
Examples
Generate Community ID for TCP
community_id!(source_ip: "1.2.3.4", destination_ip: "5.6.7.8", source_port: 1122, destination_port: 3344, protocol: 6)1:wCb3OG7yAFWelaUydu0D+125CLM=Generate Community ID for UDP
community_id!(source_ip: "1.2.3.4", destination_ip: "5.6.7.8", source_port: 1122, destination_port: 3344, protocol: 17)1:0Mu9InQx6z4ZiCZM/7HXi2WMhOg=Generate Community ID for ICMP
community_id!(source_ip: "1.2.3.4", destination_ip: "5.6.7.8", source_port: 8, destination_port: 0, protocol: 1)1:crodRHL2FEsHjbv3UkRrfbs4bZ0=Generate Community ID for RSVP
community_id!(source_ip: "1.2.3.4", destination_ip: "5.6.7.8", protocol: 46)1:ikv3kmf89luf73WPz1jOs49S768=contains
infallible purevalue string contains the specified substring.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The text to search. | yes | |
| substring | string | The substring to search for in value. | yes | |
| case_sensitive | boolean | Whether the match should be case sensitive. | true | no |
Examples
String contains with default parameters (case sensitive)
contains("banana", "AnA")falseString contains (case insensitive)
contains("banana", "AnA", case_sensitive: false)truecontains_all
infallible purevalue string contains all the specified substrings.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The text to search. | yes | |
| substrings | array | An array of substrings to search for in value. | yes | |
| case_sensitive | boolean | Whether the match should be case sensitive. | no |
Examples
String contains all with default parameters (case sensitive)
contains_all("The NEEDLE in the Haystack", ["NEEDLE", "Haystack"])trueString doesn’t contain all with default parameters (case sensitive)
contains_all("The NEEDLE in the Haystack", ["needle", "Haystack"])falseString contains all (case insensitive)
contains_all("The NEEDLE in the HaYsTaCk", ["nEeDlE", "haystack"], case_sensitive: false)truedirname
fallible purepath. This is similar to the Unix dirname command. The directory component is the path with the final component removed.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The path from which to extract the directory name. | yes |
Errors
Thedirname function is fallible, which means that
error handling is required for these errors:value is not a valid string.Examples
Extract dirname from file path
dirname!("/usr/local/bin/vrl")/usr/local/binExtract dirname from file path with extension
dirname!("/home/user/file.txt")/home/userExtract dirname from directory path
dirname!("/home/user/")/homeRoot directory dirname is itself
dirname!("/")/Relative files have current directory as dirname
dirname!("file.txt").downcase
infallible purevalue string, where downcase is defined according to the Unicode Derived Core Property Lowercase.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to lowercase. | yes |
Examples
Downcase a string
downcase("Hello, World!")hello, world!Downcase with number
downcase("FOO 2 BAR")foo 2 barends_with
infallible purevalue string ends with the specified substring.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to search. | yes | |
| substring | string | The substring with which value must end. | yes | |
| case_sensitive | boolean | Whether the match should be case sensitive. | true | no |
Examples
String ends with (case sensitive)
ends_with("The Needle In The Haystack", "The Haystack")trueString ends with (case insensitive)
ends_with("The Needle In The Haystack", "the haystack", case_sensitive: false)trueString ends with (case sensitive failure)
ends_with("foobar", "R")falsefind
infallible purevalue that matches pattern. Returns -1 if not found.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to find the pattern in. | yes | |
| pattern | string regex | The regular expression or string pattern to match against. | yes | |
| from | integer | Offset to start searching. | 0 | no |
Examples
Match text
find("foobar", "bar")3Match text at start
find("foobar", "foo")0Match regex
find("foobar", r'b.r')3No matches
find("foobar", "baz")With an offset
find("foobarfoobarfoo", "bar", 4)9join
infallible purevalue array into a single string, with items optionally separated from one another by a separator.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | array | The array of strings to join together. | yes | |
| separator | string | The string separating each original element when joined. | no |
Examples
Join array (no separator)
join!(["bring", "us", "together"])bringustogetherJoin array (comma separator)
join!(["sources", "transforms", "sinks"], separator: ", ")sources, transforms, sinkskebabcase
infallible purevalue string, and turns it into kebab-case. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to kebab-case. | yes | |
| original_case | string | Optional hint on the original case type. Must be one of: kebab-case, camelCase, PascalCase, SCREAMING_SNAKE, snake_case | no |
Examples
kebab-case a string without specifying original case
kebabcase("InputString")input-stringkebab-case a snake_case string
kebabcase("foo_bar_baz", "snake_case")foo-bar-bazkebab-case specifying the wrong original case (noop)
kebabcase("foo_bar_baz", "PascalCase")foo_bar_bazmatch
infallible purevalue matches the pattern.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The value to match. | yes | |
| pattern | regex | The regular expression pattern to match against. | yes |
Examples
Regex match on a string
match("I'm a little teapot", r'teapot')trueString does not match the regular expression
match("I'm a little teapot", r'.*balloon')falsematch_any
infallible purevalue matches any of the given patterns. All patterns are checked in a single pass over the target string, giving this function a potential performance advantage over the multiple calls in the match function.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The value to match. | yes | |
| patterns | array | The array of regular expression patterns to match against. | yes |
Examples
Regex match on a string
match_any("I'm a little teapot", [r'frying pan', r'teapot'])trueNo match
match_any("My name is John Doe", patterns: [r'\d+', r'Jane'])falseparse_float
fallible purevalue representing a floating point number in base 10 to a float.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to parse. | yes |
Errors
Theparse_float function is fallible, which means that
error handling is required for these errors:value is not a string.Examples
Parse negative integer
parse_float!("-42")-42Parse float
parse_float!("42.38")42.38Scientific notation
parse_float!("2.5e3")2500pascalcase
infallible purevalue string, and turns it into PascalCase. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to PascalCase. | yes | |
| original_case | string | Optional hint on the original case type. Must be one of: kebab-case, camelCase, PascalCase, SCREAMING_SNAKE, snake_case | no |
Examples
PascalCase a string without specifying original case
pascalcase("input-string")InputStringPascalCase a snake_case string
pascalcase("foo_bar_baz", "snake_case")FooBarBazPascalCase specifying the wrong original case (only capitalizes)
pascalcase("foo_bar_baz", "kebab-case")Foo_bar_bazredact
infallible pureRedact sensitive data in value such as:
- US social security card numbers
- Other forms of personally identifiable information with custom patterns
This can help achieve compliance by ensuring sensitive data does not leave your network.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string object array | The value to redact sensitive data from. The function’s behavior depends on
For arrays and objects, the function recurses into any nested arrays or objects. Any non-string elements are skipped. Redacted text is replaced with | yes | |
| filters | array | List of filters applied to Each filter can be specified in the following ways:
Named filters can be a:
See examples for more details. This parameter must be a static expression so that the argument can be validated at compile-time to avoid runtime errors. You cannot use variables or other dynamic expressions with it. | yes | |
| redactor | string object | Specifies what to replace the redacted strings with. It is given as an object with a “type” key specifying the type of redactor to use and additional keys depending on the type. The following types are supported:
As a convenience you can use a string as a shorthand for common redactor patterns:
This parameter must be a static expression so that the argument can be validated at compile-time to avoid runtime errors. You cannot use variables or other dynamic expressions with it. | no |
Examples
Replace text using a regex
redact("my id is 123456", filters: [r'\d+'])my id is [REDACTED]Replace us social security numbers in any field
redact({ "name": "John Doe", "ssn": "123-12-1234"}, filters: ["us_social_security_number"]){
"name": "John Doe",
"ssn": "[REDACTED]"
}Replace with custom text
redact("my id is 123456", filters: [r'\d+'], redactor: {"type": "text", "replacement": "***"})my id is ***Replace with SHA-2 hash
redact("my id is 123456", filters: [r'\d+'], redactor: "sha2")my id is GEtTedW1p6tC094dDKH+3B8P+xSnZz69AmpjaXRd63I=Replace with SHA-3 hash
redact("my id is 123456", filters: [r'\d+'], redactor: "sha3")my id is ZNCdmTDI7PeeUTFnpYjLdUObdizo+bIupZdl8yqnTKGdLx6X3JIqPUlUWUoFBikX+yTR+OcvLtAqWO11NPlNJw==Replace with SHA-256 hash using hex encoding
redact("my id is 123456", filters: [r'\d+'], redactor: {"type": "sha2", "variant": "SHA-256", "encoding": "base16"})my id is 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92replace
infallible pureReplaces all matching instances of pattern in value.
The pattern argument accepts regular expression capture groups.
Note when using capture groups:
- You will need to escape the
$by using$$to avoid Vector interpreting it as an environment variable when loading configuration - If you want a literal
$in the replacement pattern, you will also need to escape this with$$. When combined with environment variable interpolation in config files this means you will need to use$$$$to have a literal$in the replacement pattern.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The original string. | yes | |
| pattern | string regex | Replace all matches of this pattern. Can be a static string or a regular expression. | yes | |
| with | string | The string that the matches are replaced with. | yes | |
| count | integer | The maximum number of replacements to perform. -1 means replace all matches. | -1 | no |
Examples
Replace literal text
replace("Apples and Bananas", "and", "not")Apples not BananasReplace using regular expression
replace("Apples and Bananas", r'(?i)bananas', "Pineapples")Apples and PineapplesReplace first instance
replace("Bananas and Bananas", "Bananas", "Pineapples", count: 1)Pineapples and BananasReplace with capture groups
# Note that in the context of Vector configuration files, an extra `$` escape character is required
# (i.e. `$$num`) to avoid interpreting `num` as an environment variable.
replace("foo123bar", r'foo(?P<num>\d+)bar', "$num")
123Replace all
replace("foobar", "o", "i")fiibarreplace_with
infallible pureReplaces all matching instances of pattern using a closure.
The pattern argument accepts a regular expression that can use capture groups.
The function uses the function closure syntax to compute the replacement values.
The closure takes a single parameter, which is an array, where the first item is always
present and contains the entire string that matched pattern. The items from index one on
contain the capture groups of the corresponding index. If a capture group is optional, the
value may be null if it didn’t match.
The value returned by the closure must be a string and will replace the section of the input that was matched.
This returns a new string with the replacements, the original string is not mutated.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The original string. | yes | |
| pattern | regex | Replace all matches of this pattern. Must be a regular expression. | yes | |
| count | integer | The maximum number of replacements to perform. -1 means replace all matches. | -1 | no |
Examples
Capitalize words
replace_with("apples and bananas", r'\b(\w)(\w*)') -> |match| {
upcase!(match.captures[0]) + string!(match.captures[1])
}
Apples And BananasReplace with hash
replace_with("email from test@example.com", r'\w+@example.com') -> |match| {
sha2(match.string, variant: "SHA-512/224")
}
email from adf6e1bc4415d24912bd93072ad34ef825a7b6eb3bf53f68def1fc17Replace first instance
replace_with("Apples and Apples", r'(?i)apples|cones', count: 1) -> |match| {
"Pine" + downcase(match.string)
}
Pineapples and ApplesNamed capture group
replace_with("level=error A message", r'level=(?P<level>\w+)') -> |match| {
lvl = upcase!(match.level)
"[{{lvl}}]"
}
[ERROR] A messageReplace with processed capture group
replace_with(s'Got message: {"msg": "b"}', r'message: (\{.*\})') -> |m| {
to_string!(parse_json!(m.captures[0]).msg)
}
Got bReplace with optional capture group
replace_with("bar of chocolate and bar of gold", r'bar( of gold)?') -> |m| {
if m.captures[0] == null { "pile" } else { "money" }
}
pile of chocolate and moneyscreamingsnakecase
infallible purevalue string, and turns it into SCREAMING_SNAKE case. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to SCREAMING_SNAKE case. | yes | |
| original_case | string | Optional hint on the original case type. Must be one of: kebab-case, camelCase, PascalCase, SCREAMING_SNAKE, snake_case | no |
Examples
SCREAMING_SNAKE_CASE a string without specifying original case
screamingsnakecase("input-string")INPUT_STRINGSCREAMING_SNAKE_CASE a snake_case string
screamingsnakecase("foo_bar_baz", "snake_case")FOO_BAR_BAZSCREAMING_SNAKE_CASE specifying the wrong original case (capitalizes but doesn’t include _ properly)
screamingsnakecase("FooBarBaz", "kebab-case")FOOBARBAZshannon_entropy
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The input string. | yes | |
| segmentation | string | Defines how to split the string to calculate entropy, based on occurrences of segments. Byte segmentation is the fastest, but it might give undesired results when handling UTF-8 strings, while grapheme segmentation is the slowest, but most correct in these cases. | byte | no |
Examples
Simple byte segmentation example
floor(shannon_entropy("vector.dev"), precision: 4)2.9219UTF-8 string with bytes segmentation
floor(shannon_entropy("test123%456.فوائد.net."), precision: 4)4.0784UTF-8 string with grapheme segmentation
floor(shannon_entropy("test123%456.فوائد.net.", segmentation: "grapheme"), precision: 4)3.9362UTF-8 emoji (7 Unicode scalar values) with grapheme segmentation
shannon_entropy("👨👩👧👦", segmentation: "grapheme")0sieve
infallible pureKeeps only matches of pattern in value.
This can be used to define patterns that are allowed in the string and remove everything else.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The original string. | yes | |
| permitted_characters | regex | Keep all matches of this pattern. | yes | |
| replace_single | string | The string to use to replace single rejected characters. | no | |
| replace_repeated | string | The string to use to replace multiple sequential instances of rejected characters. | no |
Examples
Keep only lowercase letters
sieve("vector.dev/lowerUPPER", permitted_characters: r'[a-z]')vectordevlowerSieve with regex
sieve("test123%456.فوائد.net.", r'[a-z0-9.]')test123456..net.Custom replacements
sieve("test123%456.فوائد.net.", r'[a-z.0-9]', replace_single: "X", replace_repeated: "<REMOVED>")test123X456.<REMOVED>.net.slice
infallible pureReturns a slice of value between the start and end positions.
If the start and end parameters are negative, they refer to positions counting from the right of the
string or array. If end refers to a position that is greater than the length of the string or array,
a slice up to the end of the string or array is returned.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string array | The string or array to slice. | yes | |
| start | integer | The inclusive start position. A zero-based index that can be negative. | yes | |
| end | integer | The exclusive end position. A zero-based index that can be negative. | String length | no |
Examples
Slice a string (positive index)
slice!("Supercalifragilisticexpialidocious", start: 5, end: 13)califragSlice a string (negative index)
slice!("Supercalifragilisticexpialidocious", start: 5, end: -14)califragilisticString start
slice!("foobar", 3)barArray start
slice!([0, 1, 2], 1)[1,2]snakecase
infallible purevalue string, and turns it into snake_case. Optionally, you can pass in the existing case of the function, or else we will try to figure out the case automatically.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to snake_case. | yes | |
| original_case | string | Optional hint on the original case type. Must be one of: kebab-case, camelCase, PascalCase, SCREAMING_SNAKE, snake_case | no | |
| excluded_boundaries | array | Case boundaries to exclude during conversion. | no |
Examples
snake_case a string
snakecase("input-string")input_stringsnake_case a string with original case
snakecase("input-string", original_case: "kebab-case")input_stringsnake_case with excluded boundaries
snakecase("s3BucketDetails", excluded_boundaries: ["lower_digit"])s3_bucket_detailssplit
infallible purevalue string using pattern.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to split. | yes | |
| pattern | string regex | The string is split whenever this pattern is matched. | yes | |
| limit | integer | The maximum number of substrings to return. | no |
Examples
Split a string (no limit)
split("apples and pears and bananas", " and ")["apples","pears","bananas"]Split a string (with a limit)
split("apples and pears and bananas", " and ", limit: 2)["apples","pears and bananas"]Split string
split("foobar", "b")["foo","ar"]Split regex
split("barbaz", r'ba')["","r","z"]split_path
fallible purepath into its constituent components, returning an array of strings. Each component represents a part of the file system path hierarchy.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The path to split into components. | yes |
Errors
Thesplit_path function is fallible, which means that
error handling is required for these errors:value is not a valid string.Examples
Split path with trailing slash
split_path("/home/user/")["/","home","user"]Split path from file path
split_path("/home/user")["/","home","user"]Split path from root
split_path("/")["/"]Empty path returns empty array
split_path("")[]starts_with
infallible purevalue begins with substring.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to search. | yes | |
| substring | string | The substring that the value must start with. | yes | |
| case_sensitive | boolean | Whether the match should be case sensitive. | true | no |
Examples
String starts with (case sensitive)
starts_with("The Needle In The Haystack", "The Needle")trueString starts with (case insensitive)
starts_with("The Needle In The Haystack", "the needle", case_sensitive: false)trueString starts with (case sensitive failure)
starts_with("foobar", "F")falsestrip_ansi_escape_codes
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to strip. | yes |
strip_whitespace
infallible purevalue, where whitespace is defined by the Unicode White_Space property.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to trim. | yes |
Examples
Strip whitespace
strip_whitespace(" A sentence. ")A sentence.Start whitespace
strip_whitespace(" foobar")foobarEnd whitespace
strip_whitespace("foo bar ")foo barNewlines
strip_whitespace("\n\nfoo bar\n ")foo bartruncate
infallible purevalue string up to the limit number of characters.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to truncate. | yes | |
| limit | integer | The number of characters to truncate the string after. | yes | |
| suffix | string | A custom suffix (...) is appended to truncated strings.
If ellipsis is set to true, this parameter is ignored for backwards compatibility. | no |
Examples
Truncate a string
truncate("A rather long sentence.", limit: 11, suffix: "...")A rather lo...Truncate a string (custom suffix)
truncate("A rather long sentence.", limit: 11, suffix: "[TRUNCATED]")A rather lo[TRUNCATED]Truncate
truncate("foobar", 3)fooupcase
infallible purevalue, where upcase is defined according to the Unicode Derived Core Property Uppercase.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to convert to uppercase. | yes |
Examples
Upcase a string
upcase("Hello, World!")HELLO, WORLD!System functions
dns_lookup
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The domain name to query. | yes | |
| qtype | string | The DNS record type to query (e.g., A, AAAA, MX, TXT). Defaults to A. | A | no |
| class | string | The DNS query class. Defaults to IN (Internet). | IN | no |
| options | object | DNS resolver options. Supported fields: servers (array of nameserver addresses), timeout (seconds), attempts (number of retry attempts), ndots, aa_only, tcp, recurse, rotate. | { } | no |
Notices
This function has special behavior that you should be aware of.Examples
Basic lookup
res = dns_lookup!("dns.google")
# reset non-static ttl so result is static
res.answers = map_values(res.answers) -> |value| {
value.ttl = 600
value
}
# remove extra responses for example
res.answers = filter(res.answers) -> |_, value| {
value.rData == "8.8.8.8"
}
# remove class since this is also dynamic
res.additional = map_values(res.additional) -> |value| {
del(value.class)
value
}
res
{
"additional": [
{
"domainName": "",
"rData": "OPT ...",
"recordType": "OPT",
"recordTypeId": 41,
"ttl": 0
}
],
"answers": [
{
"class": "IN",
"domainName": "dns.google",
"rData": "8.8.8.8",
"recordType": "A",
"recordTypeId": 1,
"ttl": 600
}
],
"authority": [],
"fullRcode": 0,
"header": {
"aa": false,
"ad": false,
"anCount": 2,
"arCount": 1,
"cd": false,
"nsCount": 0,
"opcode": 0,
"qdCount": 1,
"qr": true,
"ra": true,
"rcode": 0,
"rd": true,
"tc": false
},
"question": [
{
"class": "IN",
"domainName": "dns.google",
"questionType": "A",
"questionTypeId": 1
}
],
"rcodeName": "NOERROR"
}Custom class and qtype
res = dns_lookup!("dns.google", class: "IN", qtype: "A")
# reset non-static ttl so result is static
res.answers = map_values(res.answers) -> |value| {
value.ttl = 600
value
}
# remove extra responses for example
res.answers = filter(res.answers) -> |_, value| {
value.rData == "8.8.8.8"
}
# remove class since this is also dynamic
res.additional = map_values(res.additional) -> |value| {
del(value.class)
value
}
res
{
"additional": [
{
"domainName": "",
"rData": "OPT ...",
"recordType": "OPT",
"recordTypeId": 41,
"ttl": 0
}
],
"answers": [
{
"class": "IN",
"domainName": "dns.google",
"rData": "8.8.8.8",
"recordType": "A",
"recordTypeId": 1,
"ttl": 600
}
],
"authority": [],
"fullRcode": 0,
"header": {
"aa": false,
"ad": false,
"anCount": 2,
"arCount": 1,
"cd": false,
"nsCount": 0,
"opcode": 0,
"qdCount": 1,
"qr": true,
"ra": true,
"rcode": 0,
"rd": true,
"tc": false
},
"question": [
{
"class": "IN",
"domainName": "dns.google",
"questionType": "A",
"questionTypeId": 1
}
],
"rcodeName": "NOERROR"
}Custom options
res = dns_lookup!("dns.google", options: {"timeout": 30, "attempts": 5})
res.answers = map_values(res.answers) -> |value| {
value.ttl = 600
value
}
# remove extra responses for example
res.answers = filter(res.answers) -> |_, value| {
value.rData == "8.8.8.8"
}
# remove class since this is also dynamic
res.additional = map_values(res.additional) -> |value| {
del(value.class)
value
}
res
{
"additional": [
{
"domainName": "",
"rData": "OPT ...",
"recordType": "OPT",
"recordTypeId": 41,
"ttl": 0
}
],
"answers": [
{
"class": "IN",
"domainName": "dns.google",
"rData": "8.8.8.8",
"recordType": "A",
"recordTypeId": 1,
"ttl": 600
}
],
"authority": [],
"fullRcode": 0,
"header": {
"aa": false,
"ad": false,
"anCount": 2,
"arCount": 1,
"cd": false,
"nsCount": 0,
"opcode": 0,
"qdCount": 1,
"qr": true,
"ra": true,
"rcode": 0,
"rd": true,
"tc": false
},
"question": [
{
"class": "IN",
"domainName": "dns.google",
"questionType": "A",
"questionTypeId": 1
}
],
"rcodeName": "NOERROR"
}Custom server
res = dns_lookup!("dns.google", options: {"servers": ["dns.quad9.net"]})
res.answers = map_values(res.answers) -> |value| {
value.ttl = 600
value
}
# remove extra responses for example
res.answers = filter(res.answers) -> |_, value| {
value.rData == "8.8.8.8"
}
# remove class since this is also dynamic
res.additional = map_values(res.additional) -> |value| {
del(value.class)
value
}
res
{
"additional": [
{
"domainName": "",
"rData": "OPT ...",
"recordType": "OPT",
"recordTypeId": 41,
"ttl": 0
}
],
"answers": [
{
"class": "IN",
"domainName": "dns.google",
"rData": "8.8.8.8",
"recordType": "A",
"recordTypeId": 1,
"ttl": 600
}
],
"authority": [],
"fullRcode": 0,
"header": {
"aa": false,
"ad": false,
"anCount": 2,
"arCount": 1,
"cd": false,
"nsCount": 0,
"opcode": 0,
"qdCount": 1,
"qr": true,
"ra": true,
"rcode": 0,
"rd": true,
"tc": false
},
"question": [
{
"class": "IN",
"domainName": "dns.google",
"questionType": "A",
"questionTypeId": 1
}
],
"rcodeName": "NOERROR"
}get_env_var
fallible purename.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| name | string | The name of the environment variable. | yes |
Errors
Theget_env_var function is fallible, which means that
error handling is required for these errors:name does not exist.name is not valid UnicodeExamples
Get an environment variable
get_env_var!("HOME")/rootget_hostname
fallible pureFunction spec
Errors
Theget_hostname function is fallible, which means that
error handling is required for these errors:Examples
Get hostname
get_hostname!()my-hostnameget_timezone_name
fallible purelocal, then it attempts to
determine the name of the timezone from the host OS. If this
is not possible, then it returns the fixed offset of the
local timezone for the current time in the format "[+-]HH:MM",
for example, "+02:00".Function spec
Errors
Theget_timezone_name function is fallible, which means that
error handling is required for these errors:Examples
Get the IANA name of Vector’s timezone
get_timezone_name!()UTChttp_request
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| url | string | The URL to make the HTTP request to. | yes | |
| method | string | The HTTP method to use (e.g., GET, POST, PUT, DELETE). Defaults to GET. | get | no |
| headers | object | An object containing HTTP headers to send with the request. | { } | no |
| body | string | The request body content to send. | no | |
| http_proxy | string | HTTP proxy URL to use for the request. | no | |
| https_proxy | string | HTTPS proxy URL to use for the request. | no |
Notices
This function has special behavior that you should be aware of.Examples
Basic HTTP request
http_request("https://httpbin.org/get"){
"args": {},
"headers": {
"Accept": "*/*",
"Host": "httpbin.org"
},
"url": "https://httpbin.org/get"
}HTTP request with bearer token
http_request("https://httpbin.org/bearer", headers: {"Authorization": "Bearer my_token"}){
"authenticated": true,
"token": "my_token"
}HTTP PUT request
http_request("https://httpbin.org/put", method: "put"){
"args": {},
"data": "",
"url": "https://httpbin.org/put"
}HTTP POST request with body
http_request("https://httpbin.org/post", method: "post", body: "{\"data\":{\"hello\":\"world\"}}"){
"data": "{\"data\":{\"hello\":\"world\"}}"
}reverse_dns
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The IP address (IPv4 or IPv6) to perform the reverse DNS lookup on. | yes |
Examples
Example
reverse_dns!("127.0.0.1")localhostTimestamp functions
format_timestamp
infallible purevalue into a string representation of the timestamp.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | timestamp | The timestamp to format as text. | yes | |
| format | string | The format string as described by the Chrono library. | yes | |
| timezone | string | The timezone to use when formatting the timestamp. The parameter uses the TZ identifier or local. | no |
Examples
Format a timestamp (ISO8601/RFC 3339)
format_timestamp!(t'2020-10-21T16:00:00Z', format: "%+")2020-10-21T16:00:00+00:00Format a timestamp (custom)
format_timestamp!(t'2020-10-21T16:00:00Z', format: "%v %R")21-Oct-2020 16:00Format a timestamp with custom format string
format_timestamp!(t'2021-02-10T23:32:00+00:00', format: "%d %B %Y %H:%M")10 February 2021 23:32Format a timestamp with timezone conversion
format_timestamp!(t'2021-02-10T23:32:00+00:00', format: "%d %B %Y %H:%M", timezone: "Europe/Berlin")11 February 2021 00:32now
infallible pureFunction spec
Examples
Generate a current timestamp
now()2012-03-04T12:34:56.789012345ZType functions
array
fallible purevalue if it is an array, otherwise returns an error. This enables the type checker to guarantee that the returned value is an array and can be used in any function that expects an array.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is an array. | yes |
Errors
Thearray function is fallible, which means that
error handling is required for these errors:value is not an array.Examples
Declare an array type
{"value": [1, 2, 3]}array!(.value)[1,2,3]Valid array literal
array([1,2,3])[1,2,3]Invalid type
array!(true)function call error for "array" at (0:12): expected array, got booleanbool
fallible purevalue if it is a Boolean, otherwise returns an error. This enables the type
checker to guarantee that the returned value is a Boolean and can be used in any
function that expects a Boolean.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a Boolean. | yes |
Errors
Thebool function is fallible, which means that
error handling is required for these errors:value is not a Boolean.Examples
Valid Boolean
bool(false)falseInvalid Boolean
bool!(42)function call error for "bool" at (0:9): expected boolean, got integerValid Boolean from path
{ "value": true }bool!(.value)truefloat
fallible purevalue if it is a float, otherwise returns an error. This enables the type checker to guarantee that the returned value is a float and can be used in any function that expects a float.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a float. | yes |
Errors
Thefloat function is fallible, which means that
error handling is required for these errors:value is not a float.Examples
Declare a float type
. = { "value": 42.0 }
float(.value)
42Declare a float type (literal)
float(3.1415)3.1415Invalid float type
float!(true)function call error for "float" at (0:12): expected float, got booleanint
fallible purevalue if it is an integer, otherwise returns an error. This enables the type checker to guarantee that the returned value is an integer and can be used in any function that expects an integer.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is an integer. | yes |
Errors
Theint function is fallible, which means that
error handling is required for these errors:value is not an integer.Examples
Declare an integer type
. = { "value": 42 }
int(.value)
42Declare an integer type (literal)
int(42)42Invalid integer type
int!(true)function call error for "int" at (0:10): expected integer, got booleanis_array
infallible purevalue’s type is an array.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is an array. | yes |
Examples
Valid array
is_array([1, 2, 3])trueNon-matching type
is_array("a string")falseBoolean
is_array(true)falseNull
is_array(null)falseis_boolean
infallible purevalue’s type is a boolean.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a Boolean. | yes |
Examples
Valid boolean
is_boolean(false)trueNon-matching type
is_boolean("a string")falseNull
is_boolean(null)falseis_empty
infallible pure0.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string object array | The value to check. | yes |
Examples
Empty array
is_empty([])trueNon-empty string
is_empty("a string")falseNon-empty object
is_empty({"foo": "bar"})falseEmpty string
is_empty("")trueEmpty object
is_empty({})trueNon-empty array
is_empty([1,2,3])falseis_float
infallible purevalue’s type is a float.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a float. | yes |
Examples
Valid float
is_float(0.577)trueNon-matching type
is_float("a string")falseBoolean
is_float(true)falseNull
is_float(null)falseis_integer
infallible purevalue’s type is an integer.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is an integer. | yes |
Examples
Valid integer
is_integer(1)trueNon-matching type
is_integer("a string")falseNull
is_integer(null)falseis_json
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The value to check if it is a valid JSON document. | yes | |
| variant | string | The variant of the JSON type to explicitly check for. | no |
Examples
Valid JSON object
is_json("{}")trueNon-valid value
is_json("{")falseExact variant
is_json("{}", variant: "object")trueNon-valid exact variant
is_json("{}", variant: "array")falseValid JSON string
is_json(s'"test"')trueis_null
infallible pureFunction spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is null. | yes |
Examples
Null value
is_null(null)trueNon-matching type
is_null("a string")falseArray
is_null([1, 2, 3])falseis_nullish
infallible purevalue is nullish. Returns true if the specified value is null, an empty string, a string containing only whitespace, or the string "-". Returns false otherwise.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check for nullishness, for example, a useless value. | yes |
Notices
This function has special behavior that you should be aware of.false for empty arrays ([]) and
objects ({}), but true for empty strings ("") and null.Examples
Null detection (blank string)
is_nullish("")trueNull detection (dash string)
is_nullish("-")trueNull detection (whitespace)
is_nullish("
")trueNull
is_nullish(null)trueis_object
infallible purevalue’s type is an object.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is an object. | yes |
Examples
Valid object
is_object({"foo": "bar"})trueNon-matching type
is_object("a string")falseBoolean
is_object(true)falseis_regex
infallible purevalue’s type is a regex.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a regex. | yes |
Examples
Valid regex
is_regex(r'pattern')trueNon-matching type
is_regex("a string")falseNull value
is_regex(null)falseis_string
infallible purevalue’s type is a string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a string. | yes |
Examples
Valid string
is_string("a string")trueNon-matching type
is_string([1, 2, 3])falseBoolean
is_string(true)falseNull
is_string(null)falseis_timestamp
infallible purevalue’s type is a timestamp.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a timestamp. | yes |
Examples
Valid timestamp
is_timestamp(t'2021-03-26T16:00:00Z')trueNon-matching type
is_timestamp("a string")falseBoolean value
is_timestamp(true)falseobject
fallible purevalue if it is an object, otherwise returns an error. This enables the type checker to guarantee that the returned value is an object and can be used in any function that expects an object.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is an object. | yes |
Errors
Theobject function is fallible, which means that
error handling is required for these errors:value is not an object.Examples
Declare an object type
. = { "value": { "field1": "value1", "field2": "value2" } }
object(.value)
{
"field1": "value1",
"field2": "value2"
}Invalid type
object!(true)function call error for "object" at (0:13): expected object, got booleanstring
fallible purevalue if it is a string, otherwise returns an error. This enables the type checker to guarantee that the returned value is a string and can be used in any function that expects a string.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a string. | yes |
Errors
Thestring function is fallible, which means that
error handling is required for these errors:value is not a string.Examples
Declare a string type
. = { "message": "{\"field\": \"value\"}" }
string(.message)
{"field": "value"}Invalid type
string!(true)function call error for "string" at (0:13): expected string, got booleantag_types_externally
infallible pureAdds type information to all (nested) scalar values in the provided value.
The type information is added externally, meaning that value has the form of "type": value after this
transformation.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to tag with types. | yes |
Examples
Tag types externally (scalar)
tag_types_externally(123){
"integer": 123
}Tag types externally (object)
tag_types_externally({
"message": "Hello world",
"request": {
"duration_ms": 67.9
}
})
{
"message": {
"string": "Hello world"
},
"request": {
"duration_ms": {
"float": 67.9
}
}
}Tag types externally (array)
tag_types_externally(["foo", "bar"])[{"string":"foo"},{"string":"bar"}]Tag types externally (null)
tag_types_externally(null)timestamp
fallible purevalue if it is a timestamp, otherwise returns an error. This enables the type checker to guarantee that the returned value is a timestamp and can be used in any function that expects a timestamp.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The value to check if it is a timestamp. | yes |
Errors
Thetimestamp function is fallible, which means that
error handling is required for these errors:value is not a timestamp.Examples
Declare a timestamp type
timestamp(t'2020-10-10T16:00:00Z')t'2020-10-10T16:00:00Z'Invalid type
timestamp!(true)function call error for "timestamp" at (0:16): expected timestamp, got booleantype_def
infallible pureReturns the type definition of an expression at runtime.
This is a debug function that is UNSTABLE. Behavior is NOT guaranteed even though it is technically usable.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | any | The expression to get the type definition for. | yes |
Examples
return type definition
type_def(42){
"integer": true
}validate_json_schema
fallible purevalue conforms to a JSON Schema definition. This function validates a JSON payload against a JSON Schema definition. It can be used to ensure that the data structure and types in value match the expectations defined in schema_definition.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The value to check if it conforms to the JSON schema definition. | yes | |
| schema_definition | string | The location (path) of the JSON Schema definition. | yes | |
| ignore_unknown_formats | boolean | Unknown formats can be silently ignored by setting this to true and validation continues without failing due to those fields. | no |
Notices
This function has special behavior that you should be aware of.schema_definition, it will compile the schema and cache it for subsequent calls. This
improves performance when validating multiple values against the same schema. The cache
implementation is fairly naive and does not support refreshing the schema if it changes.
If you update the schema definition file, you must restart Vector to clear the cache.Errors
Thevalidate_json_schema function is fallible, which means that
error handling is required for these errors:value is not a valid JSON Schema payload.value contains custom format declarations and ignore_unknown_formats has not been set to true.schema_definition is not a valid JSON Schema definition.schema_definition file does not exist.Examples
Payload contains a valid email
validate_json_schema!(s'{ "productUser": "valid@email.com" }', "schema_with_email_format.json", false)truePayload contains an invalid email
validate_json_schema!(s'{ "productUser": "invalidEmail" }', "schema_with_email_format.json", false)function call error for "validate_json_schema" at (0:99): JSON schema validation failed: "invalidEmail" is not a "email" at /productUserPayload contains a custom format declaration
validate_json_schema!(s'{ "productUser": "a-custom-formatted-string" }', "schema_with_custom_format.json", false)function call error for "validate_json_schema" at (0:113): Failed to compile schema: Unknown format: 'my-custom-format'. Adjust configuration to ignore unrecognized formatsPayload contains a custom format declaration, with ignore_unknown_formats set to true
validate_json_schema!(s'{ "productUser": "a-custom-formatted-string" }', "schema_with_custom_format.json", true)trueChecksum functions
crc
fallible pureCalculates a CRC of the value.The CRC algorithm used can be optionally specified.
This function is infallible if either the default algorithm value or a recognized-valid compile-time algorithm string literal is used. Otherwise, it is fallible.
Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the checksum for. | yes | |
| algorithm | string | The CRC algorithm to use. | CRC_32_ISO_HDLC | no |
Errors
Thecrc function is fallible, which means that
error handling is required for these errors:value is not a string.algorithm is not a supported algorithm.Examples
Create CRC checksum using the default algorithm
crc("foo")2356372769Create CRC checksum using the CRC_32_CKSUM algorithm
crc("foo", algorithm: "CRC_32_CKSUM")4271552933xxhash
infallible purevalue.Function spec
| Argument | Type | Description | Default | Required? |
|---|---|---|---|---|
| value | string | The string to calculate the hash for. | yes | |
| variant | string | The xxHash hashing algorithm to use. | XXH32 | no |
Notices
This function has special behavior that you should be aware of.Examples
Calculate a hash using the default (XXH32) algorithm
xxhash("foo")3792637401Calculate a hash using the XXH32 algorithm
xxhash("foo", "XXH32")3792637401Calculate a hash using the XXH64 algorithm
xxhash("foo", "XXH64")3728699739546630700Calculate a hash using the XXH3-64 algorithm
xxhash("foo", "XXH3-64")-6093828362558604000Calculate a hash using the XXH3-128 algorithm
xxhash("foo", "XXH3-128")161745101148472925293886522910304009610