Difference between revisions of "Rule/zh-cn"

From Senfi Docs
Jump to: navigation, search
(Created page with "输入 --> 条件 --> 结果")
 
(31 intermediate revisions by the same user not shown)
Line 13: Line 13:
 
   输入 --> 条件 --> 结果
 
   输入 --> 条件 --> 结果
  
   Result Changed --> Actions
+
   结果有所更改 --> 触发事件
  
== Example ==
+
== 例子 ==
* Input: <tt>iot_weighingscale_v1.battery_level</tt>
+
* 输入:<tt>iot_weighingscale_v1.battery_level</tt>
* Condition: < 20
+
* 条件: < 20
* Action: ''Email reminder to replace battery''
+
* 触发事件:''发送电子邮件提醒更换电池''
* Rule execution option: Immediately (means evaluate this rule whenever there is any incoming measurement)
+
* 规则执行选项:立即执行(在有任何测量传入时,评估此规则)
  
== Inputs, Conditions and Result ==
+
== 输入,条件和结果 ==
  
Before adding a Rule, you should already have an event or situation that you wish to be notified about. The event or situation should be one that can be detected by monitoring data received by Senfi.
+
在添加规则之前,您应该已经有想要被受通知的事件或情况。事件或情况必须是能通过监视Senfi接收的数据来检测到的。
  
