此方法允许根据指定的参数获取主机。
Parameters参数
(object)
定义期望输出的参数
该方法支持以下参数。
(integer/array)
Returns either:返回其中任一:
an array of objects;一组对象;
the count of retrieved objects, if the
countOutput
parameter has been used.如果已经使用了“countOutput”参数,则检索对象的计数.
范例
根据名称检索数据
Retrieve all data about two hosts named “Zabbix server” and “Linux server”.检索所有关于主机名为“Zabbix server”和“Linux server”的数据。
Response:
- {
- "jsonrpc": "2.0",
- "result": [
- {
- "maintenances": [],
- "hostid": "10160",
- "proxy_hostid": "0",
- "host": "Zabbix server",
- "status": "0",
- "disable_until": "0",
- "error": "",
- "available": "0",
- "errors_from": "0",
- "lastaccess": "0",
- "ipmi_authtype": "-1",
- "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": "Zabbix server",
- "description": "The Zabbix monitoring server.",
- "tls_connect": "1",
- "tls_accept": "1",
- "tls_issuer": "",
- "tls_subject": "",
- "tls_psk_identity": "",
- "tls_psk": ""
- {
- "maintenances": [],
- "hostid": "10167",
- "proxy_hostid": "0",
- "host": "Linux server",
- "status": "0",
- "disable_until": "0",
- "error": "",
- "available": "0",
- "errors_from": "0",
- "lastaccess": "0",
- "ipmi_authtype": "-1",
- "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 server",
- "description": "",
- "tls_connect": "1",
- "tls_accept": "1",
- "tls_issuer": "",
- "tls_subject": "",
- "tls_psk_identity": "",
- "tls_psk": ""
- }
- ],
- "id": 1
- }
Retrieving host groups 检索主机组
Retrieve names of the groups host “Zabbix server” is member of, but no host details themselves. 检索主机“Zabbix server”隶属于的组名,但是不检索主机本身的详情。
Request:
Response:
- {
- "jsonrpc": "2.0",
- "result": [
- {
- "hostid": "10085",
- "groups": [
- {
- "groupid": "2",
- "name": "Linux servers",
- "internal": "0",
- "flags": "0"
- {
- "groupid": "4",
- "name": "Zabbix servers",
- "internal": "0",
- "flags": "0"
- }
- ]
- }
- ],
- "id": 2
- }
Retrieving linked templates 检索相关模板
Retrieve the IDs and names of templates linked to host “10084”.检索主机“10084”相关模板的ID和名称。
Request:
Response:
- {
- "jsonrpc": "2.0",
- "result": [
- {
- "hostid": "10084",
- "parentTemplates": [
- {
- "name": "Template OS Linux",
- "templateid": "10001"
- },
- {
- "name": "Template App Zabbix Server",
- "templateid": "10047"
- }
- ]
- }
- ],
- "id": 1
- }
Searching by host inventory data 根据主机资产清单数据搜索
Request:
Response:
- {
- "jsonrpc": "2.0",
- "result": [
- {
- "hostid": "10084",
- "host": "Zabbix server",
- "inventory": {
- "os": "Linux Ubuntu"
- }
- },
- {
- "hostid": "10107",
- "host": "Linux server",
- "inventory": {
- "os": "Linux Mint"
- }
- }
- ],
- "id": 1
- }
Source 来源
CHost::get() in frontends/php/include/classes/api/services/CHost.php.