规则引擎 HTTP API

规则 API

创建规则

API 定义:

  1. POST api/v3/rules

参数定义:

rawsqlString,用于筛选和转换原始数据的 SQL 语句
actionsJSON Array,动作列表 actions.name String, 动作名字 actions.params JSON Object, 动作参数
descriptionString,可选,规则描述

API 请求示例:

  1. GET http://localhost:8080/api/v3/rules

API 请求消息体:

  1. {
  2. "rawsql": "select * from \"message.publish\"",
  3. "actions": [{
  4. "name": "inspect",
  5. "params": {
  6. "a": 1
  7. }
  8. }],
  9. "description": "test-rule"
  10. }

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "actions": [{
  5. "name": "inspect",
  6. "params": {
  7. "a": 1
  8. }
  9. }],
  10. "description": "test-rule",
  11. "enabled": true,
  12. "for": "message.publish",
  13. "id": "rule:34476883",
  14. "rawsql": "select * from \"message.publish\""
  15. }
  16. }

查询规则

API 定义:

  1. GET api/v3/rules/:id

API 请求示例:

  1. GET api/v3/rules/rule:34476883

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "actions": [{
  5. "name": "inspect",
  6. "params": {
  7. "a": 1
  8. }
  9. }],
  10. "description": "test-rule",
  11. "enabled": true,
  12. "for": "message.publish",
  13. "id": "rule:34476883",
  14. "rawsql": "select * from \"message.publish\""
  15. }
  16. }

获取当前规则列表

API 定义:

  1. GET api/v3/rules

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "actions": [{
  5. "name": "inspect",
  6. "params": {
  7. "a": 1
  8. }
  9. }],
  10. "description": "test-rule",
  11. "enabled": true,
  12. "for": "message.publish",
  13. "id": "rule:34476883",
  14. "rawsql": "select * from \"message.publish\""
  15. }]
  16. }

删除规则

API 定义:

  1. DELETE api/v3/rules/:id

请求参数示例:

  1. DELETE api/v3/rules/rule:34476883

API 返回数据示例:

  1. {
  2. "code": 0
  3. }

动作 API

获取当前动作列表

API 定义:

  1. GET api/v3/actions?for=${hook_type}

API 请求示例:

  1. GET api/v3/actions

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "app": "emqx_rule_engine",
  5. "description": "Republish a MQTT message to another topic",
  6. "for": "message.publish",
  7. "name": "republish",
  8. "params": {
  9. "target_topic": {
  10. "description": "To which topic the message will be republished",
  11. "format": "topic",
  12. "required": true,
  13. "title": "To Which Topic",
  14. "type": "string"
  15. }
  16. },
  17. "types": []
  18. }]
  19. }

API 请求示例:

  1. GET 'api/v3/actions?for=client.connected'

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "app": "emqx_rule_engine",
  5. "description": "Inspect the details of action params for debug purpose",
  6. "for": "$any",
  7. "name": "inspect",
  8. "params": {},
  9. "types": []
  10. }]
  11. }

查询动作

API 定义:

  1. GET api/v3/actions/:action_name

API 请求示例:

  1. GET 'api/v3/actions/inspect'

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "app": "emqx_rule_engine",
  5. "description": "Inspect the details of action params for debug purpose",
  6. "for": "$any",
  7. "name": "inspect",
  8. "params": {},
  9. "types": []
  10. }
  11. }

资源类型 API

获取当前资源类型列表

API 定义:

  1. GET api/v3/resource_types

返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "config": {
  5. "url": "http://host-name/chats"
  6. },
  7. "description": "forward msgs to host-name/chats",
  8. "id": "resource:a7a38187",
  9. "type": "web_hook"
  10. }]
  11. }

查询资源类型

API 定义:

  1. GET api/v3/resource_types/:type

返回数据示例:

  1. GET api/v3/resource_types/web_hook
  2. {
  3. "code": 0,
  4. "data": {
  5. "description": "WebHook",
  6. "name": "web_hook",
  7. "params": {},
  8. "provider": "emqx_web_hook"
  9. }
  10. }

获取某种类型的资源

API 定义:

  1. GET api/v3/resource_types/:type/resources

API 请求示例:

  1. GET api/v3/resource_types/web_hook/resources

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "config": {"url":"http://host-name/chats"},
  5. "description": "forward msgs to host-name/chats",
  6. "id": "resource:6612f20a",
  7. "type": "web_hook"
  8. }]
  9. }

资源 API

创建资源

API 定义:

  1. POST api/v3/resources

API 参数定义:

typeString, 资源类型
configJSON Object, 资源配置
descriptionString,可选,规则描述

API 请求参数示例:

  1. {
  2. "type": "web_hook",
  3. "config": {
  4. "url": "http://127.0.0.1:9910",
  5. "headers": {"token":"axfw34y235wrq234t4ersgw4t"},
  6. "method": "POST"
  7. },
  8. "description": "web hook resource-1"
  9. }

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": {
  4. "config": {
  5. "headers":{"token":"axfw34y235wrq234t4ersgw4t"},
  6. "method":"POST",
  7. "url":"http://127.0.0.1:9910"
  8. },
  9. "description": "web hook resource-1",
  10. "id": "resource:62763e19",
  11. "type": "web_hook"
  12. }
  13. }

获取资源列表

API 定义:

  1. GET api/v3/resources

API 返回数据示例:

  1. {
  2. "code": 0,
  3. "data": [{
  4. "config": {
  5. "headers":{"token":"axfw34y235wrq234t4ersgw4t"},
  6. "method":"POST",
  7. "url":"http://127.0.0.1:9910"
  8. },
  9. "description": "web hook resource-1",
  10. "id": "resource:62763e19",
  11. "type": "web_hook"
  12. }]
  13. }

查询资源

API 定义:

  1. GET api/v3/resources/:resource_id

API 返回数据示例:

  1. GET 'api/v3/resources/resource:62763e19'
  2. {
  3. "code": 0,
  4. "data": {
  5. "config": {
  6. "headers":{"token":"axfw34y235wrq234t4ersgw4t"},
  7. "method":"POST",
  8. "url":"http://127.0.0.1:9910"
  9. },
  10. "description": "web hook resource-1",
  11. "id": "resource:62763e19",
  12. "type": "web_hook"
  13. }
  14. }

删除资源

API 定义:

  1. DELETE api/v3/resources/:resource_id

API 返回数据示例:

  1. DELETE 'api/v3/resources/resource:62763e19'
  2. {
  3. "code": 0
  4. }