Skip to main content
Version: 6.2

Smart Monitor System Painless Script Reference

System Painless scripts process data at the storage level in the peval and search commands. The following sections describe their purpose and provide short SML examples. In the examples, ... represents the preceding part of the query.

abs​

Returns the absolute value of a number. Accepts a single value or a list and converts numeric strings to numbers. Returns null on error.

... | peval result=abs(-12)

The result field contains 12.

and​

Performs logical AND. If one argument is a list, returns true when the condition holds for at least one element. Returns false if there are no matches and null on error.

... | search status="active" AND errors=0

The results contain records where status is active and errors is 0.

case​

Evaluates condition-value pairs in order and returns the value from the first pair whose condition is true. Returns null if no condition is true or an error occurs.

... | peval result=case(errors>0,"Ошибка",true,"Норма")

The result field contains Ошибка if errors > 0; otherwise, Норма.

ceil​

Rounds a number up to the nearest integer. Accepts a single value or a list. Returns null on error.

... | peval result=ceil(2.1)

The result field contains 3.

cidrmatch​

Checks whether an IPv4 address belongs to a subnet in CIDR notation. For a list or set of addresses, one match is sufficient. Without a mask, compares addresses for an exact match; IPv6 is not supported.

... | peval result=cidrmatch("192.168.1.0/24",ip)

The result field contains true if ip belongs to 192.168.1.0/24; otherwise, false.

coalesce​

Returns the first non-null value in argument order. Returns null if there are no such values. The number 0 is a valid value.

... | peval result=coalesce(primary_value,backup_value,0)

The result field contains primary_value if it is not null; otherwise, backup_value, or 0 if both fields are null.

divide​

Divides the first number by the second with a precision of 16 significant digits. Returns an integer result as an integer if it fits in long. Returns null for division by zero or a nonnumeric argument.

... | peval result=divide(10,2)

The result field contains 5.

equal and equalsens​

Compare the string representations of two values. equal is case-insensitive; equalsens is case-sensitive. If one argument is a list, one matching element is sufficient. On error, equal returns null.

... | search status="active"
... | search sens status="ACTIVE"

The first query retains records with active in any case. The second retains only records with ACTIVE in the specified case.

exp​

Calculates e raised to the power of the supplied number. Accepts a single value or a list. Returns null on error.

... | peval result=exp(1)

The result field contains approximately 2.71828.

false​

Returns the Boolean value false. Takes no arguments.

... | peval result=false

The result field contains false.

floor​

Rounds a number down to the nearest integer and returns a floating-point number. Accepts a single value or a list; returns null on error.

... | peval result=floor(2.9)

The result field contains 2.0.

gt and gte​

Compare numbers: gt checks for greater than (>), and gte for greater than or equal to (>=). If one argument is a list, the condition needs to hold for only one element. Return null on error.

... | search errors > 5
... | search errors >= 5

The first query retains records where errors > 5; the second, where errors >= 5.

if​

Evaluates a Boolean condition. If it is true, returns the value for true; otherwise, the value for false.

... | peval result=if(temperature>80,"Перегрев","Норма")

The result field contains Перегрев if temperature > 80; otherwise, Норма.

in​

Checks whether the first value matches any subsequent value or any element of the supplied lists. If the first argument is a list, one matching element is sufficient. Returns false on error.

... | peval result=in(status,"error","warning")

The result field contains true if status is error or warning; otherwise, false.

isbool​

Checks whether a value has the Boolean type. For a list, returns true if at least one element has this type. The strings "true" and "false" are not Boolean values.

... | peval result=isbool(enabled)

The result field contains true if enabled has the Boolean type; otherwise, false.

isint​

Checks whether a value has the Integer type. For a list, one element of this type is sufficient. Fractional numbers and numeric strings are not considered Integer values.

... | peval result=isint(count)

The result field contains true if count has the Integer type; otherwise, false.

isnotnull​

For a single value, returns true if it is not null. For a list, the current implementation returns true if the list is not empty, even if all its elements are null.

... | peval result=isnotnull(value)

The result field contains true if the single value value is not null; for a list, the result depends on whether the list is empty.

isnull​

