GET /api/v4/rules/{rule_id}
获取某个规则的详情,包括规则的 SQL、Topics 列表、动作列表等。还会返回当前规则和动作的统计指标的值。
Path Parameters:
Success Response Body (JSON):
Name | Type | Description |
---|---|---|
code | Integer | 0 |
data | Object | 规则对象 |
- data.id | String | Rule ID |
- data.rawsql | String | SQL 语句,与请求中的 rawsql 一致 |
- data.for | String | Topic 列表,表示哪些 topic 可以匹配到此规则 |
- data.metrics | Array | 统计指标,具体可参看 Dashboard 上的 Rule Metrics |
- data.description | String | 规则的描述信息,与请求中的 description 一致 |
- data.actions | Array | 动作列表 |
- data.actions[0].id | String | Action ID |
- data.actions[0].params | Object | 动作参数,与请求中的 actions.params 一致 |
- data.actions[0].name | String | 动作名字,与请求中的 actions.name 一致 |
- data.actions[0].metrics | Array | 统计指标,具体可参看 Dashboard 上的 Rule Metrics |
POST /api/v4/rules
创建规则,返回规则 ID。
Parameters (json):
Name | Type | Description |
---|---|---|
code | Integer | 0 |
data | Object | 创建成功的规则对象,包含 Rule ID |
- data.id | String | Rule ID |
- data.rawsql | String | SQL 语句,与请求中的 rawsql 一致 |
- data.for | String | Topic 列表,表示哪些 topic 可以匹配到此规则 |
- data.metrics | Array | 统计指标,具体可参看 Dashboard 上的 Rule Metrics |
- data.description | String | 规则的描述信息,与请求中的 description 一致 |
- data.actions | Array | 动作列表,每个动作是一个 Object |
- data.actions[0].id | String | Action ID |
- data.actions[0].params | Object | 动作参数,与请求中的 actions.params 一致 |
- data.actions[0].name | String | 动作名字,与请求中的 actions.name 一致 |
- data.actions[0].metrics | Array | 统计指标,具体可参看 Dashboard 上的 Rule Metrics |
PUT /api/v4/rules/{rule_id}
更新规则,返回规则 ID。
Parameters (json):
Success Response Body (JSON):
Name | Type | Description |
---|---|---|
code | Integer | 0 |
data | Object | 创建成功的规则对象,包含 Rule ID |
- data.id | String | Rule ID |
- data.rawsql | String | SQL 语句,与请求中的 rawsql 一致 |
- data.for | String | Topic 列表,表示哪些 topic 可以匹配到此规则 |
- data.metrics | Array | 统计指标,具体可参看 Dashboard 上的 Rule Metrics |
- data.description | String | 规则的描述信息,与请求中的 description 一致 |
- data.actions | Array | 动作列表,每个动作是一个 Object |
- data.actions[0].id | String | Action ID |
- data.actions[0].params | Object | 动作参数,与请求中的 actions.params 一致 |
- data.actions[0].name | String | 动作名字,与请求中的 actions.name 一致 |
- data.actions[0].metrics | Array | 统计指标,具体可参看 Dashboard 上的 Rule Metrics |
DELETE /api/v4/rules/{rule_id}
删除规则。
Parameters: 无
Examples:
添加一个规则,对于所有匹配到主题 “t/a” 的消息,打印其规则运行参数。
使用规则 ID 获取刚才创建的规则详情:
{"data":{"rawsql":"select * from \"t/a\"","metrics":[{"speed_max":0,"speed_last5m":0.0,"speed":0.0,"node":"emqx@127.0.0.1","matched":0}],"id":"rule:7fdb2c9e","for":["t/a"],"enabled":true,"description":"test-rule","actions":[{"params":{"a":1},"name":"inspect","metrics":[{"success":0,"node":"emqx@127.0.0.1","failed":0}],"id":"inspect_1582434715354188116"}]},"code":0}
获取所有的规则,注意返回值里的 data 是个规则对象的数组:
更新一下规则的 SQL 语句,改为 :
删除规则:
$ curl -XDELETE --basic -u admin:public 'http://localhost:8081/api/v4/rules/rule:7fdb2c9e'