integer/array template.get(object parameters)
该方法允许根据给定参数检索模板。
此方法可供任何类型的用户使用。调用该方法的权限可以在用户角色设置中撤销。更多信息请参阅User roles。
(object)
定义输出结果的参数
该方法支持以下参数
参数 | 数据类型 | 描述 |
---|---|---|
templateids | string/array | 仅返回具有指定模板ID的模板 |
groupids | string/array | 仅返回属于指定主机组的模板 |
parentTemplateids | string/array | 仅返回作为指定模板父级的模板 |
hostids | string/array | 仅返回链接到指定主机/模板的模板 |
graphids | string/array | 仅返回包含指定图形的模板 |
itemids | string/array | 仅返回包含指定监控项的模板 |
triggerids | string/array | 仅返回包含指定触发器的模板 |
with_items | flag | 仅返回具有监控项的模板 |
with_triggers | flag | 仅返回具有触发器的模板 |
with_graphs | flag | 仅返回具有图形的模板 |
with_httptests | flag | 仅返回具有Web场景的模板 |
evaltype | integer | 标签搜索规则 可能值: 0 - (默认) 与/或; 2 - 或 |
tags | object/array | 仅返回具有指定标签的模板。根据运算符值对标签值进行精确匹配或大小写敏感/不敏感搜索 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...] 空array返回所有模板 运算符可能值: 0 - (默认) 包含; 1 - 等于; 2 - 不包含; 3 - 不等于 4 - 存在; 5 - 不存在 |
selectGroups | query | 在groups属性中返回模板所属的主机组 |
selectTags | query | 在模板标签属性中返回模板标签 |
selectHosts | query | 在hosts属性中返回链接到模板的主机 支持 count |
selectTemplates | query | 在templates 属性中返回模板作为子级的父模板支持 count |
selectParentTemplates | query | 在parentTemplates 属性中返回模板作为父级的子模板支持 count |
selectHttpTests | query | 在httpTests属性中返回模板的Web场景 支持 count |
selectItems | query | 在items属性中返回模板的监控项 支持 count |
selectDiscoveries | query | 在discoveries 属性中返回模板的低级发现规则支持 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 排序;selectDiscoveries - 按name 排序;selectTriggers - 按description 排序;selectGraphs - 按name 排序;selectDashboards - 按name 排序 |
sortfield | string/array | 按指定属性排序结果 可能值为: hostid , host , name , status |
countOutput | boolean | 这些参数在通用get方法参数中描述 |
editable | boolean | |
excludeSearch | boolean | |
filter | object | |
limit | integer | |
output | query | |
preservekeys | boolean | |
search | object | |
searchByAny | boolean | |
searchWildcardsEnabled | boolean | |
sortorder | string/array | |
startSearch | boolean |
(integer/array)
返回以下两种结果之一:
countOutput
参数,则返回检索到的objects数量。获取名为"Linux"和"Windows"的两个模板的所有数据。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Linux",
"Windows"
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"proxy_hostid": "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"
},
{
"proxy_hostid": "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
}
获取已关联"10001"(由Zabbix agent提供的Linux)模板的主机。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "templateid",
"templateids": "10001",
"selectHosts": ["hostid", "name"]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"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
}
检索标签"主机名称"等于"{主机.NAME}"的模板。
请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": ["hostid"],
"selectTags": "extend",
"evaltype": 0,
"tags": [
{
"tag": "Host name",
"value": "{HOST.NAME}",
"operator": 1
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"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 文件中。