For a single value, returns true if it is null. For a list, the current implementation always returns false, even if the list contains null.

... | peval result=isnull(value)

The result field contains true if the single value value is null; for a list, false.

isnum​

Checks whether a value is a number. For a list, returns true if at least one element is a number. Numeric strings are not considered numbers.

... | peval result=isnum(value)

The result field contains true if value is a number; for a list, one numeric element is sufficient.

isstr​

Checks whether a value is a string. For a list, returns true if at least one element is a string.

... | peval result=isstr(value)

The result field contains true if value is a string; for a list, one string element is sufficient.

len​

Returns the length of a value's string representation. Returns null for null, a list, or a set.

... | peval result=len(hostname)

The result field contains the number of characters in the string representation of hostname, for example, 4 for node.

like​

Compares a string with a pattern without considering case. Without %, compares entire strings; with %, checks the beginning against the part before the first % and checks whether the part after it occurs in the string. For a list, one match is sufficient. The part after % need not occur at the end of the string.

... | peval result=like(message,"error%")

The result field contains true if message matches error% without considering case; otherwise, false.

ln​

Calculates the natural logarithm of a number. Accepts a single value or a list. Returns null on conversion error; for zero, the result is -Infinity, and for a negative number, NaN.

... | peval result=ln(value)

The result field contains the natural logarithm of value, for example, 0.0 when value = 1.

log​

Calculates the logarithm of the first number to the base specified by the second. Returns null on conversion error; mathematically invalid values may produce NaN or Infinity.

... | peval result=log(8,2)

The result field contains approximately 3.

lower​

Converts a value to a lowercase string. For a list, converts each element; for a single null, returns null.

... | peval result=lower(hostname)

The result field contains hostname in lowercase, for example, server for SERVER.

lt and lte​

Compare numbers: lt checks for less than (<), and lte for less than or equal to (<=). If one argument is a list, the condition needs to hold for only one element. Return null on error.

... | search errors < 5
... | search errors <= 5

The first query retains records where errors < 5; the second, where errors <= 5.

ltrim​

Removes characters from the beginning of a string. An empty second argument or null means that leading whitespace is removed. Otherwise, the second argument specifies the set of characters to remove. For a list, processes each element.

... | peval result=ltrim("__Ошибка","_")

The result field contains Ошибка.

match​

Checks whether the entire string matches a Java regular expression. For a list, one matching element is sufficient. Returns false if there are no matches and null on error.

... | peval result=match(code,/\d{3}/)

The result field contains true if code consists of exactly three digits; otherwise, false.

max​

Returns the largest value. Lists are expanded, and null is skipped. If nonnumeric values are present, compares only those values as text; otherwise, compares numbers. Returns null if there are no values.

... | peval result=max(current,previous)

The result field contains the larger of current and previous, according to the comparison rules for numbers and text.

min​

Returns the smallest value. Lists are expanded, and null is skipped. If numbers are present, selects the minimum among them; otherwise, compares values as text. Returns null if there are no values.

... | peval result=min(current,previous)

The result field contains the smaller of current and previous, according to the comparison rules for numbers and text.

minus​

Subtracts the second number from the first. Returns null if either argument is nonnumeric or null.

... | peval result=10-3

The result field contains 7.

mod​

Returns the remainder of dividing the first number by the second. Returns null for a nonnumeric argument, null, or division by zero.

... | peval result=10%3

The result field contains 1.

multiply​

Multiplies two numbers. Returns null if either argument is nonnumeric or null.

... | peval result=10*5

The result field contains 50.

mvappend​

Collects the supplied arguments into a multivalue value. Preserves their order, including null and nested lists.

... | peval result=mvappend(primary_host,backup_host)

The result field contains two values: primary_host followed by backup_host.

mvcount​

Returns the number of elements in a list or set. Returns 1 for a single value and 0 for null.

... | peval result=mvcount(hosts)

The result field contains the number of elements in hosts, for example, 2 for a list of two addresses.

mvdedup​

Removes duplicate list elements, preserving the order of first occurrence, and returns a set (Set). Returns values of other types unchanged.

... | peval result=mvdedup(hosts)

The result field contains the unique values from hosts in the order of first occurrence.

