Skip to content

Commit

Permalink
Filterx function reference draft, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Fekete authored and Robert Fekete committed Aug 13, 2024
1 parent eb3e562 commit 23e529d
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 11 deletions.
18 changes: 9 additions & 9 deletions content/filterx/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,20 @@ For details, see {{% xref "/filterx/operator-reference.md" %}}.
Filterx has the following built-in functions.

<!-- FIXME definitions/descriptions -->
- "isset"
- "unset"
- "json"
- "json_array"
- "datetime"
- "isodate"
- "string"
- [`datetime`]({{< relref "/filterx/function-reference.md#datetime" >}})
- [`isodate`]({{< relref "/filterx/function-reference.md#isodate" >}})
- [`isset`]({{< relref "/filterx/function-reference.md#isset" >}})
- [`len`]({{< relref "/filterx/function-reference.md#len" >}}): Returns the length of an object.
- [`json, json_object`]({{< relref "/filterx/function-reference.md#json" >}}): Convert a value into a JSON object.
- [`json_array`]({{< relref "/filterx/function-reference.md#json-array" >}}): Convert a value into a JSON array.
- [`string`]({{< relref "/filterx/function-reference.md#string" >}}): Convert a value into a string.
- [`unset`]({{< relref "/filterx/function-reference.md#unset" >}})
- [`vars`]({{< relref "/filterx/function-reference.md#vars" >}}): The variables defined in the filterx block.
- "bytes"
- "protobuf"
- "bool"
- "int"
- "double"
- "len"
- "vars"
- "lower"
- "upper"
- "regexp_search"
Expand Down
106 changes: 104 additions & 2 deletions content/filterx/function-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ weight: 4800
sok egyszeru pelda az adott functionnel, a tmp/axosyslog/tests/light/functional_tests/filterx/test_filterx.py temakorei sok mindent lefednek
-->

## datetime

Cast a value into a datetime variable.

Usage: `datetime(<string or expression to cast as datetime>)`

For example:

```shell
date = datetime("1701350398.123000+01:00")
```
<!-- FIXME syntax for argument, timezone handling, etc. -->

## flatten

Usage: `flatten(dict, separator=".")`
Expand Down Expand Up @@ -41,16 +54,52 @@ value_separator must be a string literal, and a single character
pair_separator must be a string literal
-->

## isodate

<!-- FIXME -->

## isset

Returns true if the argument exists and its value is not empty or null.

Usage: `isset(<name of a variable, macro, or name-value pair>)`

## istype

Usage: `istype(object, type_str)`
<!-- FIXME include list of valid types -->

## json, json_object {#json}

Cast a value into a JSON object.

Usage: `json(<string or expression to cast as json>)`

For example:

```shell
js = json_object({"key": "value"})
```

## json_array {#json-array}

Cast a value into a JSON array.

Usage: `json_array(<string or expression to cast as json array>)`

For example:

```shell
list = json_array(["first_element", "second_element", "third_element"]);
```

## len

Returns the number of items in an object. For example, the length of a string, or the number of elements in a list.

Usage: `len(object)`

<!-- FIXME mire van ertelmezve es mikor mit ad vissza? -->
<!-- FIXME What does it return for different types? -->

## parse_csv

Expand Down Expand Up @@ -97,6 +146,20 @@ value_separator must be a string literal, and a single character
pair_separator must be a string literal
-->

## regexp_search

<!-- $MSG = json();
$MSG.unnamed = regexp_search("foobarbaz", /(foo)(bar)(baz)/);
$MSG.named = regexp_search("foobarbaz", /(?<first>foo)(?<second>bar)(?<third>baz)/);
$MSG.mixed = regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/);
$MSG.force_list = json_array(regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/));
$MSG.force_dict = json(regexp_search("foobarbaz", /(foo)(bar)(baz)/));
$MSG.no_match_unnamed = regexp_search("foobarbaz", /(almafa)/);
if (len($MSG.no_match_unnamed) == 0) {
$MSG.no_match_unnamed_handling = true;
}; -->

## regexp_subst

<!--
Expand All @@ -108,12 +171,51 @@ pair_separator must be a string literal
#define FILTERX_FUNC_REGEXP_SUBST_FLAG_NEWLINE_NAME "newline"
-->

## string

Cast a value into a string.

Usage: `string(<string or expression to cast>)`

For example:

```shell
myvariable = string(${LEVEL_NUM});
```

Sometimes you have to explicitly cast values to strings, for example, when you want to concatenate them into a message using the `+` operator.

## strptime

Usage: `strptime(time_str, format_str_1, ..., format_str_N)`

## unset

Deletes a variable, a name-value pair, or a key in a complex object (like JSON).

<!-- FIXME What happens when trying to unset a hard macro? Error? -->

See also {{% xref "/filterx/_index.md#delete-values" %}}.

## unset_empties

Usage: `unset_empties(object, recursive=true)`

Also unsets inner dicts' and lists' values is recursive is set.
Also unsets inner dicts' and lists' values is recursive is set.

## vars

Returns the variables (including pipeline variables and name-value pairs) defined in the filterx block as a JSON object.

For example:

```shell
filterx {
$logmsg_variable = "foo";
local_variable = "bar";
declare pipeline_level_variable = "baz";
${MESSAGE} = vars();
};
```

The value of `${MESSAGE}` will be: `{"logmsg_variable":"foo","pipeline_level_variable":"baz"}`

0 comments on commit 23e529d

Please sign in to comment.