host.get

Descrizione

integer/array host.get(object parameters)

Il metodo consente di recuperare gli host in base ai parametri specificati.

Questo metodo è disponibile per utenti di qualsiasi tipo. I permessi per chiamare il metodo possono essere revocati nelle impostazioni dei ruoli utente. Consultare Ruoli utente per ulteriori informazioni.

Parametri

(object) Parametri che definiscono l'output desiderato.

Il metodo supporta i seguenti parametri.

Parameter Type Description
groupids ID/array Restituisce solo gli host che appartengono ai gruppi specificati.
dserviceids ID/array Restituisce solo gli host correlati ai servizi rilevati specificati.
graphids ID/array Restituisce solo gli host che hanno i grafici specificati.
hostids ID/array Restituisce solo gli host con gli ID host specificati.
httptestids ID/array Restituisce solo gli host che hanno i controlli web specificati.
interfaceids ID/array Restituisce solo gli host che usano le interfacce specificate.
itemids ID/array Restituisce solo gli host che hanno gli item specificati.
maintenanceids ID/array Restituisce solo gli host interessati dalle manutenzioni specificate.
monitored_hosts flag Restituisce solo gli host monitorati.
proxyids ID/array Restituisce solo gli host monitorati dai proxy specificati.
proxy_groupids ID/array Restituisce solo gli host monitorati dai gruppi di proxy specificati.
templated_hosts flag Restituisce sia gli host sia i template.
templateids ID/array Restituisce solo gli host collegati ai template specificati.
triggerids ID/array Restituisce solo gli host che hanno i trigger specificati.
with_items flag Restituisce solo gli host che hanno item.

Sovrascrive i parametri with_monitored_items e with_simple_graph_items.
with_item_prototypes flag Restituisce solo gli host che hanno prototipi di item.

Sovrascrive il parametro with_simple_graph_item_prototypes.
with_simple_graph_item_prototypes flag Restituisce solo gli host che hanno prototipi di item, abilitati per la creazione e con tipo di informazione numerico.
with_graphs flag Restituisce solo gli host che hanno grafici.
with_graph_prototypes flag Restituisce solo gli host che hanno prototipi di grafico.
with_httptests flag Restituisce solo gli host che hanno controlli web.

Sovrascrive il parametro with_monitored_httptests.
with_monitored_httptests flag Restituisce solo gli host che hanno controlli web abilitati.
with_monitored_items flag Restituisce solo gli host che hanno item abilitati.

Sovrascrive il parametro with_simple_graph_items.
with_monitored_triggers flag Restituisce solo gli host che hanno trigger abilitati. Tutti gli item usati nel trigger devono essere anch'essi abilitati.
with_simple_graph_items flag Restituisce solo gli host che hanno item con tipo di informazione numerico.
with_triggers flag Restituisce solo gli host che hanno trigger.

Sovrascrive il parametro with_monitored_triggers.
withProblemsSuppressed boolean Se impostato su true, restituisce solo gli host con problemi soppressi.
evaltype integer Metodo di valutazione dei tag.

Valori possibili:
0 - (predefinito) And/Or;
2 - Or.
severities integer/array Restituisce gli host che hanno solo problemi con le severità specificate. Si applica solo se l'oggetto problem è trigger.
tags object/array Restituisce solo gli host con i tag specificati.
Formato: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...].
Un array vuoto restituisce tutti gli host.

Valori possibili per operator:
0 - (predefinito) Contains;
1 - Equals;
2 - Does not contain;
3 - Does not equal;
4 - Exists;
5 - Does not exist.
inheritedTags boolean Restituisce gli host che hanno i tag specificati anche in tutti i template collegati.

Valori possibili:
true - i template collegati devono avere anche i tag specificati;
false - (predefinito) i tag dei template collegati vengono ignorati.
selectDiscoveries query Restituisce una proprietà discoveries con le regole di discovery low-level dell'host.

Supporta count.
selectDiscoveryRule query Restituisce una proprietà discoveryRule con la regola di discovery low-level che ha creato l'host (da host prototype nel monitoraggio VMware).
selectGraphs query Restituisce una proprietà graphs con i grafici dell'host.