mvindex​

Returns a list element by its zero-based index; a negative index counts from the end. If an end index is specified, returns a list slice including that index. For a single value, only index 0 is available. For an invalid index, the current implementation returns an error object rather than null.

... | peval result=mvindex(hosts,0)

The result field contains the first element of hosts, because index 0 denotes the beginning of the list.

mvjoin​

Joins elements of a list or set into a string using the specified separator. Returns an empty string for an empty list and null on error.

... | peval result=mvjoin(hosts,",")

The result field contains the elements of hosts separated by commas, for example, host1,host2.

mvrange​

Creates a list from the start to the end value, including the end if reached with the specified step. The default step is 1. For an ascending range, the step must be positive; a zero or negative step may cause an infinite loop.

... | peval result=mvrange(1,5,2)

The result field contains [1, 3, 5].

mvsort​

Sorts a list or set in ascending order and returns a list. Returns values of other types unchanged and null on comparison error.

... | peval result=mvsort(values)

The result field contains values in ascending order, for example, [1, 2, 3] for [3, 1, 2].

mvzip​

Pairs elements of two multivalue values by index. Uses a comma as the default separator; the third argument specifies a different separator. Discards extra elements from the longer list.

... | peval result=mvzip(hosts,addresses,":")

The result field contains pairs in the form host:address built from elements with the same index; extra elements are excluded.

not​

Returns the negation of a Boolean value. For a list, returns true if at least one element is false. Returns null on error.

... | search NOT status="active"

The results contain records where status is not active.

notEqual​

Compares string representations case-sensitively and returns true if they differ. For a list, returns true only if none of its elements matches the second argument. Returns null on error.

... | search status!="active"

The results contain records where status differs from active, considering case.

now​

Returns the current time as the number of seconds since January 1, 1970 (Unix time).

... | peval result=now()

The result field contains the current Unix time in seconds; the number changes with each execution.

null​

Returns null. Takes no arguments.

... | peval result=null

The result field contains null.

nullif​

Returns null if two values are equal; otherwise, returns the first value. Also returns null on comparison error.

... | peval result=nullif(status,"unknown")

The result field contains null if status is unknown; otherwise, the original status value.

or​

Performs logical OR. If one argument is a list, returns true when at least one comparison yields true. Returns false for an empty list and null on error.

... | search status="error" OR status="warning"

The results contain records where status is error or warning.

pi​

Returns the mathematical constant pi as a floating-point number. Takes no arguments.

... | peval result=2*pi()*radius

The result field contains the circumference of a circle with radius radius, that is, 2 * pi * radius.

plus​

Adds two single values using +. If one argument is null, returns the other; if both are null, or a list or set is supplied, returns null.

... | peval result=5+2

The result field contains 7.

pow​

Raises a number to a power. The base or exponent can be a list; returns null on error. In the current implementation, any positive integer exponent of 2 or greater returns the square of the base, while a negative integer exponent returns null.

... | peval result=pow(3,2)

The result field contains 9.

printf​

Formats a string: the first argument specifies the format, and subsequent arguments are substituted in order. Returns a single argument unchanged; no arguments or an invalid format cause an error.

... | peval result=printf("Узел %s: %d ошибок",host,errors)

The result field contains a string with substituted values, for example, Узел server-1: 3 ошибок when host = server-1 and errors = 3.

random​

Returns a pseudorandom integer. Without arguments, uses long; with one argument n, selects a number from 0 through n-1; with two arguments, uses an inclusive lower bound and an exclusive upper bound.

... | peval result=random(10)

The result field contains a random integer from 0 through 9, inclusive.

replace​

Replaces all regular expression matches in a string. For a list, processes each element. If the replacement is null, uses an empty string; if the pattern is null, searches for two consecutive quotation marks (/""/).

... | peval result=replace(message,/\d+/,"X")

In result, all digit sequences in message are replaced with X, for example, id=X for id=123.

round​

Rounds a number to the specified number of decimal places; by default, to an integer. Rounds halfway values away from zero. Accepts a single number or a list; returns null on error.

... | peval result=round(2.345,2)

The result field contains 2.35.

rtrim​

