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

更新

描述

host.update(主机对象/数组)对象

该方法允许更新现有主机。

这个方法仅允许 管理员超级管理员 用户类型。可以在用户角色中撤销调用方法的权限设置。详情参考 用户角色

参数

(对象/数组) 待更新的主机属性。

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

但是,请注意,更新主机技术名称也将根据主机的技术名称值更新主机的可见名称(如果没有给出或为空)。

除了标准主机属性以外,此方法接受如下参数:

参数 描述
groups 对象/数组 更换主机所属的主机

主机组必须已定义 groupid 属性。所有未在请求中列出的主机组将被解除链接。
interfaces 对象/数组 主机接口用于替换当前主机接口。

所有未在请求中列出的接口将被删除。
tags 对象/数组 主机标签替换当前主机标签。

所有未在请求中列出的标签将被删除。
inventory object 主机清单属性。
macros 对象/数组 用户宏替换当前用户宏。

所有未在请求中列出的宏将被删除。
templates 对象/数组 模板替换当前链接的模板。所有未在请求中列出的模板只会被解除链接。

模板必须定义了 templateid 属性。
templates_clear 对象/数组 模板取消与主机的链接并清除。

模板必须定义了 templateid 属性。

与Zabbix前端不同,当 name (可见主机名)与 host (技术主机名)相同时,通过API更新 host 不会自动更新 name 。这两个属性都需要显式更新。

返回值

(object) 返回一个对象,该对象包含 hostids 属性下更新的主机的id。

示例

开启主机监控

启用主机监控,即设置主机监控状态为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",
                       "description": "Updated description"
                   }
               ]
           },
           "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": 1
       }

更新主机标签

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

请求:

{
           "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"
           },
           "id": 1
       }

Response:

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

另请参阅

源代码

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