host.update

描述

object host.update(object/array hosts)

此方法允许update现有的主机.

此方法仅适用于管理员超级管理员 用户类型. 调用该方法的权限可以在用户角色 设置中撤销. 更多信息请参阅User roles.

参数

(object/array) 主机 待更新属性

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

请注意,更新主机技术名称也将update 主机的可见名称(如果未提供或为空)则显示主机的技术名称 名称 值

除了主机之外,该方法 接受以下参数。

参数 数据类型 描述
groups object/array 主机组 用于替换当前 主机 组 主机 所属的组。
所有未在请求中列出的 主机 组将被解除关联。

主机 组必须仅定义 groupid 属性。
interfaces object/array Host interfaces 用于替换当前的 主机 接口
请求中未列出的所有接口将被移除
tags object/array 主机标签 用于替换当前的 主机 标签
请求中未列出的所有标签将被移除
inventory object 主机资产清单 属性
macros object/array User macros 用于替换当前用户宏。
请求中未列出的所有宏将被删除。
templates object/array Templates 用于替换当前关联的模板。
请求中未列出的所有模板将被解除关联。

模板必须仅定义 templateid 属性。
templates_clear object/array Templates 取消关联并从 主机 中 clear.

模板必须仅定义 templateid 属性.

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

返回值

(object) 返回一个包含更新后objectID的主机数组 存储在hostids属性下

示例

启用主机

启用 主机 监控,即将其状态设置为"0".

执行请求:

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

响应:

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

解除模板关联

从主机取消关联并clear两个模板.

执行请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10126",
               "templates_clear": [
                   {
                       "templateid": "10124"
                   },
                   {
                       "templateid": "10125"
                   }
               ]
           },
           "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"
                   }
               ]
           },
           "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"
               }
           },
           "id": 1
       }

响应:

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

更新主机标签

将所有主机标签替换为新的标签.

执行请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10387",
               "tags": {
                   "tag": "os",
                   "value": "rhel-7"
               }
           },
           "id": 1
       }

响应:

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

更新已发现的 主机宏

将发现规则创建的"自动"宏转换为"手动"并将其值更改为"new-value".

执行请求:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10387",
               "macros": {
                   "hostmacroid": "5541",
                   "value": "new-value",
                   "automatic": "0"
               }
           },
           "id": 1
       }

响应:

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

更新主机加密

将主机 "10590"更新为仅对从主机到Zabbix server的连接使用PSK加密,并更改PSK标识和PSK密钥。 注意主机必须为服务器agent通信配置psk示例

执行请求:

{
           "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
       }

响应:

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

另请参阅

来源

CHost::update() 位于 ui/include/classes/api/services/CHost.php 文件中.