Skip to content

Latest commit

 

History

History
237 lines (168 loc) · 3.08 KB

elastic-agent-functions.asciidoc

File metadata and controls

237 lines (168 loc) · 3.08 KB

Function reference

The condition syntax supports the following functions.

add

add(Number, Number) Number

Usage:

add(1, 2) == 3
add(5, ${foo}) >= 5

arrayContains

arrayContains(Array, String) Boolean

Usage:

arrayContains(${docker.labels}, 'monitor')

concat

concat(String, String) String

Note
Parameters are coerced into strings before the concatenation.

Usage:

concat("foo", "bar") == "foobar"
concat(${var1}, ${var2}) != "foobar"

divide

divide(Number, Number) Number

Usage:

divide(25, 5) > 0
divide(${var1}, ${var2}) > 7

endsWith

endsWith(String, String) Boolean

Usage:

endsWith("hello world", "hello") == true
endsWith(${var1}, "hello") != true

hasKey

hasKey(Dictionary, String) Boolean

Usage:

hasKey(${host}, "platform")

indexOf

indexOf(String, String, Number?) Number

Note
Returns -1 if the string is not found.

Usage:

indexOf("hello", "llo") == 2
indexOf(${var1}, "hello") >= 0

length

length(Array|Dictionary|string)

Usage:

length("foobar") > 2
length(${docker.labels}) > 0
length(${host}) > 2

match

match(String, Regexp) boolean

Note
Regexp supports Go’s regular expression syntax. Conditions that use regular expressions are more expensive to run. If speed is critical, consider using endWiths or startsWith.

Usage:

match("hello world", "^hello") == true
match(${var1}, "world$") == true

modulo

modulo(number, number) Number

Usage:

modulo(25, 5) > 0
modulo(${var1}, ${var2}) == 0

multiply

multiply(Number, Number) Number

Usage:

multiply(5, 5) == 25
multiple(${var1}, ${var2}) > x

number

number(String) Integer

Usage:

number("42") == 42
number(${var1}) == 42

startsWith

startsWith(String, String) Boolean

Usage:

startsWith("hello world", "hello") == true
startsWith(${var1}, "hello") != true

string

string(Number) String

Usage:

string(42) == "42"
string(${var1}) == "42"

stringContains

stringContains(String, String) Boolean

Usage:

stringContains("hello world", "hello") == true
stringContains(${var1}, "hello") != true

subtract

subtract(Number, Number) Number

Usage:

subtract(5, 1) == 4
subtract(${foo}, 2) != 2