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)
collection_contains(object v, [] c) boolean

collection_contains

Returns true if the specified collection contains the value. The match is case-sensitive. Note that the name of the collection is specified as the second argument.

The function raises an error if the specified collection is not found.

collection_contains(string value, string name) boolean
collection_contains(os_name, 'os_whitelist')

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()

compareMaps

compareMaps(map a, map b [, boolean ignoreEmpty])

Compares two maps and returns a map consisting of keys with differences in values. The difference is a string created using the 'old_value' -> 'new_value' pattern.

The values are compared in case-insensitive manner.

If ignoreEmpty argument is false, the returned map contains keys that are present in one map and absent in the other map.

copyList

copyList(list a) list

Returns a copy of the input list.

copyMap

copyMap(map a) map

Returns a copy of the input map.

createMap

createMap() map

Returns an empty map.

mergeMaps

mergeMaps(map a, map b) map

Returns a new map consisting of entries from both maps a and b. If the key is present in both maps, the key from map b overrides the key in map a.

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'])