Alarm Conditions
eq(topic, value) gt(topic, value) lt(topic, value) updated(topic, interval, unit) changed(topic, interval, unit) changed(topic, interval, unit, threshold) recent(topic) |
IAP provides a number of functions that allow you to establish the desired conditions for your alarms. The alarm condition is expressed in JavaScript. Any valid JavaScript construct may be used to combine or evaluate the results of these functions, or to construct arguments to these functions. The topic is typically, but not necessarily, a feedback channel topic.
Comparison Functions
eq(topic, value) gt(topic, value) It(topic, value) |
There are three comparison functions: eq (equals), gt (greater than), and lt (less than). These functions compare the most recent value received for the specified topic with the specified value, and return a Boolean result. The topic is typically, but not necessarily, a feedback channel topic.
The alarm condition is expressed in JavaScript. JavaScript expressions that use the standard JavaScript operators can be used to combine or evaluate the results of these functions, or to construct arguments to these functions.
When the alarm manager encounters the topic for the first time, it separates it into the IAP resource topic and the property selector parts, and subscribes to the IAP resource topic to track changes. When a newly published value is received on that topic, all alarm conditions that are based on that topic are evaluated. A resource topic is a topic that appears in one of the IAP channels, and the property selector is a slash-separated list of properties within that topic.
Topic examples: This topic refers to an IAP resource: glp/0/dt/fb/dev/cm/0/if/light/0 This topic refers to a property within the same IAP resource: glp/0/dt/fb/dev/cm/0/if/light/0/sp/value/b |
In the three comparison functions (eq, gt, lt), value accepts any value compatible with the topic: a string, number, Boolean constant, list, or object.
- Null can only be equal to itself (null eq null is always True).
- Null is always less than any other value (except for null).
- Two numbers are compared using standard arithmetic.
- Two strings are compared using lexicographic sorting.
- Two lists are compared with their member count; the list with more members is “greater than” the list with fewer members.
- Objects can only be compared for equality (or non-equality); ordered comparisons such as “less than” or “greater than” yield a runtime error when applied to an object.
- Comparison between items of a different type may be possible if the automatic data conversion rules detailed under Type Translation yield a value pair that can be compared. For example, number 17 can be compared with string “18”, and 17 is less than “18”.
- Standard JavaScript operators !, && or ||, among others, are available and supported to provide logic inversion and combination:
!gt("glp/0/dt/fb/dev/cm/0/if/light/0/sp/value/b", 0.5) |
Updated and Changed Functions
updated(topic, interval, unit) changed(topic, interval, unit) changed(topic, interval, unit, threshold) |
These functions detect whether a value has been updated or changed within a certain interval:
- updated() yields true if the value referenced by topic has been published, regardless of its value, less than the amount of time specified by interval.
- changed() without a threshold yields true if the value referenced by topic has been published and changed from the previous value less than the amount of time specified by interval. The alternative form uses an explicit threshold value to control the amount by which the value must change.
When a newly published value is received on that topic, all alarm conditions that depend on the topic are evaluated. The alarm manager repeatedly evaluates the alarm conditions that use updated() or changed() functions as per the unit specified: every millisecond if unit is 'ms', every second if unit is 's', and so forth. That way, the alarm manager does not evaluate alarm conditions more than necessary, and the user has control over the accuracy of the time expression: a condition with a timer of 60s is evaluated once per second, while a condition with a timer of 60000 ms is evaluated 1000 times per second.
A specific alarm manager implementation can restrict high-frequency evaluations, perhaps to a maximum rate of 10 per second.
These functions use the following parameters:
topic | (Required) See the above description of topic for the comparison functions (eq, gt, and lt). | ||||||||
interval | (Required) A number expressed as multiples of the duration specified with unit. | ||||||||
unit | (Required) Can be either:
| ||||||||
threshold | (Optional) Defines the unsigned threshold by which the value must change within the duration specified by interval and unit. |
Utility Function
recent(topic) |
The utility function, recent, returns the most recent value associated with topic, or null, if none is known. The definition of topic is the same as for the comparison functions (eq, gt, lt) described above.
Executing Alarm Conditions
Executing a user-defined alarm condition code is restricted to calling the well-defined functions above, and combinations with built-in operators. Any syntax errors or attempts to access functionality that is not permitted by the alarm condition sandbox must be reported as runtime errors.
System Alarm Conditions
Specific implementations can also support special topics in addition to topics referencing process values. Those special topics generally take the form: glp/0/./=alarm/...
An alarm manager could also expose system resources such as the CPU temperature, overall memory usage, or an individual process’ memory consumption, allowing for alarm conditions like the following CPU temperature monitor: gt(“glp/0/./=alarm/system/cpu/temperature”, 85)
The available system topics are listed with each product's documentation. For the SmartServer default alarms, see SmartServer Alarm Conditions.