跳到主要内容

资源 API

资源接口覆盖设备分组、凭据和备份命令模板。所有请求都需要 X-API-Key,并且资源响应只返回各自 API Schema 声明的字段。

列表接口都支持统一分页参数:普通列表默认 page=1limit=50limit 最大为 100

分组

端点

方法路径权限说明
GET/api/v1/groupsgroups.view分页查询分组
GET/api/v1/groups/treegroups.view查询完整分组树
GET/api/v1/groups/{group_id}groups.view获取分组详情
POST/api/v1/groupsgroups.create创建分组,返回 201
PUT/api/v1/groups/{group_id}groups.update更新分组
DELETE/api/v1/groups/{group_id}groups.delete删除分组

查询分组

GET /api/v1/groups?page=1&limit=50

分组列表没有搜索或过滤参数。分组对象字段如下:

字段类型说明
idinteger分组 ID
namestring分组名称
parent_idinteger/null父分组 ID
pathstring分组路径,例如 /1/3/
depthinteger树深度
sort_orderinteger同级排序值
created_atstring创建时间

查询分组树

GET /api/v1/groups/tree

返回值是分组对象数组,每个节点额外包含递归的 children 数组:

[
{
"id": 1,
"name": "核心机房",
"parent_id": null,
"path": "/1/",
"depth": 0,
"sort_order": 0,
"created_at": "2026-08-14T10:00:00",
"children": [
{
"id": 2,
"name": "接入区",
"parent_id": 1,
"path": "/1/2/",
"depth": 1,
"sort_order": 0,
"created_at": "2026-08-14T10:01:00",
"children": []
}
]
}
]

创建、更新和删除分组

创建:

POST /api/v1/groups
Content-Type: application/json
{
"name": "核心机房",
"parent_id": null
}

name 必填且不能与已有分组重复;parent_idnull 表示根分组。

更新:

PUT /api/v1/groups/{group_id}
Content-Type: application/json
{
"name": "核心机房-01",
"parent_id": 2
}

当前实现中,name 不提供时保持原值;parent_id 不提供时会按输入模型的默认值 null 处理,即将分组移动到根层级。若要保持原父分组,请显式传入原来的 parent_id

删除:

DELETE /api/v1/groups/{group_id}

成功响应为 { "status": "success" }。包含子分组或仍被设备使用的分组不能删除。

常见错误码:RESOURCE_GROUP_NAME_EXISTSRESOURCE_GROUP_NOT_FOUNDRESOURCE_GROUP_HAS_CHILDRENRESOURCE_GROUP_IN_USE

凭据

端点

方法路径权限说明
GET/api/v1/credentialscredentials.view分页查询凭据
GET/api/v1/credentials/{credential_id}credentials.view获取凭据详情
POST/api/v1/credentialscredentials.create创建凭据,返回 201
PUT/api/v1/credentials/{credential_id}credentials.update更新凭据
DELETE/api/v1/credentials/{credential_id}credentials.delete删除凭据

查询凭据

GET /api/v1/credentials?page=1&limit=50

凭据列表没有搜索或过滤参数。成功响应中的凭据对象只包含:

{
"id": 1,
"name": "只读网络设备账号",
"username": "backup-reader",
"remarks": "仅用于测试环境",
"created_at": "2026-08-14T10:00:00"
}

passwordenable_password 永远不会出现在 API 响应中。

创建和更新凭据

创建:

POST /api/v1/credentials
Content-Type: application/json
{
"name": "只读网络设备账号",
"username": "backup-reader",
"password": "replace-me",
"enable_password": null,
"remarks": "仅用于测试环境"
}

nameusername 必填,passwordenable_passwordremarks 可选。密码在服务端加密保存。

更新:

PUT /api/v1/credentials/{credential_id}
Content-Type: application/json
{
"username": "backup-reader-v2",
"password": "replace-me"
}

更新字段可选;未提供的字段保持原值。密码字段不会回显,也不要在请求日志、Issue 或自动化平台的公开输出中打印密码。

删除凭据

DELETE /api/v1/credentials/{credential_id}

凭据仍被设备使用时不能删除。常见错误码:RESOURCE_CREDENTIAL_NAME_EXISTSRESOURCE_CREDENTIAL_NOT_FOUNDRESOURCE_CREDENTIAL_IN_USE

备份命令模板

端点

方法路径权限说明
GET/api/v1/templatestemplates.view分页查询模板
GET/api/v1/templates/{template_id}templates.view获取模板详情
POST/api/v1/templatestemplates.create创建模板,返回 201
PUT/api/v1/templates/{template_id}templates.update更新模板
DELETE/api/v1/templates/{template_id}templates.delete删除模板

创建和更新模板

创建:

POST /api/v1/templates
Content-Type: application/json
{
"name": "Cisco IOS 默认备份",
"platform": "cisco_ios",
"commands": "show running-config"
}

nameplatform 必填,commands 可选。省略或提交空白命令时,系统会根据平台填充默认命令。

更新:

PUT /api/v1/templates/{template_id}
Content-Type: application/json
{
"commands": "show running-config\nshow startup-config"
}

未提供的字段保持原值;如果 commands 为空,则会按更新后的平台重新使用默认命令。模板响应字段为 idnameplatformcommandscreated_at

commands 是设备上实际执行的命令文本。请根据设备权限和平台要求验证命令,不要把具有修改或破坏性的命令放入备份模板。

删除模板

DELETE /api/v1/templates/{template_id}

成功响应为 { "status": "success" }。模板不存在时返回 RESOURCE_TEMPLATE_NOT_FOUND