Arbiter Built-in Functions¶
append
¶
Function prototype: fn append(li: list, v: ...bool|int|float|str|list|map) -> list
Function description: Appends a value to a list.
Function parameters:
li
: The list to append to.v
: The value to append.
Function return value:
list
: The list with the appended value.
Function examples:
-
Example 0:
Script content:
Standard output:
-
Example 1:
Script content:
Standard output:
b64dec
¶
Function prototype: fn b64dec(data: str) -> (str, bool)
Function description: Base64 decoding.
Function parameters:
data
: Data that needs to be base64 decoded.
Function return value:
str
: The decoded string.bool
: Whether decoding is successful.
Function examples:
-
Example 0:
Script content:
Standard output:
b64enc
¶
Function prototype: fn b64enc(data: str) -> (str, bool)
Function description: Base64 encoding.
Function parameters:
data
: Data that needs to be base64 encoded.
Function return value:
str
: The encoded string.bool
: Whether encoding is successful.
Function examples:
-
Example 0:
Script content:
Standard output:
call_func
¶
Function prototype: fn call_func(name: str, kwargs: map = {}) -> map
Function description: Calling remote functions on the Function platform
Function parameters:
name
: Remote function name.kwargs
: Parameter map, corresponding to **kwargs in Python.
Function return value:
map
:
Function examples:
-
Example 0:
Script content:
Standard output:
-
Example 1:
Script content:
Standard output:
cast
¶
Function prototype: fn cast(val: bool|int|float|str, typ: str) -> bool|int|float|str
Function description: Convert the value to the target type.
Function parameters:
val
: The value of the type to be converted.typ
: Target type. One of (bool
,int
,float
,str
).
Function return value:
bool|int|float|str
: The value after the conversion.
Function examples:
-
Example 0:
Script content:
v1 = "1.1" v2 = "1" v2_1 = "-1" v3 = "true" printf("%v; %v; %v; %v; %v; %v; %v; %v\n", cast(v1, "float") + 1, cast(v2, "int") + 1, cast(v2_1, "int"), cast(v3, "bool") + 1, cast(cast(v3, "bool") - 1, "bool"), cast(1.1, "str"), cast(1.1, "int"), cast(1.1, "bool") )
Standard output:
cidr
¶
Function prototype: fn cidr(ip: str, mask: str) -> bool
Function description: Check the IP whether in CIDR block
Function parameters:
ip
: The ip addressmask
: The CIDR mask
Function return value:
bool
: Whether the IP is in CIDR block
Function examples:
-
Example 0:
Script content:
Standard output:
-
Example 1:
Script content:
Standard output:
delete
¶
Function prototype: fn delete(m: map, key: str)
Function description: Delete key from the map.
Function parameters:
m
: The map for deleting keykey
: Key need delete from map.
Function examples:
-
Example 0:
Script content:
v = { "k1": 123, "k2": { "a": 1, "b": 2, }, "k3": [{ "c": 1.1, "d":"2.1", }] } delete(v["k2"], "a") delete(v["k3"][0], "d") printf("result group 1: %v; %v\n", v["k2"], v["k3"]) v1 = {"a":1} v2 = {"b":1} delete(key="a", m=v1) delete(m=v2, key="b") printf("result group 2: %v; %v\n", v1, v2)
Standard output:
dql
¶
Function prototype: fn dql(query: str, qtype: str = "dql", limit: int = 10000, offset: int = 0, slimit: int = 0, time_range: list = []) -> map
Function description: Query data using dql or promql.
Function parameters:
query
: DQL or PromQL query statements.qtype
: Query language, One ofdql
orpromql
, default isdql
.limit
: Query limit.offset
: Query offset.slimit
: Query slimit.time_range
: Query timestamp range, the default value can be modified externally by the script caller.
Function return value:
map
: Query response.
Function examples:
-
Example 0:
Script content:
Standard output:
{ "series": [ [ { "columns": { "time": 1744866108991, "total": 7.18078381, "user": 4.77876106 }, "tags": { "cpu": "cpu-total", "test_site": "testing", "host": "172.16.241.111", "host_ip": "172.16.241.111", "name": "cpu", "project": "demo-testing" } }, { "columns": { "time": 1744866103991, "total": 10.37376049, "user": 7.17009916 }, "tags": { "cpu": "cpu-total", "test_site": "testing", "host": "172.16.241.111", "host_ip": "172.16.241.111", "name": "cpu", "project": "demo-testing" } } ], [ { "columns": { "time": 1744866107975, "total": 21.75562864, "user": 5.69187959 }, "tags": { "cpu": "cpu-total", "test_site": "testing", "host": "172.16.242.112", "host_ip": "172.16.242.112", "name": "cpu", "project": "demo-testing" } }, { "columns": { "time": 1744866102975, "total": 16.59466328, "user": 5.28589581 }, "tags": { "cpu": "cpu-total", "test_site": "testing", "host": "172.16.242.112", "host_ip": "172.16.242.112", "name": "cpu", "project": "demo-testing" } } ] ], "status_code": 200 }
dql_series_get
¶
Function prototype: fn dql_series_get(series: map, name: str) -> list
Function description: get series data
Function parameters:
series
: dql query resultname
: column or tag name
Function return value:
list
: specified column or tag value for the series
Function examples:
-
Example 0:
Script content:
v = dql("M::cpu limit 2 slimit 2") hostLi = dql_series_get(v, "host") time_li = dql_series_get(v, "time") printf("%v", {"host": hostLi, "time": time_li})
Standard output:
dql_timerange_get
¶
Function prototype: fn dql_timerange_get() -> list
Function description: Get the time range of the DQL query, which is passed in by the script caller or defaults to the last 15 minutes.
Function return value:
list
: The time range. For example,[1744214400000, 1744218000000]
, the timestamp precision is milliseconds
Function examples:
-
Example 0:
Script content:
Standard output:
-
Example 1:
Script content:
Standard output:
dump_json
¶
Function prototype: fn dump_json(v: str, indent: str = "") -> (str, bool)
Function description: Returns the JSON encoding of v.
Function parameters:
v
: Object to encode.indent
: Indentation prefix.
Function return value:
str
: JSON encoding of v.bool
: Whether decoding is successful.
Function examples:
-
Example 0:
Script content:
Standard output:
-
Example 1:
Script content:
Standard output:
exit
¶
Function prototype: fn exit()
Function description: Exit the program
Function examples:
-
Example 0:
Script content:
Standard output:
format_int
¶
Function prototype: fn format_int(val: int, base: int) -> str
Function description: Formats an integer into a string.
Function parameters:
val
: The integer to format.base
: The base to use for formatting. Must be between 2 and 36.
Function return value:
str
: The formatted string.
Function examples:
-
Example 0:
Script content:
Standard output:
geoip
¶
Function prototype: fn geoip(ip: str) -> map
Function description: GeoIP
Function parameters:
ip
: IP address.
Function return value:
map
: IP geographical information.
Function examples:
-
Example 0:
Script content:
Standard output:
-
Example 1:
Script content:
Standard output:
gjson
¶
Function prototype: fn gjson(input: str, json_path: str) -> (bool|int|float|str|list|map, bool)
Function description: GJSON provides a fast and easy way to get values from a JSON document.
Function parameters:
input
: JSON format string to parse.json_path
: JSON path.
Function return value:
bool|int|float|str|list|map
: Parsed result.bool
: Parsed status.
Function examples:
-
Example 0:
Script content:
v='''{ "name": {"first": "Tom", "last": "Anderson"}, "age": 37, "children": ["Sara","Alex","Jack"], "fav.movie": "Deer Hunter", "friends": [ {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]}, {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]}, {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]} ] }''' age, ok = gjson(v, "age") if ok { printf("%.0f", age) } else { printf("not found") }
Standard output:
-
Example 1:
Script content:
v='''{ "name": {"first": "Tom", "last": "Anderson"}, "age": 37, "children": ["Sara","Alex","Jack"], "fav.movie": "Deer Hunter", "friends": [ {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]}, {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]}, {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]} ] }''' name, ok = gjson(v, "name") printf("%v", name)
Standard output:
-
Example 2:
Script content:
v='''[ {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]}, {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]}, {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]} ]''' net, ok = gjson(v, "0.nets.2") printf("%v", net)
Standard output:
grok
¶
Function prototype: fn grok(input: str, pattern: str, extra_patterns: map = {}, trim_space: bool = true) -> (map, bool)
Function description: Extracts data from a string using a Grok pattern. Grok is based on regular expression syntax, and using regular (named) capture groups in a pattern is equivalent to using a pattern in a pattern. A valid regular expression is also a valid Grok pattern.
Function parameters:
input
: The input string used to extract data.pattern
: The pattern used to extract data.extra_patterns
: Additional patterns for parsing patterns.trim_space
: Whether to trim leading and trailing spaces from the parsed value.
Function return value:
map
: The parsed result.bool
: Whether the parsing was successful.
Function examples:
-
Example 0:
Script content:
```txt app_log="2021-01-11T17:43:51.887+0800 DEBUG io io/io.go:458 post cost 6.87021ms"
Use built-in patterns, named capture groups, custom patterns, extract fields;¶
convert the type of the extracted field by specifying the type.¶
v, ok = grok( app_log, "%{TIMESTAMP_ISO8601:log_time}\s+(?P
[a-zA-Z]+)\s+%{WORD}\s+%{log_code_pos_pattern:log_code_pos}.*\s%{NUMBER:log_cost:float}ms", { "log_code_pos_pattern": "[a-zA-Z0