template.get
Descrizione
integer/array template.get(object parameters)
Il metodo consente di recuperare i template in base ai parametri specificati.
Questo metodo è disponibile per utenti di qualsiasi tipo. Le autorizzazioni per chiamare il metodo possono essere revocate nelle impostazioni dei ruoli utente. Per ulteriori informazioni, vedere User roles.
Parametri
(object) Parametri che definiscono l'output desiderato.
Il metodo supporta i seguenti parametri.
| Parameter | Type | Description |
|---|---|---|
| templateids | ID/array | Restituisce solo i template con i template ID specificati. |
| groupids | ID/array | Restituisce solo i template che appartengono ai gruppi di template specificati. |
| parentTemplateids | ID/array | Restituisce solo i template a cui il template specificato è collegato. |
| hostids | ID/array | Restituisce solo i template collegati agli host/template specificati. |
| graphids | ID/array | Restituisce solo i template che contengono i grafici specificati. |
| itemids | ID/array | Restituisce solo i template che contengono gli item specificati. |
| triggerids | ID/array | Restituisce solo i template che contengono i trigger specificati. |
| with_items | flag | Restituisce solo i template che hanno item. |
| with_triggers | flag | Restituisce solo i template che hanno trigger. |
| with_graphs | flag | Restituisce solo i template che hanno grafici. |
| with_httptests | flag | Restituisce solo i template che hanno scenari web. |
| evaltype | integer | Metodo di valutazione dei tag. Valori possibili: 0 - (predefinito) And/Or; 2 - Or. |
| tags | object/array | Restituisce solo i template con i tag specificati. Formato: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...].Un array vuoto restituisce tutti i template. Valori possibili per operator: 0 - (predefinito) Contiene; 1 - Uguale a; 2 - Non contiene; 3 - Diverso da; 4 - Esiste; 5 - Non esiste. |
| selectTags | query | Restituisce i tag del template nella proprietà tags. |
| selectHosts | query | Restituisce gli host collegati al template nella proprietà hosts.Supporta count. |
| selectTemplateGroups | query | Restituisce i gruppi di template a cui il template appartiene nella proprietà templategroups. |
| selectTemplates | query | Restituisce i template a cui il template specificato è collegato nella proprietà templates.Supporta count. |
| selectParentTemplates | query | Restituisce i template collegati al template specificato nella proprietà parentTemplates.Supporta count. |
| selectHttpTests | query | Restituisce gli scenari web dal template nella proprietà httpTests.Supporta count. |
| selectItems | query | Restituisce gli item dal template nella proprietà items.Supporta count. |
| selectDiscoveries | query | Restituisce le low-level discovery dal template nella proprietà discoveries.Supporta count. |
| selectTriggers | query | Restituisce i trigger dal template nella proprietà triggers.Supporta count. |
| selectGraphs | query | Restituisce i grafici dal template nella proprietà graphs.Supporta count. |
| selectMacros | query | Restituisce le macro dal template nella proprietà macros. |
| selectDashboards | query | Restituisce i dashboard dal template nella proprietà dashboards.Supporta count. |
| selectValueMaps | query | Restituisce una proprietà valuemaps con le value map del template. |
| limitSelects | integer | Limita il numero di record restituiti dalle sotto-selezioni. Si applica alle seguenti sotto-selezioni: selectTemplates - i risultati saranno ordinati per name;selectHosts - ordinati per host;selectParentTemplates - ordinati per host;selectItems - ordinati per name;selectDiscoveries - ordinati per name;selectTriggers - ordinati per description;selectGraphs - ordinati per name;selectDashboards - ordinati per name. |
| sortfield | string/array | Ordina il risultato in base alle proprietà specificate. Valori possibili: hostid, host, name, status. |
| countOutput | boolean | Questi parametri sono descritti nel commento di riferimento. |
| editable | boolean | |
| excludeSearch | boolean | |
| filter | object | |
| limit | integer | |
| output | query | |
| preservekeys | boolean | |
| search | object | |
| searchByAny | boolean | |
| searchWildcardsEnabled | boolean | |
| sortorder | string/array | |
| startSearch | boolean | |
| selectGroups (deprecated) |
query | Questo parametro è deprecato, usare invece selectTemplateGroups.Restituisce i gruppi di template a cui il template appartiene nella proprietà groups. |
Valori restituiti
(integer/array) Restituisce uno dei seguenti:
- un array di oggetti;
- il numero di oggetti recuperati, se è stato utilizzato il parametro
countOutput.
Esempi
Recupero dei template per nome
Recupera tutti i dati relativi a due template denominati "Linux" e "Windows".
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Linux",
"Windows"
]
}
},
"id": 1
}
Risposta:
{
"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
}
Recupero dei gruppi di template
Recupera i gruppi di template di cui il template "Linux by Zabbix agent" è membro.
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": ["hostid"],
"selectTemplateGroups": "extend",
"filter": {
"host": [
"Linux by Zabbix agent"
]
}
},
"id": 1
}
Risposta:
{
"jsonrpc": "2.0",
"result": [
{
"templateid": "10001",
"templategroups": [
{
"groupid": "10",
"name": "Templates/Operating systems",
"uuid": "846977d1dfed4968bc5f8bdb363285bc"
}
]
}
],
"id": 1
}
Recupero degli host per template
Recupera gli host a cui è collegato il template "10001" (Linux by Zabbix agent).
{
"jsonrpc": "2.0",
"method": "template.get",
"params": {
"output": "templateid",
"templateids": "10001",
"selectHosts": ["hostid", "name"]
},
"id": 1
}
Risposta:
{
"jsonrpc": "2.0",
"result": [
{
"templateid": "10001",
"hosts": [
{
"hostid": "10084",
"name": "Zabbix server"
},
{
"hostid": "10603",
"name": "Host 1"
},
{
"hostid": "10604",
"name": "Host 2"
}
]
}
],
"id": 1
}
Ricerca per tag del template
Recupera i template che hanno il tag "host-name" uguale a "{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
}
Risposta:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10402",
"tags": [
{
"tag": "host-name",
"value": "{HOST.NAME}"
}
]
}
],
"id": 1
}
Vedi anche
Fonte
CTemplate::get() in ui/include/classes/api/services/CTemplate.php.