Supporta count.
selectHostDiscovery query Restituisce una proprietà hostDiscovery con i dati dell'oggetto di discovery dell'host.

L'oggetto di discovery dell'host collega un host rilevato a un host prototype oppure un host prototype a una regola LLD e ha le seguenti proprietà:
host - (string) host dell'host prototype;
hostid - (string) ID dell'host rilevato o dell'host prototype;
parent_hostid - (string) ID dell'host prototype da cui è stato creato l'host;
parent_itemid - (string) ID della regola LLD che ha creato l'host rilevato;
lastcheck - (timestamp) momento dell'ultima discovery dell'host;
status - (int) stato della discovery dell'host:
0 - (predefinito) host rilevato,
1 - host non più rilevato;
ts_delete - (timestamp) momento in cui un host non più rilevato verrà eliminato;
ts_disable - (timestamp) momento in cui un host non più rilevato verrà disabilitato;
disable_source - (int) indicatore che specifica se l'host è stato disabilitato da una regola LLD o manualmente:
0 - (predefinito) disabilitato automaticamente,
1 - disabilitato da una regola LLD.
selectHostGroups query Restituisce una proprietà hostgroups con i dati dei gruppi host a cui appartiene l'host.
selectHttpTests query Restituisce una proprietà httpTests con gli scenari web dell'host.

Supporta count.
selectInterfaces query Restituisce una proprietà interfaces con le interfacce dell'host.

Supporta count.
selectInventory query Restituisce una proprietà inventory con i dati di inventario dell'host.
selectItems query Restituisce una proprietà items con gli item dell'host.

Supporta count.
selectMacros query Restituisce una proprietà macros con le macro dell'host.
selectParentTemplates query Restituisce una proprietà parentTemplates con i template a cui l'host è collegato.

Oltre ai campi dell'oggetto Template, contiene link_type - (integer) il modo in cui il template è collegato all'host.
Valori possibili:
0 - (predefinito) collegato manualmente;
1 - collegato automaticamente da LLD.

Supporta count.
selectDashboards query Restituisce una proprietà dashboards.

Supporta count.
selectTags query Restituisce una proprietà tags con i tag dell'host.
selectInheritedTags query Restituisce una proprietà inheritedTags con i tag presenti in tutti i template collegati all'host.
selectTriggers query Restituisce una proprietà triggers con i trigger dell'host.

Supporta count.
selectValueMaps query Restituisce una proprietà valuemaps con le mappe dei valori dell'host.
filter object Restituisce solo i risultati che corrispondono esattamente al filtro specificato.

Accetta un oggetto, in cui le chiavi sono nomi di proprietà e i valori sono un singolo valore o un array di valori da confrontare.

Non supporta le proprietà di tipo data type text.

Supporta proprietà aggiuntive: proprietà dell'Host interface.
limitSelects integer Limita il numero di record restituiti dalle sotto-selezioni.

Si applica alle seguenti sotto-selezioni:
selectParentTemplates - i risultati saranno ordinati per host;
selectInterfaces;
selectItems - ordinati per name;
selectDiscoveries - ordinati per name;
selectTriggers - ordinati per description;
selectGraphs - ordinati per name;
selectDashboards - ordinati per name.
search object Restituisce i risultati che corrispondono al pattern specificato (senza distinzione tra maiuscole e minuscole).

Accetta un oggetto, in cui le chiavi sono nomi di proprietà e i valori sono stringhe da cercare. Se non vengono fornite opzioni aggiuntive, esegue una ricerca LIKE "%…%".

Supporta solo proprietà di tipo data type string e text.

Supporta proprietà aggiuntive: proprietà dell'Host interface.
searchInventory object Restituisce gli host che hanno dati di inventario corrispondenti al pattern specificato (senza distinzione tra maiuscole e minuscole).

Accetta un oggetto, in cui le chiavi sono nomi di proprietà e i valori sono stringhe da cercare. Se non vengono fornite opzioni aggiuntive, esegue una ricerca LIKE "%…%".

Supporta solo proprietà di tipo data type string e text.
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
limit integer
output query
preservekeys boolean
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean
selectGroups
(deprecated)
query Questo parametro è deprecato, usare invece selectHostGroups.
Restituisce una proprietà groups con i dati dei gruppi host a cui appartiene l'host.

