integer/array template.get(object parameters)
The method allows to retrieve templates according to the given parameters. 此方法允许根据指定的参数检索模板。
(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 - (default) And/Or; 2 - Or. |
| tags | array/object | 仅返回具有给定标签的模板。 按标记进行精确匹配,并根据运算符的值按标记值进行区分大小写或不区分大小写的搜索。 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]空数组将返回所有模板。 可能的运算符值: 0 - (default) Contains; 1 - Equals. |
| selectGroups | query | 从groups属性中返回所属模板的主机组。 |
| selectTags | query | 在tags属性中返回模板标签。 |
| 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。 |
| selectApplications | query | 从applications属性中返回来自模板的应用。支持 count。 |
| selectMacros | query | 从macros属性中返回来自模板的宏。 |
| selectScreens | query | 从screens属性中返回来自模板的聚合图形。支持 count。 |
| limitSelects | integer | 限制子查询返回的记录数。 应用于以下子查询: selectTemplates - 结果将以name排序;selectHosts - 以host排序;selectParentTemplates - 以host排序;selectItems - 以name排序;selectDiscoveries - 以name排序;selectTriggers - 以description排序;selectGraphs - 以name排序;selectApplications - 以name排序;selectScreens - 以name排序; |
| sortfield | string/array | 根据给定的属性为结果排序。 许可值为: hostid,host,name,status。 |
| countOutput | boolean | 这些参数十分普遍,适用所有get方法,详情参见reference commentary。 |
| 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参数,则检索对象的计数。检索名称为"Template OS Linux"和"Template OS Windows"这两个模板的所有数据。 Request 请求:
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Template OS Linux",
"Template OS Windows"
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}Response 响应:
{
"jsonrpc": "2.0",
"result": [
{
"proxy_hostid": "0",
"host": "Template OS 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": "Template OS Linux",
"flags": "0",
"templateid": "10001",
"description": "",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": ""
},
{
"proxy_hostid": "0",
"host": "Template OS 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": "Template OS Windows",
"flags": "0",
"templateid": "10081",
"description": "",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"tls_psk_identity": "",
"tls_psk": ""
}
],
"id": 1
}检索标记为“Host name”等于“ {HOST.NAME}”的模板。
Request 请求:
{
"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
}Response 响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10402",
"tags": [
{
"tag": "Host name",
"value": "{HOST.NAME}"
}
]
}
],
"id": 1
}CTemplate::get()方法可在ui/include/classes/api/services/CTemplate.php中参考。