2022 Zabbix中国峰会
2022 Zabbix中国峰会

更新

Description

描述

object script.update(object/array scripts)

This method allows to update existing scripts. 此方法允许更新已存在的脚本。 ::: noteclassic This method is only available to Super admin user type. Permissions to call the method can be revoked in user role settings. See User roles for more information. ::: ::: 请注意 此方法只有_超级管理员_ 用户可以使用。可以在用户角色设置中撤销调用此方法的权限。 更多信息见 User roles :::

Parameters

参数

(object/array) Script properties to be updated. (object/array) 待更新的[脚本属性] The scriptid property must be defined for each script, all other properties are optional. Only the passed properties will be updated, all others will remain unchanged. An exception is type property change from 5 (Webhook) to other: the parameters property will be cleaned. 所有脚本必须定义scriptid属性,其他所有属性都是可选的。只有被传递的属性会被更新,其他所有属性保持不变。例外是type属性会从5(Webhook)变成其他:parameters属性会被清除。

Return values

返回值

(object) Returns an object containing the IDs of the updated scripts under the scriptids property. (object) 返回一个scriptids属性包含被更新脚本ID的对象。

Examples

示例

Change script command

修改脚本命令

Change the command of the script to "/bin/ping -c 10 {HOST.CONN} 2>&1". 把脚本命令修改为“/bin/ping -c 10 {HOST.CONN} 2>&1”。 Request: 请求:

{
           "jsonrpc": "2.0",
           "method": "script.update",
           "params": {
               "scriptid": "1",
               "command": "/bin/ping -c 10 {HOST.CONN} 2>&1"
           },
           "id": 1
       }

Response: 响应

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

Change script command and add manual input

更改脚本命令并添加手动输入

Change the command of the script to "/bin/ping -c {MANUALINPUT} {HOST.CONN} 2>&1". 改变脚本命令"/bin/ping -c {MANUALINPUT} {HOST.CONN} 2>&1". Request: 请求

{
           "jsonrpc": "2.0",
           "method": "script.update",
           "params": {
             "scriptid": "1",
             "command": "/bin/ping -c {MANUALINPUT} {HOST.CONN} 2>&1",
             "manualinput": "1",
             "manualinput_prompt": "Specify the number of ICMP packets to send with the ping command",
             "manualinput_validator": "^(?:[1-9]|10)$",
             "manualinput_validator_type": "0",
             "manualinput_default_value": "10"
           },
           "id": 1
       }

Response: 响应:

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

源代码

CScript::update() 在 frontends/php/include/classes/api/services/CScript.php