Valori restituiti

(intero/array) Restituisce:

  • un array di oggetti;
  • il conteggio degli oggetti recuperati, se è stato utilizzato il parametro countOutput.

Esempi

Recupero dei dati per nome

Recupera tutti i dati relativi a due host denominati "Zabbix server" e "Linux server".

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "filter": {
            "host": [
                "Zabbix server",
                "Linux server"
            ]
        }
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10160",
            "proxyid": "0",
            "host": "Zabbix server",
            "status": "0",
            "ipmi_authtype": "-1",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "ipmi_password": "",
            "maintenanceid": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenance_from": "0",
            "name": "Zabbix server",
            "flags": "0",
            "description": "Il server di monitoraggio Zabbix.",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "proxy_groupid": "0",
            "monitored_by": "0",
            "inventory_mode": "1",
            "active_available": "1",
            "assigned_proxyid": "0"
        },
        {
            "hostid": "10167",
            "proxyid": "0",
            "host": "Linux server",
            "status": "0",
            "ipmi_authtype": "-1",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "ipmi_password": "",
            "maintenanceid": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenance_from": "0",
            "name": "Linux server",
            "flags": "0",
            "description": "",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "proxy_groupid": "0",
            "monitored_by": "0",
            "inventory_mode": "1",
            "active_available": "1",
            "assigned_proxyid": "0"
        }
    ],
    "id": 1
}

Recupero dei gruppi di host

Recupera i gruppi di host di cui l'host "Zabbix server" è membro.

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectHostGroups": "extend",
        "filter": {
            "host": [
                "Zabbix server"
            ]
        }
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "hostgroups": [
                {
                    "groupid": "2",
                    "name": "Linux servers",
                    "flags": "0",
                    "uuid": "dc579cd7a1a34222933f24f52a68bcd8"
                },
                {
                    "groupid": "4",
                    "name": "Zabbix servers",
                    "flags": "0",
                    "uuid": "6f6799aa69e844b4b3918f779f2abf08"
                }
            ]
        }
    ],
    "id": 1
}

Recupero dei template collegati

Recupera gli ID e i nomi dei template collegati all'host "10084".

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectParentTemplates": [
            "templateid",
            "name"
        ],
        "hostids": "10084"
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "parentTemplates": [
                {
                    "name": "Linux",
                    "templateid": "10001"
                },
                {
                    "name": "Zabbix Server",
                    "templateid": "10047"
                }
            ]
        }
    ],
    "id": 1
}

Recupero degli host per template

Recupera gli host a cui è collegato il template "10001" (Linux by Zabbix agent).

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid", "name"],
        "templateids": "10001"
    },
    "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 dati di inventario dell'host

Recupera gli host che contengono "Linux" nel campo "OS" dell'inventario dell'host.

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "host"
        ],
        "selectInventory": [
            "os"
        ],
        "searchInventory": {
            "os": "Linux"
        }
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "host": "Zabbix server",
            "inventory": {
                "os": "Linux Ubuntu"
            }
        },
        {
            "hostid": "10107",
            "host": "Linux server",
            "inventory": {
                "os": "Linux Mint"
            }
        }
    ],
    "id": 1
}

Ricerca per tag host

Recupera gli host che hanno il tag "host-name" uguale a "linux-server".

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectTags": "extend",
        "evaltype": 0,
        "tags": [
            {
                "tag": "host-name",
                "value": "linux-server",
                "operator": 1
            }
        ]
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "tags": [
                {
                    "tag": "host-name",
                    "value": "linux-server",
                    "automatic": "0"
                },
                {
                    "tag": "os",
                    "value": "rhel-7",
                    "automatic": "0"
                }
            ]
        }
    ],
    "id": 1
}

Recupera gli host che hanno questi tag non solo a livello di host ma anche nei loro template padre collegati.

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "tags": [
            {
                "tag": "os",
                "value": "rhel-7",
                "operator": 1
            }
        ],
        "inheritedTags": true
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10623",
            "name": "PC room 1"
        },
        {
            "hostid": "10601",
            "name": "Office"
        }
    ],
    "id": 1
}

