Collection Functions

Overview

These functions return information about the collection or checks for the presence of a specified element.

Create a collection by declaring the elements inline, enclosed in square brackets:

['john.doe@example.org', 'mary.jones@example.org']

Alternatively, load a named collection using the collection() function or another lookup function.

collection('oncall-emails')

Reference

IN

string s IN (string a[, string b[...]]) bool

Returns true if string s equals one of the strings enclosed in round brackets and separated by comma.

Examples:

// Returns true if entity is nurswgvml007
entity IN ('nurswgvml007', 'nurswgvml008')
tags.location IN ('NUR', 'SVL')

LIKE

string s LIKE (string a[, string b[...]]) bool

Returns true if string s matches any pattern in the collection of strings enclosed in round brackets and separated by comma. The patterns support ? and * wildcards. The collection can contain string literals and variables.

Examples:

entity LIKE ('nurswgvml*', 'nurswghbs*')
tags.version LIKE ('1.2.*', '1.3.?')
tags.location LIKE ('NUR*', entity.tags.location)

likeAny

likeAny(string s, [string] strcoll) bool

Returns true if string s matches any element in the string collection strcoll.

Load collection strcoll from a named collection or initialize collection strcoll from an array of strings. The elements of the collection can include patterns with ? and * wildcards.

Examples:

likeAny(tags.request_ip, ['192.0.2.1', '192.0.2.2'])
likeAny(tags.location, ['NUR', 'SVL*'])
likeAny(tags.request_ip, collection('ip_white_list'))

matchList

matchList(string s, string name) bool

Returns true if s matches one of the elements in the collection identified by name.

The collection can include patterns with ? and * wildcards.

Example:

matchList(tags.request_ip, 'ip_white_list')

matches

matches(string pattern, [string] strcoll) bool

Returns true if one of the elements in collection strcoll matches the specified pattern.

The pattern supports ? and * wildcards.

Example:

matches('*atsd*', property_values('docker.container::image'))

contains

[string].contains(string s) bool

Returns true if string s is contained in the specified collection.

Example:

collection('ip_white_list').contains(tags.request_ip)

size

[].size() int

Returns the number of elements in the collection.

Note

The function can be applied to a collection containing elements of any type (string, number) as well as maps such as entity.tags.

Examples:

collection('ip_white_list').size()
entity.tags.size()

isEmpty

[].isEmpty() bool

Returns true if the number of elements in the collection is zero.

Data Types

The function can be applied to a collection containing elements of any type (string, number) as well as maps such as entity.tags.

Example:

collection('ip_white_list').isEmpty()

excludeKeys

excludeKeys(map, [string] strcoll) map

Returns a copy of the input key-value map without the keys specified in collection strcoll.

The keys in strcoll can contain wildcards ? and * to remove multiple matching keys from the map.

Examples:

excludeKeys(replacementTable('oncall-emails'),['jack.smith@example.org', 'mary.jones@example.org'])
/* Returns ["b1": "w1", "b2": "w2"] */
excludeKeys(["a1": "v1", "a2": "v2", "b1": "w1", "b2": "w2", "c1": "z1"], ['a*', 'c1'])