Arbiter Built-in Functions¶
append¶
Function prototype: fn append(li: list, v: ...bool|int|float|str|list|map) -> list
Description: Appends a value to a list.
Parameters:
li: The list to append to.v: The value to append.
Return value:
list: The list with the appended value.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
b64dec¶
Function prototype: fn b64dec(data: str) -> (str, bool)
Description: Base64 decoding.
Parameters:
data: Data that needs to be base64 decoded.
Return value:
str: The decoded string.bool: Whether decoding is successful.
Examples:
-
Example 0:
Script:
Standard output:
b64enc¶
Function prototype: fn b64enc(data: str) -> (str, bool)
Description: Base64 encoding.
Parameters:
data: Data that needs to be base64 encoded.
Return value:
str: The encoded string.bool: Whether encoding is successful.
Examples:
-
Example 0:
Script:
Standard output:
call_func¶
Function prototype: fn call_func(name: str, kwargs: map = {}) -> map
Description: Calling remote functions on the Function platform.
Parameters:
name: Remote function name.kwargs: Parameter map, corresponding to **kwargs in Python.
Return value:
map:
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
cast¶
Function prototype: fn cast(val: bool|int|float|str, typ: str) -> bool|int|float|str
Description: Convert the value to the target type.
Parameters:
val: The value of the type to be converted.typ: Target type. One of (bool,int,float,str).
Return value:
bool|int|float|str: The value after the conversion.
Examples:
-
Example 0:
Script:
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
Description: Check the IP whether in CIDR block.
Parameters:
ip: The ip address.mask: The CIDR mask.
Return value:
bool: Whether the IP is in CIDR block.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
delete¶
Function prototype: fn delete(m: map, key: str)
Description: Delete key from the map.
Parameters:
m: The map for deleting key.key: Key need delete from map.
Examples:
-
Example 0:
Script:
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 = [], workspace_uuid: str = "") -> map
Description: Query data using dql or promql.
Parameters:
query: DQL or PromQL query statements.qtype: Query language, One ofdqlorpromql, 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.workspace_uuid: Workspace UUID to query data from.
Return value:
map: Query response.
Examples:
-
Example 0:
Script:
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
Description: get series data.
Parameters:
series: dql query result.name: column or tag name.
Return value:
list: specified column or tag value for the series.
Examples:
-
Example 0:
Script:
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
Description: Get the time range of the DQL query, which is passed in by the script caller or defaults to the last 15 minutes.
Return value:
list: The time range. For example,[1744214400000, 1744218000000], the timestamp precision is milliseconds.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
dump_json¶
Function prototype: fn dump_json(v: str, indent: str = "") -> (str, bool)
Description: Returns the JSON encoding of v.
Parameters:
v: Object to encode.indent: Indentation prefix.
Return value:
str: JSON encoding of v.bool: Whether decoding is successful.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
exit¶
Function prototype: fn exit()
Description: Exit the program.
Examples:
-
Example 0:
Script:
Standard output:
format_int¶
Function prototype: fn format_int(val: int, base: int) -> str
Description: Formats an integer into a string.
Parameters:
val: The integer to format.base: The base to use for formatting. Must be between 2 and 36.
Return value:
str: The formatted string.
Examples:
-
Example 0:
Script:
Standard output:
geoip¶
Function prototype: fn geoip(ip: str) -> map
Description: GeoIP.
Parameters:
ip: IP address.
Return value:
map: IP geographical information.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
gjson¶
Function prototype: fn gjson(input: str, json_path: str) -> (bool|int|float|str|list|map, bool)
Description: GJSON provides a fast and easy way to get values from a JSON document.
Parameters:
input: JSON format string to parse.json_path: JSON path.
Return value:
bool|int|float|str|list|map: Parsed result.bool: Parsed status.
Examples:
-
Example 0:
Script:
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:
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:
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)
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.
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.
Return value:
map: The parsed result.bool: Whether the parsing was successful.
Examples:
-
Example 0:
Script:
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<log_level>[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-9/\\.]+:\\d+", } ) if ok { v, ok = dump_json(v, " ") if ok { printf("%v", v) } }Standard output:
hash¶
Function prototype: fn hash(text: str, method: str) -> str
Description:
Parameters:
text: The string used to calculate the hash.method: Hash Algorithms, allowing values includingmd5,sha1,sha256,sha512.
Return value:
str: The hash value.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
-
Example 2:
Script:
Standard output:
-
Example 3:
Script:
Standard output:
-
Example 4:
Script:
Standard output:
http_request¶
Function prototype: fn http_request(method: str, url: str, body: bool|int|float|str|list|map = nil, headers: map = {}) -> map
Description: Used to send http request.
Parameters:
method: HTTP request method.url: HTTP request url.body: HTTP request body.headers: HTTP request headers.
Return value:
map: HTTP response.
Examples:
-
Example 0:
Script:
resp = http_request("GET", "http://test-domain/test") delete(resp["headers"], "Date") resp_str, ok = dump_json(resp, " ") printf("%s", resp_str)Standard output:
-
Example 1:
Script:
resp = http_request("GET", "http://localhost:80/test") # Usually, access to private IPs will be blocked, # you need to contact the administrator. resp_str, ok = dump_json(resp, " ") printf("%s", resp_str)Standard output:
len¶
Function prototype: fn len(val: map|list|str) -> int
Description: Get the length of the value. If the value is a string, returns the length of the string. If the value is a list or map, returns the length of the list or map.
Parameters:
val: The value to get the length of.
Return value:
int: The length of the value.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
-
Example 2:
Script:
Standard output:
load_json¶
Function prototype: fn load_json(val: str) -> (bool|int|float|str|list|map, bool)
Description: Unmarshal json string.
Parameters:
val: JSON string.
Return value:
bool|int|float|str|list|map: Unmarshal result.bool: Unmarshal status.
Examples:
-
Example 0:
Script:
Standard output:
lowercase¶
Function prototype: fn lowercase(val: str) -> str
Description: Converts a string to lowercase.
Parameters:
val: The string to convert.
Return value:
str: Returns the lowercase value.
Examples:
-
Example 0:
Script:
Standard output:
match¶
Function prototype: fn match(val: str, pattern: str, n: int = 1) -> (list, bool)
Description: Regular expression matching.
Parameters:
val: The string to match.pattern: Regular expression pattern.n: The number of matches to return. Defaults to 1, -1 for all matches.
Return value:
list: Returns the matched value.bool: Returns true if the regular expression matches.
Examples:
-
Example 0:
Script:
text="abc def 123 abc def 123" v, ok = match(text, "(abc) (?:def) (?P<named_group>123)") if ok { printf("%v", v) }Standard output:
-
Example 1:
Script:
text="abc def 123 abc def 123" v, ok = match(text, "(abc) (?:def) (?P<named_group>123)", -1) if ok { printf("%v", v) }Standard output:
parse_date¶
Function prototype: fn parse_date(date: str, timezone: str = "") -> (int, bool)
Description: Parses a date string to a nanoseconds timestamp, support multiple date formats. If the date string not include timezone and no timezone is provided, the local timezone is used.
Parameters:
date: The key to use for parsing.timezone: The timezone to use for parsing.
Return value:
int: The parsed timestamp in nanoseconds.bool: Whether the parsing was successful.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
-
Example 2:
Script:
Standard output:
parse_duration¶
Function prototype: fn parse_duration(s: str) -> (int, bool)
Description: Parses a golang duration string into a duration. A duration string is a sequence of possibly signed decimal numbers with optional fraction and unit suffixes for each number, such as 300ms, -1.5h or 2h45m. Valid units are ns, us (or μs), ms, s, m, h.
Parameters:
s: The string to parse.
Return value:
int: The duration in nanoseconds.bool: Whether the duration is valid.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
parse_int¶
Function prototype: fn parse_int(val: str, base: int) -> (int, bool)
Description: Parses a string into an integer.
Parameters:
val: The string to parse.base: The base to use for parsing. Must be between 2 and 36.
Return value:
int: The parsed integer.bool: Whether the parsing was successful.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
printf¶
Function prototype: fn printf(format: str, args: ...str|bool|int|float|list|map)
Description: Output formatted strings to the standard output device.
Parameters:
format: String format.args: Argument list, corresponding to the format specifiers in the format string.
Examples:
-
Example 0:
Script:
Standard output:
replace¶
Function prototype: fn replace(input: str, pattern: str, replacement: str) -> (str, bool)
Description: Replaces text in a string.
Parameters:
input: The string to replace text in.pattern: Regular expression pattern.replacement: Replacement text to use.
Return value:
str: The string with text replaced.bool: True if the pattern was found and replaced, false otherwise.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
setopt¶
Function prototype: fn setopt(trigger_keepalive: int)
Description: Set option.
Parameters:
trigger_keepalive: Set the trigger keepalive time (seconds).
Examples:
-
Example 0:
Script:
Standard output:
sql_cover¶
Function prototype: fn sql_cover(val: str) -> (str, bool)
Description: Obfuscate SQL query string.
Parameters:
val: The sql to obfuscate.
Return value:
str: The obfuscated sql.bool: The obfuscate status.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
v, ok = sql_cover("SELECT $func$INSERT INTO table VALUES ('a', 1, 2)$func$ FROM users") if ok { printf("%s",v) }Standard output:
-
Example 2:
Script:
Standard output:
str_join¶
Function prototype: fn str_join(li: list, sep: str) -> str
Description: String join.
Parameters:
li: List to be joined with separator. The elements type need to be string, if not, they will be ignored.sep: Separator to be used between elements.
Return value:
str: Joined string.
Examples:
-
Example 0:
Script:
Standard output:
str_split¶
Function prototype: fn str_split(text: str, sep: str) -> list
Description: String split.
Parameters:
text: String to be split.sep: Separator to be used for splitting.
Return value:
list: List of strings.
Examples:
-
Example 0:
Script:
Standard output:
strfmt¶
Function prototype: fn strfmt(format: str, args: ...bool|int|float|str|list|map) -> str
Description:
Parameters:
format: String format.args: Parameters to replace placeholders.
Return value:
str: String.
Examples:
-
Example 0:
Script:
Standard output:
time_now¶
Function prototype: fn time_now(precision: str = "ns") -> int
Description: Get current timestamp with the specified precision.
Parameters:
precision: The precision of the timestamp. Supported values:ns,us,ms,s.
Return value:
int: Returns the current timestamp.
Examples:
-
Example 0:
Script:
Standard output:
trigger¶
Function prototype: fn trigger(result: int|float|bool|str, status: str = "", dimension_tags: map = {}, related_data: map = {}, check_workspace_uuid: str = "")
Description: Trigger a security event.
Parameters:
result: Event check result.status: Event status. One of: (critical,high,medium,low,info).dimension_tags: Dimension tags.related_data: Related data.check_workspace_uuid: UUID of the workspace related to the detection result.
Examples:
-
Example 0:
Script:
trigger(1, "critical", {"tag_abc":"1"}, {"a":"1", "a1":2.1}) trigger(result=2, dimension_tags={"a":"1", "b":"2"}, related_data={"b": {}}) trigger(false, related_data={"a":1, "b":2}, status="critical") trigger("hello", dimension_tags={}, related_data={"a":1, "b":[1]}, status="critical")Standard output:
Trigger output:
[ { "result": 1, "status": "critical", "dimension_tags": { "tag_abc": "1" }, "related_data": { "a": "1", "a1": 2.1 }, "check_workspace_uuid": "" }, { "result": 2, "status": "", "dimension_tags": { "a": "1", "b": "2" }, "related_data": { "b": {} }, "check_workspace_uuid": "" }, { "result": false, "status": "critical", "dimension_tags": {}, "related_data": { "a": 1, "b": 2 }, "check_workspace_uuid": "" }, { "result": "hello", "status": "critical", "dimension_tags": {}, "related_data": { "a": 1, "b": [ 1 ] }, "check_workspace_uuid": "" } ]
trim¶
Function prototype: fn trim(val: str, cutset: str = "", side: int = 0) -> str
Description: Removes leading and trailing whitespace from a string.
Parameters:
val: The string to trim.cutset: Characters to remove from the beginning and end of the string. If not specified, whitespace is removed.side: The side to trim from. If value is 0, trim from both sides. If value is 1, trim from the left side. If value is 2, trim from the right side.
Return value:
str: The trimmed string.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
-
Example 2:
Script:
Standard output:
-
Example 3:
Script:
Standard output:
uppercase¶
Function prototype: fn uppercase(val: str) -> str
Description: Converts a string to uppercase.
Parameters:
val: The string to convert.
Return value:
str: Returns the uppercase value.
Examples:
-
Example 0:
Script:
Standard output:
url_decode¶
Function prototype: fn url_decode(val: str) -> (str, bool)
Description: Decodes a URL-encoded string.
Parameters:
val: The URL-encoded string to decode.
Return value:
str: The decoded string.bool: The decoding status.
Examples:
-
Example 0:
Script:
v, ok = url_decode("https:%2F%2Fkubernetes.io%2Fdocs%2Freference%2Faccess-authn-authz%2Fbootstrap-tokens%2F") if ok { printf("%s", v) }Standard output:
url_parse¶
Function prototype: fn url_parse(url: str) -> (map, bool)
Description: Parses a URL and returns it as a map.
Parameters:
url: The URL to parse.
Return value:
map: Returns the parsed URL as a map.bool: Returns true if the URL is valid.
Examples:
-
Example 0:
Script:
v, ok = url_parse("http://www.example.com:8080/path/to/file?query=abc") if ok { v, ok = dump_json(v, " ") if ok { printf("%v", v) } }Standard output:
user_agent¶
Function prototype: fn user_agent(header: str) -> map
Description: Parses a User-Agent header.
Parameters:
header: The User-Agent header to parse.
Return value:
map: Returns the parsed User-Agent header as a map.
Examples:
-
Example 0:
Script:
v = user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36") printf("%s", v)Standard output:
valid_json¶
Function prototype: fn valid_json(val: str) -> bool
Description: Returns true if the value is a valid JSON.
Parameters:
val: The value to check.
Return value:
bool: Returns true if the value is a valid JSON.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
-
Example 2:
Script:
Standard output:
value_type¶
Function prototype: fn value_type(val: str) -> str
Description: Returns the type of the value.
Parameters:
val: The value to get the type of.
Return value:
str: Returns the type of the value. One of (bool,int,float,str,list,map,nil). If the value and the type is nil, returnsnil.
Examples:
-
Example 0:
Script:
Standard output:
-
Example 1:
Script:
Standard output:
-
Example 2:
Script:
Standard output:
xml_query¶
Function prototype: fn xml_query(input: str, xpath: str) -> (str, bool)
Description: Returns the value of an XML field.
Parameters:
input: The XML input to get the value of.xpath: The XPath expression to get the value of.
Return value:
str: Returns the value of the XML field.bool: Returns true if the field exists, false otherwise.
Examples:
-
Example 0:
Script:
xml_data=''' <OrderEvent actionCode = "5"> <OrderNumber>ORD12345</OrderNumber> <VendorNumber>V11111</VendorNumber> </OrderEvent> ''' v, ok = xml_query(xml_data, "/OrderEvent/OrderNumber/text()") if ok { printf("%s", v) }Standard output:
-
Example 1:
Script:
xml_data=''' <OrderEvent actionCode = "5"> <OrderNumber>ORD12345</OrderNumber> <VendorNumber>V11111</VendorNumber> </OrderEvent> ''' v, ok = xml_query(xml_data, "/OrderEvent/@actionCode") if ok { printf("%s", v) }Standard output: