On this page
/api/tree
树是元数据,用于以类似于常规文件系统的分层结构组织时间序列以进行浏览。 /tree
根目录下的许多端点允许使用各种与树相关的数据:
Tree API 端点
/tree
端点允许创建或修改树定义。树定义包括可通过此端点访问的配置和元数据,以及可通过/tree/rule
或/tree/rules
访问的规则集。
Note
创建树时,默认情况下会将enabled
字段设置为false
。创建树后,应添加规则,然后将tree/test
端点与几个 TSUID 一起使用,以确保生成的树将符合您的期望。验证结果之后,可以将enabled
字段设置为true
,然后新的 TSMeta 对象或树同步将开始填充分支。
Verbs
GET-检索一个或多个树定义
POST-编辑树字段
PUT-替换树字段
删除-删除树和/或树定义的结果
Requests
以下字段可用于所有树端点请求:
Name | Data Type | Required | Description | Default | QS | RW | Example |
---|---|---|---|---|---|---|---|
treeId | Integer | Required* | 用于获取或修改特定的树。 *创建新树时,不得存在tree 值。 |
treeid | RO | 1 | |
name | String | Required* | 树的简短描述性名称。 *仅在创建树时需要。 | name | RW | Network Infrastructure | |
description | String | Optional | 关于树包含的内容的详细说明 | description | RW | 包含所有网络设备的树 | |
notes | String | Optional | 关于树的详细说明 | notes | RW | ||
strictMatch | Boolean | Optional | 如果时间序列未能匹配一个或多个规则级别,则是否应将时间序列包括在树中。 | false | strict_match | RW | true |
enabled | Boolean | Optional | 是否应通过树处理 TSMeta。默认情况下,此设置为false ,以便您可以在构建分支之前设置规则并测试某些对象。 |
false | enabled | RW | true |
storeFailures | Boolean | Optional | 是否应记录冲突和“不匹配”的 TSUID。这样可以创建非常宽的行。 | false | store_failures | RW | true |
definition | Boolean | Optional | 仅在DELETE 进入树时使用,如果此标志设置为 true,则整个树定义以及所有分支,碰撞和不匹配的条目将被删除 |
false | definition | true |
Response
对GET
,POST
或PUT
请求的成功响应将返回带有对象请求的更改的树对象。成功的DELETE
呼叫将返回204
状态代码且没有正文。修改数据时,如果不存在任何更改,即调用未提供要存储的任何数据,则响应将为304
而没有任何正文内容。如果请求的树在系统中不存在,将返回404
并显示错误消息。如果提供了无效数据,将返回400
错误。
除其他字段外,响应中还将显示所有 Request 字段:
Name | Data Type | Description | Example |
---|---|---|---|
rules | Map | 具有由level 和order 组织的树定义规则的 Map 或字典。如果尚未定义任何规则,则值为null |
See Examples |
created | Integer | 最初创建树时的 Unix Epoch 时间戳,以秒为单位。 | 1350425579 |
GET
没有树 ID 的GET
到/api/tree
的请求将返回系统中配置的所有树的列表。结果将包括为每棵树配置的规则。如果尚未配置任何树,则列表将为空。
示例 GET All Trees 查询
http://localhost:4242/api/tree
Example Response
[
{
"name": "Test Tree",
"description": "My Description",
"notes": "Details",
"rules": {
"0": {
"0": {
"type": "TAGK",
"field": "host",
"regex": "",
"separator": "",
"description": "Hostname rule",
"notes": "",
"level": 0,
"order": 0,
"treeId": 1,
"customField": "",
"regexGroupIdx": 0,
"displayFormat": ""
}
},
"1": {
"0": {
"type": "METRIC",
"field": "",
"regex": "",
"separator": "",
"description": "",
"notes": "Metric rule",
"level": 1,
"order": 0,
"treeId": 1,
"customField": "",
"regexGroupIdx": 0,
"displayFormat": ""
}
}
},
"created": 1356998400,
"treeId": 1,
"strictMatch": false,
"storeFailures": false,
"enabled": true
},
{
"name": "2nd Tree",
"description": "Other Tree",
"notes": "",
"rules": {
"0": {
"0": {
"type": "TAGK",
"field": "host",
"regex": "",
"separator": "",
"description": "",
"notes": "",
"level": 0,
"order": 0,
"treeId": 2,
"customField": "",
"regexGroupIdx": 0,
"displayFormat": ""
}
},
"1": {
"0": {
"type": "METRIC",
"field": "",
"regex": "",
"separator": "",
"description": "",
"notes": "",
"level": 1,
"order": 0,
"treeId": 2,
"customField": "",
"regexGroupIdx": 0,
"displayFormat": ""
}
}
},
"created": 1368964815,
"treeId": 2,
"strictMatch": false,
"storeFailures": false,
"enabled": false
}
]
要获取特定的树,请提供`` treeId'值。如果找到,响应将包括树对象。如果请求的树不存在,则将返回 404 异常。
示例 GET 单棵树
http://localhost:4242/api/treeId?tree=1
Example Response
{
"name": "2nd Tree",
"description": "Other Tree",
"notes": "",
"rules": {
"0": {
"0": {
"type": "TAGK",
"field": "host",
"regex": "",
"separator": "",
"description": "",
"notes": "",
"level": 0,
"order": 0,
"treeId": 2,
"customField": "",
"regexGroupIdx": 0,
"displayFormat": ""
}
},
"1": {
"0": {
"type": "METRIC",
"field": "",
"regex": "",
"separator": "",
"description": "",
"notes": "",
"level": 1,
"order": 0,
"treeId": 2,
"customField": "",
"regexGroupIdx": 0,
"displayFormat": ""
}
}
},
"created": 1368964815,
"treeId": 2,
"strictMatch": false,
"storeFailures": false,
"enabled": false
}
POST/PUT
使用POST
或PUT
方法,您可以创建新树或编辑现有树的大多数字段。新树需要name
值,而`` ID 和任何需要修改的字段都需要。成功的请求将返回修改后的树对象。
Note
一棵新树将没有任何规则。您的下一个通话应该应该是/tree/rule
或/tree/rules
。
POST 创建请求示例
http://localhost:4242/api/tree?name=Network%20Tree&method_override=post
Example Response
{
"name": "Network",
"description": "",
"notes": "",
"rules": null,
"created": 1368964815,
"treeId": 3,
"strictMatch": false,
"storeFailures": false,
"enabled": false
}
POST 编辑请求示例
http://localhost:4242/api/tree?treeId=3&description=Network%20Device%20Information&method_override=post
Example Response
{
"name": "Network",
"description": "Network Device Information",
"notes": "",
"rules": null,
"created": 1368964815,
"treeId": 3,
"strictMatch": false,
"storeFailures": false,
"enabled": false
}
DELETE
使用DELETE
方法只会从存储中删除冲突,而不会删除给定树的匹配条目和分支。该端点开始删除。因为删除可能需要一些时间,所以如果删除完成,则端点将返回成功的 204 响应而没有数据。如果未找到树,则它将返回 404.如果要删除树定义本身,则可以在查询字符串中提供_标志,其值为true
,并且树和规则定义也将被删除。
Warning
此方法无法撤消。一旦执行,清除将 continue 运行,除非关闭 TSD。
Note
在执行DELETE
查询之前,应确保数据上没有运行手动树同步。如果是这样,在清除过程中可能会存储一些孤立的分支或叶子。删除后的某个时间使用 CLi 工具清理残留在分支或叶子上的东西。
删除请求示例
http://localhost:4242/api/tree?tree=1&method_override=delete