Terminology & Syntax

What is AppliesTo Scripting?

Each DataSource has an AppliesTo field, which controls which hosts the DataSource is applied to. AppliesTo Scripting is the language used to express whether a DataSource applies to a device, given a device's properties as input.  If, given the properties of the device as input, the AppliesTo Scripting expression evaluates to True, then the DataSource applies to the device. If not, the DataSource does not apply to the device.  For an overview, see Determining Whether a DataSource Applies to a Device.

AppliesTo Scripting can also be used to build dynamic group queries, auto-assign device properties, or apply device dashboard templates to different devices.

For some quick examples, see the AppliesTo Scripting Examples.

AppliesTo Scripting Functions

true() The simplest case is if the AppliesTo field contains the function true(). With this function, a DataSource instance will unconditionally apply to all hosts, regardless of host properties. Please be careful!
false() The opposite of true(). This completely disassociates the DataSource from any host in your account and purges the historical data.
getPropValue(varName) This will return the value of the designated property. Use this function in cases where your query includes special characters such as "=", ":", or a space
contains (array, "value") Returns True if the specified array of the host contains the specified value. This function can be used with the system.categories, system.groups, system.staticgroups, and system.ips resource properties.

For example, contains(system.groups, "network gear") would apply the DataSource to all hosts in the "network gear" group. The string comparison is not case sensitive. The string being matched does not support glob or regular expressions - it is only a match comparison. To use regular expression matching, use the join(array,string) function to flatten the array.
exists(varName) Returns True if the specified varName exists in the variables.
getCollectorVersion() Gets the value of "system.collectorversion".
hasCategory(varName) Returns True if the system.categories property for a particular host contains the specified value (not case sensitive). Given that the OID to Categories mapping table will have assigned different values to this property based on the system.sysoid, this is a simple way to apply DataSources appropriate for the category of device.
startsWith(property,"value") Returns True if the property "property" starts with "value". e.g., startswith(system.sysinfo,"Cisco") will return True for those hosts that have a system.sysinfo property that starts with the string "Cisco". The string comparison is not case sensitive.
join(array,string)

Flattens the array into a single string, separated by the string separator. This function can be used with the system.categories, system.groups, system.staticgroups, and system.ips resource properties.

Matching IP Addresses: join(system.ips,",") =~ "1\\.1\\.1\\.*" will allow you to test for regex equivalence against the array of IP addresses for a host. This can be used in combination with other regular expressions for different matches. For example, 
join(system.ips,",") =~ "\\d+\\.\\d+\\.\\d+\\.1$" will match only if the last octet is 1. 

Testing for group or subgroup membership: to prevent circular reasoning, you may not refer to dynamic groups in an AppliesTo expression. Therefore, attempting to use join(system.groups,",") will return an error. To return True for all hosts that are members of a normal group Foo or its sub-groups, use join(system.staticgroups,",") =~ "Foo"

<custom.property> Returns true if the property is defined for the host. e.g., activemq.ports
You can also test the value of a property: e.g.,
system.collectorid=="112" See "Referencing Device Properties" below.
(Note that because the system.categories and system.staticgroups properties have multiple values, you should use the join(array,string) function to verify that a specific value is present.)
system.sysoid == ".1.3.6.1.4.1.9.1" Returns True if the host's SNMP Agent OID matches the value.
 

Convenience Functions

There are several convenience functions defined in AppliesTo Scripting:

isAWSService() Check if the value of "system.devicetype" is "2"
isAzureService() Check if the value of "system.devicetype" is "4"
isCisco() Check if "cisco" is contained in "system.sysinfo" or "system.categories"
isCollectorDevice() Check if the value of "system.collector" is "true"
isDevice() Check if the value of "system.devicetype" is 0 or "collectorDataSources" is contained in "system.categories".
isF5() Check if the variable "systemsysoid" starts with "13.6.1.4.1.3375.2.1.3.4.4" or "f5" is contained in "system.categories"
isFreebsd() Check if "freebsd" is contained in "system.sysinfo" or "system.categories"
isLinux() Check if "linux" is contained in "system.sysinfo" or "system.categories" and "Cisco IOS" is not in "system.sysinfo"
isNetApp() Check if "netapp" is contained in "systemsysinfo" or "system.categories"
isNetflow() Check if the value of "systemenablenetflow" is "true"
isNetscaler() Check if "netscaler" is contained in "system.sysinfo" or "system.categories"
isSolaris() check if "solaris" is contained in "system.sysinfo" or "system.categories"
isUnix() Check if “solaris” or “linux" or "freebsd" is contained in "systemsysinfo" or "system.categories"
isWindows() Check if "windows" or "hyper-v" is contained in "system.sysinfo" or "system.categories"
 

Boolean Operators

The following tests are available in AppliesTo Scripting expressions:

"==" Equals
"!=" Not Equals
">" Greater Than
">=" Greater Than or Equal to
"<" Less Than
"<=" Less Than or Equal to
"and" / "&&" logical AND - either expression may be used
"or"  / "||" logical OR - either expression may be used
"(" ")" grouping operator
"=~" regular expression equality. e.g., system.sysinfo =~ "Vista"
"!~" regular expression inequality e.g., system.sysinfo !~ "x64"
"!" logical NOT
 

User Defined Functions

You can define your own functions globally, and those functions can then be called by any datasource.  You can manage user defined functions from Settings | LogicModules | Functions:

User Defined Functions

For more information on creating, editing and deleting user defined functions, see this page.

 

Referencing Device Properties

Most AppliesTo Scripting expressions evaluate device properties.  You can reference device properties in AppliesTo Scripting expressions exactly as they appear in the Info Tab for a device or group (as an unquoted string).  Note that because system.categories and system.groups properties have multiple values, you'll need to use functions such as contains, hasCategory, getPropValue, or join to verify that a specific value is present (as opposed to using Boolean Operators).

Referencing Device Properties