item.get

Descripció

integer/array item.get(object parameters)

El mètode permet recuperar elements segons els paràmetres proveïts.

Aquest mètode és disponible per a usuaris de qualsevol mena. Els permisos per cridar al mètode es poden revocar a les configuracions de rols d'usuari. Per a més informació, veieu Rols d'usuari.

Paràmetres

(object) Paràmetres que defineixen la sortida esperada.

El mètode admet els paràmetres següents.

Paràmetre Tipus Descripció
itemids ID/array Retorna només els elements amb els identificadors donats.
groupids ID/array Retorna només els elements que pertanyen als equips dels grups donats.
templateids ID/array Retorna només els elements que pertanyen a les plantilles donades.
hostids ID/array Retorna només els elements que pertanyen als equips donats.
proxyids ID/array Retorna només els elements monitorats pels proxys donats.
interfaceids ID/array Retorna només elements que empren les interfícies d'equip donades.
graphids ID/array Retorna només els elements emprats en els gràfics donats.
triggerids ID/array Retorna només els elements emprats en els triggers donats.
webitems flag Inclou elements web al resultat.
inherited boolean Si s'estableix a true, només retorna els elements heretats d'un model.
templated boolean Si s'estableix a true, retorna només els elements que pertanyen a les plantilles.
monitored boolean Si s'estableix a true, només retorna els elements activats que pertanyen als equips monitorats.
group string Retorna només els elements que pertanyen a un grup amb el nom especificat.
host string Retorna només els elements que pertanyen a un equip amb el nom especificat.
evaltype integer Regles de cerca d'etiquetes.

Valors possibles:
0 - (per defecte) I/O;
2 - O.
tags array of objects Retorna només els elements amb les etiquetes donades. Concordança exacta per lectura de btag i cerca que distingeix entre majúscules i minúscules o no distingeix entre majúscules i minúscules pel valor de l'etiqueta en funció del valor de l'operador.
Format: [{"tag": "<etiqueta>", "valor": " <valor>", " operador": "<operador>"}, ...].
Una matriu buida retorna tots els elements.

Tipus d'operadors possibles:
0 - (per defecte) És com;
1 - Igual;
2 - No és com;
3 - No és igual
4 - Existeix;
5 - No existeix.
with_triggers boolean Si s'estableix a true, només retorna els elements emprats als triggers.
selectHosts query Retorna una propietat hosts que conté una matriu d'equips a què pertany l'element.
selectInterfaces query Retorna una propietat interfaces que conté una matriu d'interfícies d'equip emprades per l'element.
selectTriggers query Retorna una propietat triggers que conté els triggers que empra aquest element.

Admet count.
selectGraphs query Retorna una propietat graphs que conté els gràfics que empra l'element.

Admet count.
selectDiscoveryRule query Retorna una propietat discoveryRule que conté la regla de descoberta de baix nivell que va crear l'element.
selectItemDiscovery query Retorna l'objecte de descoberta d'elements a la propietat itemDiscovery. L'objecte de descoberta d'elements enllaça l'element a un prototip d'element des del qual s'ha creat.

Té les propietats següents:
itemdiscoveryid - (string) Identificador de descoberta de l'element;
itemid - (string) Identificació de l'element descobert ;
parent_itemid - (string) Identificador del prototip d'element des del qual s'ha creat l'element;
key_ - (cadena) clau del prototip de l'element;< br>lastcheck - (timestamp) quan l'element es va descobrir per última vegada;
status - (int) estat de la descoberta de l'element:
0 - (per defecte) s'ha trobat l'element,
1 - l'element ja no es troba;
ts_delete - (timestamp) quan s'esborrarà un element que ja no es troba;
ts_disable - (timestamp) quan es deshabilitarà un element que ja no es troba;
disable_source - (int) indicador sobre si l'element s'ha deshabilitat per una regla LLD o manualment:
0 - (per defecte) es desactiva automàticament,
1 - es desactiva per una regla LLD.
selectPreprocessing query Retorna una propietat preprocessing que conté opcions de preprocessament d'elements.
selectTags query Retorna etiquetes d'element a la propietat tags.
selectValueMap query Retorna una propietat valuemap que conté el mapa de valors de l'element.
filter object Només retorna resultats que coincideixen exactament amb el filtre donat.

Accepta una matriu on les claus són noms de propietat i els valors són un valor únic o una matriu de valors per comparar.< br>
Admet filtres addicionals:
host - Nom tècnic de l'equip al qual pertany l'element.
limitSelects integer Limita el nombre de registres retornats per les subconsultes.

S'aplica a les subconsultes següents:
selectGraphs - els resultats s'ordenaran per name;< br>selectTriggers - resultats s'ordenarà per description.
sortfield string/array Ordena el resultat per les propietats donades.

Els valors possibles són: itemid, name, key_, delay, history, trends , type i status.
countOutput boolean Aquests paràmetres, comuns a tots els mètodes get, es descriuen als comentaris de referència.
editable boolean
excludeSearch boolean
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

Valors de retorn

(integer/array) Retorna un d'entre:

  • una taula d'objectes;
  • el recompte d'objectes recuperats, si s'empra el paràmetre countOutput.