Removes characters from the end of a string. An empty second argument or null means that trailing whitespace is removed. Otherwise, the second argument specifies the set of characters to remove. For a list or set, processes each element.

... | peval result=rtrim("Ошибка__","_")

The result field contains Ошибка.

sigfig​

Despite its name, the current implementation rounds a number to the nearest long integer rather than to a specified number of significant digits. Accepts a single value or a list; returns null on error.

... | peval result=sigfig(12.7)

The result field contains 13.

split​

Splits a string using the specified separator and returns a list of nonempty parts. Returns null for null, a list, or a set.

... | peval result=split("А,,Б",",")

The result field contains ["А", "Б"]: the empty part between the commas is removed.

sqrt​

Calculates the square root of a number. Accepts a single value or a list. Returns null on conversion error; for a negative number, the result is NaN.

... | peval result=sqrt(9)

The result field contains 3.0.

strftime​

Converts Unix time in seconds to a string using a Java SimpleDateFormat pattern. For a list, processes each timestamp separately. The result depends on the runtime time zone; returns null on error.

... | peval result=strftime(timestamp,"yyyy-MM-dd")

The result field contains the date from timestamp in year-month-day format, for example, 2024-01-01.

strptime​

Converts a date and time string to Unix time in seconds using a Java SimpleDateFormat pattern. For a list, processes each string separately. The result depends on the runtime time zone; returns null on error.

... | peval result=strptime(date_text,"yyyy-MM-dd HH:mm:ss")

The result field contains Unix time in seconds for the date in date_text; the exact number depends on the runtime time zone.

substr​

Extracts part of a string. With two arguments, returns the string from the index to the end; a positive index is zero-based. With three arguments, the third specifies the number of characters, and a positive starting position is one-based. A negative position counts from the end.

... | peval result=substr("abcdef",2,3)

The result field contains bcd: three characters starting at the second position.

tobool​

Converts a value to Boolean. For a number, returns true if greater than zero; for a string, only if it equals "true", ignoring case. For a list, converts each element; for a single null, returns null.

... | peval result=tobool(enabled)

The result field contains true for a positive number or the string true; for zero, negative numbers, and other strings, false.

tonumber​

Converts a value to a number. Uses base ten by default; the second argument specifies a base from 2 to 36 for integers. Fractional values are converted as decimal numbers. For a list, processes each element; returns null if conversion is impossible.

... | peval result=tonumber("FF",16)

The result field contains 255: the hexadecimal number FF.

tostring​

Converts a value to a string. Returns the string "null" for null; for a list, converts each element. Formats ZonedDateTime with milliseconds and a time zone offset.

... | peval result=tostring(value)

The result field contains the string representation of value, for example, 42 as a string for the number 42.

trim​

Removes characters from the beginning and end of a string. An empty second argument or null means that whitespace is removed. Otherwise, the second argument specifies the set of characters to remove. For a list or set, processes each element.

... | peval result=trim("__Ошибка__","_")

The result field contains Ошибка.

true​

Returns the Boolean value true. Takes no arguments.

... | peval result=true

The result field contains true.

typeof​

Returns the value type as a string: "Number", "Boolean", or "String". For a list, returns the type of each element. Returns null for null and other types.

... | peval result=typeof(value)

The result field contains Number, Boolean, or String, depending on the type of value; for another type, null.

upper​

Converts a value to an uppercase string. For a list, converts each element; for a single null, returns null.

... | peval result=upper(hostname)

The result field contains hostname in uppercase, for example, SERVER for server.

validate​

Evaluates condition-value pairs in order and returns the value from the first pair whose condition is false. Returns null if all conditions are true or an error occurs.

... | peval result=validate(status!="error","Ошибка",true,"")

The result field contains Ошибка if status is error; otherwise, null.

wildcard and wildcardsens​

Compare a value with a pattern. In a pattern, * represents any sequence of characters, and ? represents one character. wildcard is case-insensitive; wildcardsens is case-sensitive. For a list, one match is sufficient; return false for null and on error. If the tested value itself is "*", the current implementation always returns true.

... | search host="server-*"
... | search sens host="Server-*"

The first query retains host names matching server-* without considering case. The second considers case and retains only names beginning with Server-.