9 String functions

All functions listed here are supported in:

The functions are listed without additional information. Click on the function to see the full details.

FunctionDescription
asciiThe ASCII code of the leftmost character of the value.
bitlengthThe length of value in bits.
bytelengthThe length of value in bytes.
charReturn the character by interpreting the value as ASCII code.
concatThe string resulting from concatenating the referenced item values or constant values.
insertInsert specified characters or spaces into the character string beginning at the specified position in the string.
leftReturn the leftmost characters of the value.
lengthThe length of value in characters.
ltrimRemove specified characters from the beginning of string.
midReturn a substring of N characters beginning at the character position specified by ‘start’.
repeatRepeat a string.
replaceFind the pattern in the value and replace with replacement.
rightReturn the rightmost characters of the value.
rtrimRemove specified characters from the end of string.
trimRemove specified characters from the beginning and end of string.

Function details

Some general notes on function parameters:

  • Function parameters are separated by a comma
  • Expressions are accepted as parameters
  • String parameters must be double-quoted; otherwise they might get misinterpreted
  • Optional function parameters (or parameter parts) are indicated by < >
ascii(value)

The ASCII code of the leftmost character of the value.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check

For example, a value like ‘Abc’ will return ‘65’ (ASCII code for ‘A’).

Example:

  1. ascii(last(/host/key))
bitlength(value)

The length of value in bits.
Supported value types: String, Text, Log, Integer.

Parameter:

  • value - the value to check

Example:

  1. bitlength(last(/host/key))
bytelength(value)

The length of value in bytes.
Supported value types: String, Text, Log, Integer.

Parameter:

  • value - the value to check

Example:

  1. bytelength(last(/host/key))
char(value)

Return the character by interpreting the value as ASCII code.
Supported value types: Integer.

Parameter:

  • value - the value to check

The value must be in the 0-255 range. For example, a value like ‘65’ (interpreted as ASCII code) will return ‘A’.

Example:

  1. char(last(/host/key))
concat(<value1>,<value2>,…)

The string resulting from concatenating the referenced item values or constant values.
Supported value types: String, Text, Log, Float, Integer.

Parameter:

  • valueX - the value returned by one of the history functions or a constant value (string, integer, or float number). Must contain at least two parameters.

For example, a value like ‘Zab’ concatenated to ‘bix’ (the constant string) will return ‘Zabbix’.

Examples:

  1. concat(last(/host/key),"bix")
  2. concat("1 min: ",last(/host/system.cpu.load[all,avg1]),", 15 min: ",last(/host/system.cpu.load[all,avg15]))
insert(value,start,length,replacement)

Insert specified characters or spaces into the character string beginning at the specified position in the string.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • start - start position;

  • length - positions to replace;

  • replacement - replacement string.

For example, a value like ‘Zabbbix’ will be replaced by ‘Zabbix’ if ‘bb’ (starting position 3, positions to replace 2) is replaced by ‘b’.

Example:

  1. insert(last(/host/key),3,2,"b")
left(value,count)

Return the leftmost characters of the value.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • count - the number of characters to return.

For example, you may return ‘Zab’ from ‘Zabbix’ by specifying 3 leftmost characters to return. See also right().

Example:

  1. left(last(/host/key),3) #return three leftmost characters
length(value)

The length of value in characters.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check.

Examples:

  1. length(last(/host/key)) #the length of the latest value
  2. length(last(/host/key,#3)) #the length of the third most recent value
  3. length(last(/host/key,#1:now-1d)) #the length of the most recent value one day ago
ltrim(value,<chars>)

Remove specified characters from the beginning of string.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • chars (optional) - specify the characters to remove.

Whitespace is left-trimmed by default (if no optional characters are specified). See also: rtrim(), trim().

Examples:

  1. ltrim(last(/host/key)) #remove whitespace from the beginning of string
  2. ltrim(last(/host/key),"Z") #remove any 'Z' from the beginning of string
  3. ltrim(last(/host/key)," Z") #remove any space and 'Z' from the beginning of string
mid(value,start,length)

Return a substring of N characters beginning at the character position specified by ‘start’.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • start - start position of the substring;

  • length - positions to return in substring.

For example, it is possible return ‘abbi’ from a value like ‘Zabbix’ if starting position is 2, and positions to return is 4.

Example:

  1. mid(last(/host/key),2,4)="abbi"
repeat(value,count)

Repeat a string.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • count - the number of times to repeat.

Example:

  1. repeat(last(/host/key),2) #repeat the value two times
replace(value,pattern,replacement)

Find the pattern in the value and replace with replacement. All occurrences of the pattern will be replaced.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • pattern - the pattern to find;

  • replacement - the string to replace the pattern with.

Example:

  1. replace(last(/host/key),"ibb","abb") - replace all 'ibb' with 'abb'
right(value,count)

Return the rightmost characters of the value.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • count - the number of characters to return.

For example, you may return ‘bix’ from ‘Zabbix’ by specifying 3 rightmost characters to return. See also left().

Example:

  1. right(last(/host/key),3) #return three rightmost characters
rtrim(value,<chars>)

Remove specified characters from the end of string.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • chars (optional) - specify the characters to remove.

Whitespace is right-trimmed by default (if no optional characters are specified). See also: ltrim(), trim().

Examples:

  1. rtrim(last(/host/key)) #remove whitespace from the end of string
  2. rtrim(last(/host/key),"x") #remove any 'x' from the end of string
  3. rtrim(last(/host/key),"x ") #remove any 'x' and space from the end of string
trim(value,<chars>)

Remove specified characters from the beginning and end of string.
Supported value types: String, Text, Log.

Parameter:

  • value - the value to check;

  • chars (optional) - specify the characters to remove.

Whitespace is trimmed from both sides by default (if no optional characters are specified). See also: ltrim(), rtrim().

Examples:

  1. trim(last(/host/key)) - remove whitespace from the beginning and end of string
  2. trim(last(/host/key),"_") - remove '_' from the beginning and end of string

See all supported functions.