Select, as '''Inputs''', the '''Metrics''' and '''Measurements''' from which the event or situation can be detected from. Then, [[#constructing_condition|construct the set of '''Conditions''']] that will evaluate to true when event or situation occurs. The result of said '''Conditions''' is the '''Result''' of the Rule.
+
选择要从中检测事件或情况的'''参数''''''测量'''作为'''输入'''。然后, [[Rule/zh-cn#Constructing_Condition|构造一组'''条件''']] ,当事件或情况发生时这些条件的评估结果为真。所述'''条件''''''结果'''便是规则的结果。
  
== Actions ==
+
== 触发事件 ==
Whenever '''Result''' changes (from true to false and vice versa), '''Actions''' may be executed. '''Actions''' includes sending an email, request to a webhook or triggering an alert in the dashboard.
+
只要'''结果'''有所更改(从真到假,反之亦然),就可'''触发事件'''。可'''触发的事件'''包括发送电子邮件,向网络挂钩发送请求或在仪表板中触发警报。
  
=== Content of Actions ===
+
=== 触发事件的内容 ===
Depending on the '''Action''', different content options are available. Some examples is the title & body of an email, and body content for webhook request. You will be able to describe the event or situation that has happened to the recipient of the notification in the content of an '''Action'''
+
根据'''触发的事件''',,可以使用不同的内容选项。一些选项包括电子邮件的标题和正文,以及网络挂钩发送请求的正文内容。您将能够在'''触发事件'''的内容中描述通知接收者发生的事件或情况。
  
To further aid you in describing the event, you can embed the value or tag of an '''Input''' metric in the content of an '''Action'''. You can also embed the Rule's [[#Name_and_Description|Name, Description]] and [[#Name_and_Description|Severity]] in the content of an '''Action'''.
+
为了进一步帮助您描述事件,可以将'''输入'''参数的值或标签嵌入到'''事件'''的内容中。您还可以在'''事件'''的内容中嵌入规则的[[#名称和描述|名称,描述]][[#严重程度|严重性]]
  
To embed:
+
若要镶嵌:
* metric's value, use <tt>${<measurement_code>.<metric_code>}</tt>. e.g: <tt>${iot_temperature_sensor_v1.temperature}</tt>
+
* 参数的值,请使用<tt>${<measurement_code>.<metric_code>}</tt>。 例如:<tt>${iot_temperature_sensor_v1.temperature}</tt>
* metric's tag, use <tt>${<measurement_code>.<tag>}</tt>. e.g: <tt>${iot_temperature_sensor_v1.site_id}</tt>
+
* 参数的标签,请使用<tt>${<measurement_code>.<tag>}</tt>。 例如:<tt>${iot_temperature_sensor_v1.site_id}</tt>
* Rule's name, use <tt>${NAME}</tt>.
+
* 规则的名称,请使用<tt>${NAME}</tt>
* Rule's description, use <tt>${DESCRIPTION}</tt>.
+
* 规则的描述,请使用<tt>${DESCRIPTION}</tt>
* Rule's severity, use <tt>${SEVERITY}</tt>.
+
* 规则的严重程度,请使用<tt>${SEVERITY}</tt>
  
<div class="important">Note: embedding Rule's name, description and severity is case sensitive. You must use all capital letters.</div>
+
<div class="important">注意:在嵌入规则的名称,描述和严重程度时有区分大小写。 您必须使用所有大写字母。</div>
  
Take a look at [[#Detailed_Example | this more detailed example]].
+
请看这个[[#详细的例子 |更详细的例子]]
  
== Rule execution options ==
+
== 规则执行选项 ==
By setting '''Evaluate Type''' to '''Immediate''' or '''Polling''', you can choose to execute a Rule when new values are received for any Input Measurements, or periodically, regardless of whether any Input Measurements have changed.
+
通过将'''评估类型'''设置为'''立即''''''轮询''',您可以选择在收到任何输入测量的新值时执行规则,或不管任何输入测量是否有更改,定期执行规则。
  
If Rule is set to run periodically ('''Polling'''), you must specify how often a Rule is executed by setting '''Intervals''' in seconds.
+
如果将规则设置为定期运行('''轮询'''),则必须通过以秒为单位设置'''间隔'''来指定执行规则的频率。
  
== Misc ==
+
== 杂项 ==
=== Name and Description ===
+
=== 名称和描述 ===
A Rule also has a Name and Description. The Name and Description allows you to describe the event or situation that the Rule detects, such that recipients of the Rule's alert/notification knows exactly what happened and is able to react to it accordingly.
+
规则也有自己的名称和描述。名称和描述允许您描述规则检测到的事件或情况,以使规则的警报/通知的接收者确切知道发生了什么并能够做出相应的反应。
* The Rule's Name is displayed in the CMS' list of Rules.
+
* 规则名称将被显示在内容管理系统的规则列表中。
* The Rule's Name and Description is displayed in the Dashboard.
+
* 规则的名称和描述将被显示在仪表板上。
  
You can also embed the value or tag of '''Input''' metrics in the Description. The syntax is the same as embedding in the content of an '''Action''', as described [[#content_of_action|here]].
+
您也可以在“描述”中嵌入'''输入'''参数的值或标签。使用的语法与嵌入'''触发事件'''描述内容的语法相同,如[[#触发事件的内容|此处]]所述。
  
Description is also the default content of an '''Action'''. You can describe the event or situation once in the Description, and reuse the information in all the Actions of the Rule.
+
规则描述也是'''触发事件'''所使用的默认内容。这样一来,您只需在规则描述里将事件或情况描述一遍,便可以在规则里的各个触发事件重复使用信息。
  
=== Severity ===
+
=== 严重程度 ===
You can also set the severity of the Rule. Default severity is '''Critical'''. Severity allows users of the Dashboard to filter '''Alerts''' by severity and attend to more severe '''Alerts''' first.
+
您还可以设置规则的严重程度。默认严重程度为'''严重'''。严重程度设置可允许仪表板的用户按严重程度筛选'''警报''',并首先关注更严重的'''警报'''
  
== Detailed Example ==
+
== 详细的例子 ==
The event that you would like to be notified about is potential fire in a building.
+
您想要得到通知的事件是建筑物中潜在的火灾。整个建筑物中都有温度传感器。当任何温度传感器的读数超过60°C时,这意味着传感器附近可能已发生火灾。您希望通过电子邮件收到这种情况的通知。
There are temperature sensors throughout the building. When a reading from any temperature sensor exceeds 60°C, a fire has probably broken out near the sensor.
 
You would like to be notified by email of such an occurrence.
 
  
* The '''Input''' in this example would be the metric and measurement that readings from temperature sensor is sent to. e.g: <tt>iot_temperature_sensor_v1.temperature</tt>
+
* 在此示例中,'''输入'''将是温度传感器的读数所发送到的参数和测量。 例如:<tt>iot_temperature_sensor_v1.temperature</tt>
* '''Condition''' is <tt>iot_temperature_sensor_v1.temperature > 60</tt>
+
* '''条件'''<tt>iot_temperature_sensor_v1.temperature > 60</tt>
* '''Action''' is email, with body text:
+
* '''触发的事件'''将会是发送电子邮件,而邮件的正文是:
:<tt>"Potential fire detected in room: ${iot_temperature_sensor_v1.room}. Temperature in the room is ${iot_temperature_sensor_v1.temperature}°C"</tt>
+
:<tt>"检测到潜在火灾的房间:${iot_temperature_sensor_v1.room}。室内温度为${iot_temperature_sensor_v1.temperature}°C"</tt>
  
With the above '''Rule''' configured, when <tt>iot_temperature_sensor.temperature</tt> goes from 59 to 61, an email will be sent with the body text:
+
配置了上述'''规则''' 后,当<tt>iot_temperature_sensor.temperature</tt>从59变为61时,将发送一封包含以下正文的电子邮件:
:"Potential fire detected in room: #03-00. Temperature in the room is 61°C"
+
:"检测到潜在火灾的房间: #03-00。室内温度为61°C。"
  
Note: "room" is a Tag of the <tt>iot_temperature_sensor_v1</tt> measurement that indicates which room the sensor is in.
+
注意:"房间"<tt>iot_temperature_sensor_v1</tt>测量的标签,它指示传感器所在的房间。
  
 
== Constructing Condition ==
 
== Constructing Condition ==
Line 184: Line 182:
 
:This option accepts an additional "function" parameter. Using the custom "function" parameter, transforms each input value
 
:This option accepts an additional "function" parameter. Using the custom "function" parameter, transforms each input value
  
<span class="right">[[Computed_measurement|Next: Computed Measurement]]</span>
+
<span class="right">[[Computed_measurement/zh-cn|下一页:计算的测量]]</span>

Latest revision as of 10:18, 27 November 2019

正如整体概念中介绍的那样,规则是一种工具,您可以使用它来监视资产并在异常情况或事件发生时得到通知。您可以配置规则以发送电子邮件或在仪表板中通知您的操作员。用例包括:在建筑物中检测到火灾,电梯发生故障或机器逾时维修。规则是可用于配置这些通知的工具。

Senfi中的规则包括:

  • 输入-参数和标签值
  • 条件
  • 结果-真或假,布尔值
  • 触发事件-当结果更改时采取措施。例如发送通知电子邮件
  • 规则执行选项-配置何时评估规则

输入条件评估以生成单个布尔结果。当结果的值更改时,诸如发送电子邮件和仪表板警报之类的事件可被触发。 规则执行选项可以让您配置规则的执行方式。例如:评估规则的频率,何时触发事件 等。

 输入 --> 条件 --> 结果
 结果有所更改 --> 触发事件

例子

  • 输入:iot_weighingscale_v1.battery_level
  • 条件: < 20
  • 触发事件:发送电子邮件提醒更换电池
  • 规则执行选项:立即执行(在有任何测量传入时,评估此规则)

输入,条件和结果

在添加规则之前,您应该已经有想要被受通知的事件或情况。事件或情况必须是能通过监视Senfi接收的数据来检测到的。

选择要从中检测事件或情况的参数测量作为输入。然后, 构造一组条件 ,当事件或情况发生时这些条件的评估结果为真。所述条件结果便是规则的结果。

触发事件

只要结果有所更改(从真到假,反之亦然),就可触发事件。可触发的事件包括发送电子邮件,向网络挂钩发送请求或在仪表板中触发警报。

触发事件的内容

根据触发的事件,,可以使用不同的内容选项。一些选项包括电子邮件的标题和正文,以及网络挂钩发送请求的正文内容。您将能够在触发事件的内容中描述通知接收者发生的事件或情况。

为了进一步帮助您描述事件,可以将输入参数的值或标签嵌入到事件的内容中。您还可以在事件的内容中嵌入规则的名称,描述严重性

若要镶嵌:

  • 参数的值,请使用${<measurement_code>.<metric_code>}。 例如:${iot_temperature_sensor_v1.temperature}
  • 参数的标签,请使用${<measurement_code>.<tag>}。 例如:${iot_temperature_sensor_v1.site_id}
  • 规则的名称,请使用${NAME}
  • 规则的描述,请使用${DESCRIPTION}
  • 规则的严重程度,请使用${SEVERITY}
注意:在嵌入规则的名称,描述和严重程度时有区分大小写。 您必须使用所有大写字母。

请看这个更详细的例子

规则执行选项

通过将评估类型设置为立即轮询,您可以选择在收到任何输入测量的新值时执行规则,或不管任何输入测量是否有更改,定期执行规则。

如果将规则设置为定期运行(轮询),则必须通过以秒为单位设置间隔来指定执行规则的频率。

杂项

名称和描述

规则也有自己的名称和描述。名称和描述允许您描述规则检测到的事件或情况,以使规则的警报/通知的接收者确切知道发生了什么并能够做出相应的反应。

  • 规则名称将被显示在内容管理系统的规则列表中。
  • 规则的名称和描述将被显示在仪表板上。

您也可以在“描述”中嵌入输入参数的值或标签。使用的语法与嵌入触发事件描述内容的语法相同,如此处所述。

规则描述也是触发事件所使用的默认内容。这样一来,您只需在规则描述里将事件或情况描述一遍,便可以在规则里的各个触发事件重复使用信息。

严重程度

您还可以设置规则的严重程度。默认严重程度为严重。严重程度设置可允许仪表板的用户按严重程度筛选警报,并首先关注更严重的警报

详细的例子

您想要得到通知的事件是建筑物中潜在的火灾。整个建筑物中都有温度传感器。当任何温度传感器的读数超过60°C时,这意味着传感器附近可能已发生火灾。您希望通过电子邮件收到这种情况的通知。

  • 在此示例中,输入将是温度传感器的读数所发送到的参数和测量。 例如:iot_temperature_sensor_v1.temperature
  • 条件iot_temperature_sensor_v1.temperature > 60
  • 触发的事件将会是发送电子邮件,而邮件的正文是:
"检测到潜在火灾的房间:${iot_temperature_sensor_v1.room}。室内温度为${iot_temperature_sensor_v1.temperature}°C"

配置了上述规则 后,当iot_temperature_sensor.temperature从59变为61时,将发送一封包含以下正文的电子邮件:

"检测到潜在火灾的房间: #03-00。室内温度为61°C。"

注意:"房间"是iot_temperature_sensor_v1测量的标签,它指示传感器所在的房间。

Constructing Condition

This section will guide you to construct a condition using the Rule Editor when adding/editing a Rule in the CMS. The objective here is to tell Senfi how to detect the event or situation that you wish to be notified of.

Rule Editor

The Rule Editor is a graph based "Drag and Drop" editor. Each node in the Editor represents either an Input, Data Transformation, Logic, or an Action. Arrows are used to link the nodes and control the flow of data between nodes.

Input & Output of a node

Arrows coming into the left of a node indicates the node's input,
and arrows going out the right of a node indicates the node's output
.

The graph must always start from Input nodes and ends in the Result or Action nodes (Data originates from Input nodes, is transformed by Data Transformation, Logic nodes, and is consumed by Result & Action nodes).

Input nodes
Metric - outputs the value/s of a metric. can be set to output the last known value, or a range of historical values
Logic Nodes
Compare - comparison operators. e.g. <, >=, ==, !=
Logic - perform "AND" or "OR" between 2 or more boolean values
Data Transformation nodes
Filter - used to filter a range of values and output a subset number of values. Can only be used after a Metric node in "Range of Value" mode and before an Aggregate
Aggregate - used to aggregates a range of values into a single value. E.g. sum, average, median. Can only be used after a Metric node in "Range of Value" mode
Function - value-wise transformation. Transform each value, e.g ABS, Floor, Round etc. Can be used after a Metric node and before a Compare node. Outputs the same number of values as its input.
Result node
Result - Result node. Must have 1 and only 1 node. Specifies the Result of a Rule
Action nodes
Action - Action node. Input must always be from the "Result" node. Can have 0 or more "Action" nodes. Instructs Senfi to do something when Result changes.

Basic Steps

  1. Drag a node above working area into the working area to create a node.
  2. Create "Metric" nodes, one for each Input metric.
  3. Select the correct measurement and metric for each "Metric" node. Read: how to configure a node
  4. (Optional) If you need to compare metric value against a constant value, use the "Constant" node.
  5. Create "Operator" and "Logic" nodes to construct necessary logic
    • logic graph should output a single boolean (true or false) value
    • output from "Metric" node must go to input of a "Operator" node.
    • "Operator" and "Logic" nodes can be nested.
    • You can attach more than 2 inputs to a "Logic" node
  6. Create a "Result" node and attach output of logic graph as its input
  7. Create "Action" nodes, one for each desired Action and attach output of "Result" node as its input
  8. Save when done

Example

Example 1

Example 1: A simple Rule detecting when a Lift has tripped (safetyTrip == 1).

Example 2

Example 2: Detects when a Lift tripped (safetyTrip == 1), AND passengers are trapped in the Lift (load > 0)

Working with historical values

When historical values is required to detect an event, the "Range", "Filter" and "Aggregate" nodes are needed.

By default, a "Metric" node will output the Last Known value of the metric. To obtain historical values of a metric, attach the output of "Metric" node to the input of a "Range" node. The output of the "Range" node will be historical values from the metric.

The configuration options of the "Range" node allows you to change the range of historical values to output. E.g: You can configure it to output metric values from 1 hour ago till now, or the last 10 received metric values.

After obtaining the list of historical values, you can:

  • Filter the list using the "Filter" node.
  • Transform each value in the list using the "Function" node.

The "Filter" and "Function" nodes can be nested.

Finally, the list of historical values must be aggregated using the "Aggregate" node before its output can be used by a "Logic" or "Operator" node.

Example using historical values

Historical Example 1

The example above detects when a Lift is stopped at Level 2 for over a minute.

Configuring Nodes

Each node contains attributes & options which you can modify. To modify the attributes of a node, move your mouse over the node and click on the "Gear" button that appears near the top right corner of the node (Beside the "X" button). A window will popup to allow you to configure the node.

Aggregate node

This section explains what each of the options for "Aggregate" node does.

sum
the sum of all input values
count
the number of input values
average
the average of input values
median
the median value of input values
max
the largest value
min
the smallest value
mode
the value that appears most often
range
the difference between the largest and smallest value (max - min)
stddev
standard deviation
percentile
percentile. This option accepts an additional "Percentile Value" parameter.
every
outputs true if every value fulfills the condition. This option accepts an additional "Condition" parameter.
any
outputs true if at least 1 value fulfills the condition. This option accepts an additional "Condition" parameter.

Function node

This section explains what each of the options in "Function" node does.

abs
absolute value
round
round to nearest integer
ceil
round up
floor
round down
map
This option accepts an additional "function" parameter. Using the custom "function" parameter, transforms each input value

下一页:计算的测量