Recupera gli host escludendo quelli con il tag "component".

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectTags": "extend",
        "evaltype": 0,
        "tags": [
            {
                "tag": "component",
                "value": "",
                "operator": 5
            }
        ]
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "tags": [
                {
                    "tag": "class",
                    "value": "os",
                    "automatic": "0"
                },
                {
                    "tag": "target",
                    "value": "linux",
                    "automatic": "0"
                }
            ]
        },
        {
            "hostid": "10629",
            "tags": [
                {
                    "tag": "class",
                    "value": "application",
                    "automatic": "0"
                },
                {
                    "tag": "target",
                    "value": "browser",
                    "automatic": "0"
                }
            ]
        }
    ],
    "id": 1
}

Ricerca di un host con tag e tag del template

Recupera un host con i tag e tutti i tag collegati ai template padre.

Richiesta:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "hostids": 10502,
        "selectTags": ["tag", "value"],
        "selectInheritedTags": ["tag", "value"]
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10502",
            "name": "Desktop",
            "tags": [
                {
                    "tag": "host-name",
                    "value": "linux-server"
                },
                {
                    "tag": "os",
                    "value": "rhel-7"
                }
            ],
            "inheritedTags": [
                {
                    "tag": "class",
                    "value": "os"
                },
                {
                    "tag": "target",
                    "value": "linux"
                },
                {
                    "tag": "os",
                    "value": "rhel-7"
                }
            ]
        }
    ],
    "id": 1
}

Ricerca degli host per gravità del problema

Recupera gli host che hanno problemi di livello "Disaster".

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "severities": 5
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10160",
            "name": "Zabbix server"
        }
    ],
    "id": 1
}

Recupera gli host che hanno problemi di livello "Average" e "High".

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "severities": [3, 4]
    },
    "id": 1
}

Risposta:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "20170",
            "name": "Database"
        },
        {
            "hostid": "20183",
            "name": "workstation"
        }
    ],
    "id": 1
}

Recupero degli item dell'host

Recupera gli item per l'host "Zabbix server". La richiesta è limitata alle proprietà dell'item itemid, name e status. A causa delle grandi dimensioni della risposta, nell'esempio viene mostrato solo un sottoinsieme di item.

Request:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectItems": ["itemid","name","status"],
        "filter": {
            "host": [
                "Zabbix server"
            ]
        }
    },
    "id": 1
}

Response:

{
  "jsonrpc": "2.0",
  "result": [
    {
      "hostid": "10084",
      "items": [
        {
          "itemid": "42227",
          "name": "Host name of Zabbix agent running",
          "status": "0"
        },
        {
          "itemid": "42237",
          "name": "Zabbix agent ping",
          "status": "0"
        },
        {
          "itemid": "42250",
          "name": "Version of Zabbix agent running",
          "status": "0"
        },
        {
          "itemid": "42251",
          "name": "Maximum number of open file descriptors",
          "status": "0"
        },
        {
          "itemid": "42252",
          "name": "Maximum number of processes",
          "status": "0"
        },
        {
          "itemid": "69869",
          "name": "Interface enp0s3: Inbound packets discarded",
          "status": "0"
        },
        {
          "itemid": "69870",
          "name": "Interface enp0s3: Inbound packets with errors",
          "status": "0"
        },
        {
          "itemid": "69871",
          "name": "Interface enp0s3: Bits received",
          "status": "0"
        },
        {
          "itemid": "69872",
          "name": "Interface enp0s3: Outbound packets discarded",
          "status": "0"
        },
        {
          "itemid": "69873",
          "name": "Interface enp0s3: Outbound packets with errors",
          "status": "0"
        },
        {
          "itemid": "69874",
          "name": "Interface enp0s3: Bits sent",
          "status": "0"
        },
        {
          "itemid": "42253",
          "name": "Number of processes",
          "status": "0"
        },
        {
          "itemid": "42254",
          "name": "Number of running processes",
          "status": "0"
        },
        {
          "itemid": "42255",
          "name": "System boot time",
          "status": "0"
        }
      ]
    }
  ],
  "id": 1
}

Vedi anche

Sorgente

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