获取
描述
integer/array template.get(object parameters)
该方法允许根据给定参数检索模板。
此方法可供任何类型的用户使用。 调用该方法的权限可在用户角色设置中撤销。 更多信息请参见 用户角色。
参数
(object) 定义所需输出的参数。
该方法支持以下参数。
| 参数 | 类型 | 说明 |
|---|---|---|
| templateids | ID/array | 仅返回具有给定模板 ID 的模板。 |
| groupids | ID/array | 仅返回属于给定模板组的模板。 |
| parentTemplateids | ID/array | 仅返回给定模板所链接到的模板。 |
| hostids | ID/array | 仅返回链接到给定主机/模板的模板。 |
| graphids | ID/array | 仅返回包含给定图形的模板。 |
| itemids | ID/array | 仅返回包含给定监控项的模板。 |
| triggerids | ID/array | 仅返回包含给定触发器的模板。 |
| with_items | flag | 仅返回具有监控项的模板。 |
| with_triggers | flag | 仅返回具有触发器的模板。 |
| with_graphs | flag | 仅返回具有图形的模板。 |
| with_httptests | flag | 仅返回具有 Web 场景的模板。 |
| evaltype | integer | 标签评估方法。 可选值: 0 - (默认) And/Or; 2 - Or。 |
| tags | object/array | 仅返回具有给定标签的模板。 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]。空数组将返回所有模板。 可选的operator值: 0 - (默认) Contains; 1 - Equals; 2 - Does not contain; 3 - Does not equal; 4 - Exists; 5 - Does not exist。 |
| inheritedTags | boolean | 返回在链接模板中也具有给定 tags 的模板。可选值: true - 链接模板也必须具有给定标签;false - (默认) 忽略来自链接模板的标签。 |
| selectInheritedTags | query | 返回 inheritedTags 属性,其中包含链接模板上的标签。 |
| selectTags | query | 在 tags 属性中返回模板标签。 |
| selectDiscoveryRules | query | 返回 discoveryRules 属性,其中包含模板 LLD 规则。支持 count。 |
| selectHosts | query | 在 hosts 属性中返回链接到该模板的主机。支持 count。 |
| selectTemplateGroups | query | 在 templategroups 属性中返回该模板所属的模板组。 |
| selectTemplates | query | 在 templates 属性中返回给定模板所链接到的模板。支持 count。 |
| selectParentTemplates | query | 在 parentTemplates 属性中返回链接到给定模板的模板。支持 count。 |
| selectHttpTests | query | 在 httpTests 属性中返回模板中的 Web 场景。支持 count。 |
| selectItems | query | 在 items 属性中返回模板中的监控项。支持 count。 |
| selectTriggers | query | 在 triggers 属性中返回模板中的触发器。支持 count。 |
| selectGraphs | query | 在 graphs 属性中返回模板中的图形。支持 count。 |
| selectMacros | query | 在 macros 属性中返回模板中的宏。 |
| selectDashboards | query | 在 dashboards 属性中返回模板中的仪表板。支持 count。 |
| selectValueMaps | query | 返回 valuemaps 属性,其中包含模板值映射。 |
| limitSelects | integer | 限制子选择返回的记录数。 适用于以下子选择: selectTemplates - 结果将按 name 排序;selectHosts - 按 host 排序;selectParentTemplates - 按 host 排序;selectItems - 按 name 排序;selectDiscoveryRules - 按 name 排序;selectTriggers - 按 description 排序;selectGraphs - 按 name 排序;selectDashboards - 按 name 排序。 |
| sortfield | string/array | 按给定属性对结果进行排序。 可选值: hostid、host、name、status。 |
| countOutput | boolean | 这些参数在参考说明中进行了描述。 |
| editable | boolean | |
| excludeSearch | boolean | |
| filter | object | |
| limit | integer | |
| output | query | |
| preservekeys | boolean | |
| search | object | |
| searchByAny | boolean | |
| searchWildcardsEnabled | boolean | |
| sortorder | string/array | |
| startSearch | boolean | |
| selectDiscoveries | query | 在 discoveries 属性中返回模板中的低级别发现。支持 count。此查询已弃用,请改用 selectDiscoveryRules。 |
返回值
(integer/array) 返回以下之一:
- 对象数组;
- 如果使用了
countOutput参数,则返回已检索对象的数量。
示例
按名称检索模板
检索名为“Linux by Zabbix agent”和“Windows by Zabbix agent”的两个模板的所有数据。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Linux by Zabbix agent",
"Windows by Zabbix agent"
]
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"proxyid": "0",
"host": "Linux by Zabbix agent",
"status": "3",
"ipmi_authtype": "-1",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"name": "Linux by Zabbix agent",
"flags": "0",
"templateid": "10001",
"description": "这是一个官方 Linux 模板。它需要 Zabbix agent 8.0 或更高版本。\r\n\r\n有关文件系统(FS)发现的说明:\r\n- ext4/3/2 文件系统会为特权用途保留空间,默认通常设置为 5%。\r\n- BTRFS 默认会为自身需求分配卷空间的 10%。\r\n- 为降低潜在灾难风险,FS 使用情况触发器基于最大可用空间。\r\n - 利用率公式:'pused = 100 - 100 * (available / total - free + available)'\r\n- FS 利用率图表源自图形原型,它将 FS 保留空间表示为总卷容量中已用空间与可用空间之间的差值。\r\n\r\n您可以在我们的论坛中讨论此模板或留下反馈:https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/387225-discussion-thread-for-official-zabbix-template-for-linux\r\n\r\n由官方 Zabbix 模板工具 \"Templator\" 生成",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": "",
"custom_interfaces": "0",
"uuid": "f8f7908280354f2abeed07dc788c3747",
"vendor_name": "Zabbix",
"vendor_version": "8.0-2",
"proxy_groupid": "0",
"monitored_by": "0",
"wizard_ready": "1",
"readme": "## 概述\r\n\r\n这是一个官方 Linux 模板。它需要 Zabbix agent 8.0 或更高版本。\r\n\r\n#### 有关文件系统(FS)发现的说明:\r\n- ext4/3/2 FS 会为特权用途保留空间,默认通常设置为 5%。\r\n- BTRFS 默认会为自身需求分配卷空间的 10%。\r\n- 为降低潜在灾难风险,FS 使用情况触发器基于最大可用空间。\r\n - 利用率公式:`pused = 100 - 100 * (available / total - free + available)`\r\n- FS 利用率图表源自图形原型,它将 FS 保留空间表示为总卷容量中已用空间与可用空间之间的差值。"
},
{
"proxyid": "0",
"host": "Windows by Zabbix agent",
"status": "3",
"ipmi_authtype": "-1",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"name": "Windows by Zabbix agent",
"flags": "0",
"templateid": "10081",
"description": "这是一个官方 Windows 模板。它需要 Zabbix agent 8.0 或更高版本。\r\n\r\n您可以在我们的论坛中讨论此模板或留下反馈:https://www.zabbix.com/forum/zabbix-suggestions-and-feedback/387224-discussion-thread-for-official-zabbix-template-for-windows\r\n\r\n由官方 Zabbix 模板工具 \"Templator\" 生成",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": "",
"custom_interfaces": "0",
"uuid": "13b06904a6bf41cbb795e3193d896340",
"vendor_name": "Zabbix",
"vendor_version": "8.0-2",
"proxy_groupid": "0",
"monitored_by": "0",
"wizard_ready": "1",
"readme": "## 概述\r\n\r\n这是一个官方 Windows 模板。它需要 Zabbix agent 8.0 或更高版本。"
}
],
"id": 1
}
检索模板组
检索模板 "Linux by Zabbix agent" 所属的模板组。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": ["hostid"],
"selectTemplateGroups": "extend",
"filter": {
"host": [
"Linux by Zabbix agent"
]
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"templateid": "10001",
"templategroups": [
{
"groupid": "10",
"name": "Templates/Operating systems",
"uuid": "846977d1dfed4968bc5f8bdb363285bc"
}
]
}
],
"id": 1
}
按模板检索主机
检索已链接到 "10001"(即 Linux by Zabbix agent)模板的主机。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "templateid",
"templateids": "10001",
"selectHosts": ["hostid", "name"]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"templateid": "10001",
"hosts": [
{
"hostid": "10084",
"name": "Zabbix server"
},
{
"hostid": "10603",
"name": "Host 1"
},
{
"hostid": "10604",
"name": "Host 2"
}
]
}
],
"id": 1
}
按模板标签搜索
检索具有标签“host-name”且其值等于“{HOST.NAME}”的模板。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": ["hostid"],
"selectTags": "extend",
"evaltype": 0,
"tags": [
{
"tag": "host-name",
"value": "{HOST.NAME}",
"operator": 1
}
]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"templateid": "10402",
"tags": [
{
"tag": "host-name",
"value": "{HOST.NAME}"
}
]
}
],
"id": 1
}
另请参见
来源
CTemplate::get() 在 ui/include/classes/api/services/CTemplate.php.