这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

更新

描述

object host.update(object/array hosts)

该方法用来更新已存在的主机。

参数

(object/array) 要更新的主机属性。

必须为每个主机定义hostid属性,所有其他属性都是可选的。当只更新指定的属性,其他属性将保持不变。

但是请注意,更新主机名称还会通过主机的名称值来更新主机的可见名称(如果未提供或为空)。

另外,对于标准主机属性,此方法接受如下参数。

参数 [ 型](//zh/manual/api/reference_commentary#data_types) 描述
groups 对象/数组 替换主 所属的当前主机组

主机组必须具有定义的groupid属性。请求中未列出的所有主机组将被取消链接。
interfaces 对象/数组 替换当 的主机接口
tags object/array 替换当前的主机标签

请求中未列出的所有标签将被删除。
inventory 对象 主 资产清单属性。
macros 对象/数组 替换当 用户宏
templates 对象/数组 替换当 链接的模板。请求中未列出的所有模板将仅取消链接。

模板必须已定义过templateid属性。
templates_clear 对象/数组 从主机 删除模板链接并清除。

模板必须已定义过templateid属性。

<note tip>相对于Zabbix前端,当namehost一致,更新host的时候不会自动更新name。两个属性需要明确的更新。这两个属性都需要显式地更新。 :::

返回值

(object)hostids属性中返回包含已更新主机ID对象。

示例

启用主机

启用主机,将status设置为0。

请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10126",
               "status": 0
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10126"
               ]
           },
           "id": 1
       }

删除模板链接

从主机中删除链接并清除两个模板。

请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10126",
               "templates_clear": [
                   {
                       "templateid": "10124"
                   },
                   {
                       "templateid": "10125"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10126"
               ]
           },
           "id": 1
       }

更新主机宏

用两个新的宏替换主机所有的宏。

请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10126",
               "macros": [
                   {
                       "macro": "{$PASS}",
                       "value": "password"
                   },
                   {
                       "macro": "{$DISC}",
                       "value": "sda"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10126"
               ]
           },
           "id": 1
       }

更新主机资产清单

更改资产清单模式并添加位置。

请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10387",
               "inventory_mode": 0,
               "inventory": {
                   "location": "Latvia, Riga"
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10387"
               ]
           },
           "id": 2
       }

更新主机标签

用一个新的标签替换所有的标签。

请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10387",
               "tags": {
                   "tag": "OS",
                   "value": "CentOS 7"
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10387"
               ]
           },
           "id": 1
       }

Updating host encryption

Update the host "10590" to use PSK encryption only for connections from host to Zabbix server, and change the PSK identity and PSK key. Note that the host has to be pre-configured to use PSK.

Request:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10590",
               "tls_connect": 1,
               "tls_accept": 2,
               "tls_psk_identity": "PSK 002",
               "tls_psk": "e560cb0d918d26d31b4f642181f5f570ad89a390931102e5391d08327ba434e9"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10590"
               ]
           },
           "id": 1
       }

参考

来源

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