/api/tree

树是元数据,用于以类似于常规文件系统的分层结构组织时间序列以进行浏览。 /tree根目录下的许多端点允许使用各种与树相关的数据:

Tree API 端点

/tree端点允许创建或修改树定义。树定义包括可通过此端点访问的配置和元数据,以及可通过/tree/rule/tree/rules访问的规则集。

Note

创建树时,默认情况下会将enabled字段设置为false。创建树后,应添加规则,然后将tree/test端点与几个 TSUID 一起使用,以确保生成的树将符合您的期望。验证结果之后,可以将enabled字段设置为true,然后新的 TSMeta 对象或树同步将开始填充分支。

Verbs

  • GET-检索一个或多个树定义

  • POST-编辑树字段

  • PUT-替换树字段

  • 删除-删除树和/或树定义的结果

Requests

以下字段可用于所有树端点请求:

NameData TypeRequiredDescriptionDefaultQSRWExample
treeIdIntegerRequired*用于获取或修改特定的树。 *创建新树时,不得存在tree值。 treeidRO1
nameStringRequired*树的简短描述性名称。 *仅在创建树时需要。 nameRWNetwork Infrastructure
descriptionStringOptional关于树包含的内容的详细说明 descriptionRW包含所有网络设备的树
notesStringOptional关于树的详细说明 notesRW
strictMatchBooleanOptional如果时间序列未能匹配一个或多个规则级别,则是否应将时间序列包括在树中。falsestrict_matchRWtrue
enabledBooleanOptional是否应通过树处理 TSMeta。默认情况下,此设置为false,以便您可以在构建分支之前设置规则并测试某些对象。falseenabledRWtrue
storeFailuresBooleanOptional是否应记录冲突和“不匹配”的 TSUID。这样可以创建非常宽的行。falsestore_failuresRWtrue
definitionBooleanOptional仅在DELETE进入树时使用,如果此标志设置为 true,则整个树定义以及所有分支,碰撞和不匹配的条目将被删除falsedefinition true

Response

GETPOSTPUT请求的成功响应将返回带有对象请求的更改的树对象。成功的DELETE呼叫将返回204状态代码且没有正文。修改数据时,如果不存在任何更改,即调用未提供要存储的任何数据,则响应将为304而没有任何正文内容。如果请求的树在系统中不存在,将返回404并显示错误消息。如果提供了无效数据,将返回400错误。

除其他字段外,响应中还将显示所有 Request 字段:

NameData TypeDescriptionExample
rulesMap具有由levelorder组织的树定义规则的 Map 或字典。如果尚未定义任何规则,则值为nullSee Examples
createdInteger最初创建树时的 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

使用POSTPUT方法,您可以创建新树或编辑现有树的大多数字段。新树需要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