integer/array template.get(object parameters)
该方法允许根据给定的参数检索模板。
这个方法所有用户类型都可以使用。在用户角色设置中可用撤销掉用该方法的权限。 查看 用户角色获取更多信息。
(object)
参数定义所需的输出。
该方法支持以下参数。
参数 | 类型 | 描述 |
---|---|---|
templateids | ID/数组 | 仅返回具有指定模板ID的模板。 |
groupids | ID/数组 | 仅返回属于指定模板组的模板。 |
parentTemplateids | ID/数组 | 仅返回链接到指定模板的模板。 |
hostids | ID/数组 | 仅返回链接到指定主机/模板的模板。 |
graphids | ID/数组 | 仅返回包含指定图表的模板。 |
itemids | ID/数组 | 仅返回包含指定监控项的模板。 |
triggerids | ID/数组 | 仅返回包含指定触发器的模板。 |
with_items | 标记 | 仅返回具有监控项的模板。 |
with_triggers | 标记 | 仅返回具有触发器的模板。 |
with_graphs | 标记 | 仅返回具有图表的模板。 |
with_httptests | 标记 | 仅返回具有网络场景的模板。 |
evaltype | 整数 | 标签搜索规则。 可能的值: 0 - (默认)与/或; 2 - 或。 |
tags | 对象/数组 | 仅返回具有指定标签的模板。根据操作符值,标签完全匹配或标签值大小写敏感/不敏感搜索。 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...] 。空数组返回所有模板。 可能的操作符值: 0 - (默认)包含; 1 - 等于; 2 - 不像; 3 - 不等于; 4 - 存在; 5 - 不存在。 |
selectTags | 查询 | 在[tags] 属性中返回模板标签。 |
selectHosts | 查询 | 在[hosts] 属性中返回链接到模板的主机。支持 count 。 |
selectTemplateGroups | 查询 | 在[templategroups] 属性中返回模板所属的模板组。 |
selectTemplates | 查询 | 在[templates] 属性中返回链接到给定模板的模板。支持 count 。 |
selectParentTemplates | 查询 | 在parentTemplates 属性中返回链接到给定模板的模板。支持 count 。 |
selectHttpTests | 查询 | 在[httpTests] 属性中返回模板中的网络场景。支持 count 。 |
selectItems | 查询 | 在[items] 属性中返回模板中的监控项。支持 count 。 |
selectDiscoveries | 查询 | 在discoveries 属性中返回模板中的低级发现。支持 count 。 |
selectTriggers | 查询 | 在[triggers] 属性中返回模板中的触发器。支持 count 。 |
selectGraphs | 查询 | 在[graphs] 属性中返回模板中的图表。支持 count 。 |
selectMacros | 查询 | 在macros 属性中返回模板中的宏。 |
selectDashboards | 查询 | 在[dashboards] 属性中返回模板中的仪表盘。支持 count 。 |
selectValueMaps | 查询 | 返回带有模板值映射的[valuemaps] 属性。 |
limitSelects | 整数 | 限制子选择返回的记录数。 适用于以下子选择: selectTemplates - 结果将按name 排序;selectHosts - 按host 排序;selectParentTemplates - 按host 排序;selectItems - 按name 排序;selectDiscoveries - 按name 排序;selectTriggers - 按description 排序;selectGraphs - 按name 排序;selectDashboards - 按name 排序。 |
sortfield | 字符串/数组 | 根据给定属性对结果进行排序。 可能的值: hostid ,host ,name ,status 。 |
countOutput | 布尔值 | 这些参数在参考说明中描述。 |
editable | 布尔值 | |
excludeSearch | 布尔值 | |
filter | 对象 | |
limit | 整数 | |
output | 查询 | |
preservekeys | 布尔值 | |
search | 对象 | |
searchByAny | 布尔值 | |
searchWildcardsEnabled | 布尔值 | |
sortorder | 字符串/数组 | |
startSearch | 布尔值 | |
selectGroups (已废弃) |
查询 | 此参数已废弃,请改用selectTemplateGroups 。在 [groups] 属性中返回模板所属的模板组。 |
(integer/array)
返回以下二选一:
countOutput
参数,则返回检索到的对象的数量。检索名为 "Linux" 和 "Windows" 的两个模板的所有数据。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Linux",
"Windows"
]
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"proxyid": "0",
"host": "Linux",
"status": "3",
"disable_until": "0",
"error": "",
"available": "0",
"errors_from": "0",
"lastaccess": "0",
"ipmi_authtype": "0",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"ipmi_disable_until": "0",
"ipmi_available": "0",
"snmp_disable_until": "0",
"snmp_available": "0",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"ipmi_errors_from": "0",
"snmp_errors_from": "0",
"ipmi_error": "",
"snmp_error": "",
"jmx_disable_until": "0",
"jmx_available": "0",
"jmx_errors_from": "0",
"jmx_error": "",
"name": "Linux",
"flags": "0",
"templateid": "10001",
"description": "",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": "",
"uuid": "282ffe33afc74cccaf1524d9aa9dc502"
},
{
"proxyid": "0",
"host": "Windows",
"status": "3",
"disable_until": "0",
"error": "",
"available": "0",
"errors_from": "0",
"lastaccess": "0",
"ipmi_authtype": "0",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"ipmi_disable_until": "0",
"ipmi_available": "0",
"snmp_disable_until": "0",
"snmp_available": "0",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"ipmi_errors_from": "0",
"snmp_errors_from": "0",
"ipmi_error": "",
"snmp_error": "",
"jmx_disable_until": "0",
"jmx_available": "0",
"jmx_errors_from": "0",
"jmx_error": "",
"name": "Windows",
"flags": "0",
"templateid": "10081",
"description": "",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": "",
"uuid": "522d17e1834049be879287b7c0518e5d"
}
],
"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": [
{
"hostid": "10402",
"tags": [
{
"tag": "host-name",
"value": "{HOST.NAME}"
}
]
}
],
"id": 1
}
CTemplate::get() 在 ui/include/classes/api/services/CTemplate.php.