Exemples

Cercar elements per una clau

Recupera tots els elements emprats amb l'ID d'equip específics que contenen el mot "system.cpu" a la clau d'element, i ordenar els resultats per nom.

Petició:

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": "extend",
               "hostids": "10084",
               "with_triggers": true,
               "search": {
                   "key_": "system.cpu"
               },
               "sortfield": "name"
           },
           "id": 1
       }

Resposta:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "42269",
                   "type": "18",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "CPU utilization",
                   "key_": "system.cpu.util",
                   "delay": "0",
                   "history": "7d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "0",
                   "trapper_hosts": "",
                   "units": "%",
                   "logtimefmt": "",
                   "templateid": "42267",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "CPU utilization in %.",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "42264",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "CPU utilization"
               },
               {
                   "itemid": "42259",
                   "type": "0",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "Load average (15m avg)",
                   "key_": "system.cpu.load[all,avg15]",
                   "delay": "1m",
                   "history": "7d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "0",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "42219",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "Load average (15m avg)"
               },
               {
                   "itemid": "42249",
                   "type": "0",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "Load average (1m avg)",
                   "key_": "system.cpu.load[all,avg1]",
                   "delay": "1m",
                   "history": "7d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "0",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "42209",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "Load average (1m avg)"
               },
               {
                   "itemid": "42257",
                   "type": "0",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "Load average (5m avg)",
                   "key_": "system.cpu.load[all,avg5]",
                   "delay": "1m",
                   "history": "7d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "0",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "42217",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "Load average (5m avg)"
               },
               {
                   "itemid": "42260",
                   "type": "0",
                   "snmp_oid": "",
                   "hostid": "10084",
                   "name": "Number of CPUs",
                   "key_": "system.cpu.num",
                   "delay": "1m",
                   "history": "7d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "3",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "42220",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "1",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "Number of CPUs"
               }
           ],
           "id": 1
       }

Cercar elements dependents, per clau

Recupera tots els elements dependents de l'equip amb ID "10116" donada una clau que conté el nom "apache".

Petició:

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": "extend",
               "hostids": "10116",
               "search": {
                   "key_": "apache"
               },
               "filter": {
                   "type": 18
               }
           },
           "id": 1
       }

ResposTA:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "25550",
                   "type": "18",
                   "snmp_oid": "",
                   "hostid": "10116",
                   "name": "Days",
                   "key_": "apache.status.uptime.days",
                   "delay": "0",
                   "history": "90d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "3",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "25545",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "Days"
               },
               {
                   "itemid": "25555",
                   "type": "18",
                   "snmp_oid": "",
                   "hostid": "10116",
                   "name": "Hours",
                   "key_": "apache.status.uptime.hours",
                   "delay": "0",
                   "history": "90d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "3",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "25545",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "0",
                   "prevvalue": "0",
                   "name_resolved": "Hours"
               }
           ],
           "id": 1
       }

Trobar un element d'agent HTTP

Troba un element d'agent HTTP amb el tipus de cos XML per a un ID d'equip donat.

Petició:

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "hostids": "10255",
               "filter": {
                   "type": 19,
                   "post_type": 3
               }
           },
           "id": 1
       }

Resposta:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "28252",
                   "type": "19",
                   "snmp_oid": "",
                   "hostid": "10255",
                   "name": "template item",
                   "key_": "ti",
                   "delay": "30s",
                   "history": "90d",
                   "trends": "365d",
                   "status": "0",
                   "value_type": "3",
                   "trapper_hosts": "",
                   "units": "",
                   "logtimefmt": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "flags": "0",
                   "interfaceid": "0",
                   "description": "",
                   "inventory_link": "0",
                   "evaltype": "0",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "localhost",
                   "query_fields": [
                       {
                           "name": "mode",
                           "value": "xml"
                       }
                   ],
                   "posts": "<body>\r\n<![CDATA[{$MACRO}<foo></bar>]]>\r\n</body>",
                   "status_codes": "200",
                   "follow_redirects": "0",
                   "post_type": "3",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "1",
                   "request_method": "3",
                   "output_format": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "state": "0",
                   "error": "",
                   "parameters": [],
                   "lastclock": "0",
                   "lastns": "0",
                   "lastvalue": "",
                   "prevvalue": "",
                   "name_resolved": "template item"
               }
           ],
           "id": 1
       }

Cercar elements amb regles de pretractament

Recuperar tots els elements i les seves regles de pretractament per un ID d'equip específic.

Petició:

{
           "jsonrpc": "2.0",
           "method": "item.get",
           "params": {
               "output": ["itemid", "name", "key_"],
               "selectPreprocessing": "extend",
               "hostids": "10254"
           },
           "id": 1
       }

Resposta:

{
           "jsonrpc": "2.0",
           "result": {
               "itemid": "23865",
               "name": "HTTP agent example JSON",
               "key_": "json",
               "preprocessing": [
                   {
                       "type": "12",
                       "params": "$.random",
                       "error_handler": "1",
                       "error_handler_params": ""
                   }
               ]
           },
           "id": 1
       }

Veieu també

Font

CItem::get() in ui/include/classes/api/services/CItem.php.