调试模式用于调试日志的输出,测试阶段建议选择
点击规则链,进入详情页面
打开规则链进行规则配置
规则链节点类型分为6类,每一类下面又包含多个小类
定义一个规则:JSON在最后
curl -v -X POST http://192.168.0.16:8080/api/v1/vl4hijxt4ihg4szr2xdl/telemetry --header Content-Type:application/json --data "{temperature:60,mac:\"HTTP设备\"}"
打开规则中的Debug模式
查看消息的输入与输出
观察最终结果-属性
观察最终结果-告警
观察最终结果-kafka
{
"ruleChain": {
"additionalInfo": {
"description": ""
},
"name": "device profile switch example",
"type": "CORE",
"firstRuleNodeId": null,
"root": false,
"debugMode": false,
"configuration": null,
"externalId": null
},
"metadata": {
"firstNodeIndex": 0,
"nodes": [
{
"additionalInfo": {
"description": "设备配置选择",
"layoutX": 125,
"layoutY": 334
},
"type": "org.thingsboard.rule.engine.filter.TbDeviceTypeSwitchNode",
"name": "to device rule chain",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"version": 0
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 306,
"layoutY": 580
},
"type": "org.thingsboard.rule.engine.transform.TbTransformMsgNode",
"name": "修改温度",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"scriptLang": "JS",
"jsScript": "var hsTemp = msg.temperature * 33.8\nmsg.hsTemp = hsTemp\nreturn {msg: msg, metadata: metadata, msgType: msgType};",
"tbelScript": "return {msg: msg, metadata: metadata, msgType: msgType};"
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 877,
"layoutY": 517
},
"type": "org.thingsboard.rule.engine.action.TbCreateAlarmNode",
"name": "温度预警",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"scriptLang": "TBEL",
"alarmDetailsBuildJs": "var details = {};\nif (metadata.prevAlarmDetails) {\n details = JSON.parse(metadata.prevAlarmDetails);\n //remove prevAlarmDetails from metadata\n delete metadata.prevAlarmDetails;\n //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
"alarmDetailsBuildTbel": "var details = {};\nif (metadata.prevAlarmDetails != null) {\n details = JSON.parse(metadata.prevAlarmDetails);\n //remove prevAlarmDetails from metadata\n // metadata.remove('prevAlarmDetails');\n //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
"useMessageAlarmData": false,
"overwriteAlarmDetails": false,
"alarmType": "General Alarm",
"severity": "CRITICAL",
"propagate": false,
"relationTypes": [],
"propagateToOwner": false,
"propagateToTenant": false,
"dynamicSeverity": false
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 882,
"layoutY": 355
},
"type": "org.thingsboard.rule.engine.action.TbClearAlarmNode",
"name": "消除",
"debugMode": false,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"alarmType": "General Alarm",
"scriptLang": "TBEL",
"alarmDetailsBuildJs": "var details = {};\nif (metadata.prevAlarmDetails) {\n details = JSON.parse(metadata.prevAlarmDetails);\n //remove prevAlarmDetails from metadata\n delete metadata.prevAlarmDetails;\n //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
"alarmDetailsBuildTbel": "var details = {};\nif (metadata.prevAlarmDetails != null) {\n details = JSON.parse(metadata.prevAlarmDetails);\n //remove prevAlarmDetails from metadata\n metadata.remove('prevAlarmDetails');\n //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;"
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 531,
"layoutY": 477
},
"type": "org.thingsboard.rule.engine.filter.TbJsFilterNode",
"name": "temperature",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"scriptLang": "TBEL",
"jsScript": "return msg.temperature > 20;",
"tbelScript": "return msg.temperature > 50 || msg.temperature < 10;"
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 1198,
"layoutY": 420
},
"type": "org.thingsboard.rule.engine.kafka.TbKafkaNode",
"name": "告警消息",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"topicPattern": "tb_test_topic",
"keyPattern": " $[metadataKey]",
"bootstrapServers": "192.168.0.11:9092,192.168.0.12:9092,192.168.0.13:9092",
"retries": 0,
"batchSize": 16384,
"linger": 0,
"bufferMemory": 33554432,
"acks": "-1",
"keySerializer": "org.apache.kafka.common.serialization.StringSerializer",
"valueSerializer": "org.apache.kafka.common.serialization.StringSerializer",
"otherProperties": {},
"addMetadataKeyValuesAsKafkaHeaders": true,
"kafkaHeadersCharset": "UTF-8"
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 861,
"layoutY": 615
},
"type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode",
"name": "保存属性",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 1,
"configuration": {
"scope": "SERVER_SCOPE",
"notifyDevice": false,
"sendAttributesUpdatedNotification": false,
"updateAttributesOnlyOnValueChange": true
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 860,
"layoutY": 720
},
"type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",
"name": "保存遥测",
"debugMode": false,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"defaultTTL": 0,
"skipLatestPersistence": false,
"useServerTs": false
},
"externalId": null
},
{
"additionalInfo": {
"description": "",
"layoutX": 529,
"layoutY": 651
},
"type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode",
"name": "消息类型配置",
"debugMode": true,
"singletonMode": false,
"configurationVersion": 0,
"configuration": {
"version": 0
},
"externalId": null
}
],
"connections": [
{
"fromIndex": 0,
"toIndex": 1,
"type": "HTTP设备配置"
},
{
"fromIndex": 1,
"toIndex": 4,
"type": "Success"
},
{
"fromIndex": 1,
"toIndex": 8,
"type": "Success"
},
{
"fromIndex": 2,
"toIndex": 5,
"type": "Created"
},
{
"fromIndex": 2,
"toIndex": 5,
"type": "Updated"
},
{
"fromIndex": 3,
"toIndex": 5,
"type": "Cleared"
},
{
"fromIndex": 4,
"toIndex": 2,
"type": "True"
},
{
"fromIndex": 4,
"toIndex": 3,
"type": "False"
},
{
"fromIndex": 8,
"toIndex": 6,
"type": "Post attributes"
},
{
"fromIndex": 8,
"toIndex": 7,
"type": "Post telemetry"
}
],
"ruleChainConnections": null
}
}