template.get

Description说明

integer/array template.get(object parameters)

The method allows to retrieve templates according to the given parameters该方法允许根据指定的参数检索模板.

Parameters参数

(object) Parameters defining the desired output定义所需输出的参数.

The method supports the following parameters该方法支持以下参数.

Parameter参数 T pe类型 Des ription说明
templateids string/array Return only templates with the given template IDs只返回具有给定模板ID的模板.
groupids string/array Return only templates that belong to the given host groups只返回所属指定的主机组的模板.
parentTemplateids string/array Return only templates that are children of the given templates只返回作为指定模板的子项的模板.
hostids string/array Return only templates that are linked to the given hosts只返回链接到指定主机的模板.
graphids string/array Return only templates that contain the given graphs只返回包含指定图形的模板.
itemids string/array Return only templates that contain the given items只返回包含指定监控项的模板.
triggerids string/array Return only templates that contain the given triggers只返回包含指定触发器的模板.
with_items flag Return only templates that have items只返回具有监控项的模板.
with_triggers flag Return only templates that have triggers只返回具有触发器的模板.
with_graphs flag Return only templates that have graphs只返回具有图形的模板.
with_httptests flag Return only templates that have web scenarios只返回具有Web场景的模板.
selectGroups query Return the host groups that the template belongs to in the groups property在groups属性中返回模板所属的主机组.
selectHosts query Return the hosts that are linked to the template in the hosts property在hosts属性中返回链接到模板的主机.

Supports count.
selectTemplates query Return the child templates in the templates property返回templates属性中的子模板.

Supports count.
selectParentTemplates query Return the parent templates in the parentTemplates property返回parentTemplates属性中的父模板.

Supports count.
selectHttpTests query Return the web scenarios from the template in the httpSteps property从httpSteps属性中的模板返回Web场景.

Supports count.
selectItems query Return items from the template in the items property在items属性中返回模板中的监控项.

Supports count.
selectDiscoveries query Return low-level discoveries from the template in the discoveries property从discoveries属性中的模板返回低水平自动发现.

Supports count.
selectTriggers query Return triggers from the template in the triggers property从''triggers'属性中的模板返回触发器.

Supports count.
selectGraphs query Return graphs from the template in the graphs property从graphs属性中的模板返回图形.

Supports count.
selectApplications query Return applications from the template in the applications property从applications属性中的模板返回应用集.

Supports count.
selectMacros query Return the macros from the template in the macros property在macros属性中返回模板中的宏.
selectScreens query Return screens from the template in the screens property从screens属性中的模板返回聚合图形.

Supports count.
limitSelects integer Limits the number of records returned by subselects限制子选择返回的记录数.

Applies to the following subselects:
selectTemplates - results will be sorted by name;
selectHosts - sorted by host;
selectParentTemplates - sorted by host;
selectItems - sorted by name;
selectDiscoveries - sorted by name;
selectTriggers - sorted by description;
selectGraphs - sorted by name;
selectApplications - sorted by name;
selectScreens - sorted by name.
sortfield string/array Sort the result by the given properties.

Possible values are: hostid, host, name, status.
countOutput flag These parameters being common for all get methods are described in detail in the reference commentary.
editable boolean
excludeSearch flag
filter object
limit integer
output query
preservekeys flag
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch flag

Return values返回值

(integer/array) Returns either返回两者其中任一:

  • an array of objects一组对象;
  • the count of retrieved objects, if the countOutput parameter has been used如果已经使用了countOutput参数,则检索对象的计数.

Examples范例

Retrieving templates by name按名称检索模板

Retrieve all data about two templates named "Template OS Linux" and "Template OS Windows". 检索有关名为"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
       }

See also参考

Source来源

CTemplate::get() in frontends/php/include/classes/api/services/CTemplate.php.