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

script.getscriptsbyevents

检索给定事件可用的脚本。

Description

描述

object script.getscriptsbyevents(object parameters)

This method allows to retrieve all available scripts on the given event or specific script if script ID is provided. When manualinput is provided, it substitutes the {MANUALINPUT} macro with the specified value. 此方法允许检索给定事件的所有可用脚本 或特定脚本(如果提供了脚本ID)。当提供手动输入时, 它用指定的值替换{MANUALPINPUT}宏。 ::: noteclassic This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information. ::: ::: 请注意 任何类型的用户都可以使用此方法。权限调用该方法可以在用户角色设置中撤消。请参阅[用户 角色](/manual/web_interface/frontend_actions/users/user_roles)了解更多信息。 :::

Parameters

参数

(object/array) The method accepts object or array of objects with the following parameters. (object/array) 该方法接受具有以下参数的对象或对象数组。 |Parameter参数|Type类型|Description说明| |--|--|------| |eventid|ID|要返回脚本的事件的ID。必须是唯一的。

Parameter behavior:
- required| |scriptid|ID|返回脚本ID.| |manualinput|string|用户提供的{MANUALPINPUT}宏的值。|

Return values

返回值

(object) Returns an object with event IDs as properties and arrays of available scripts as values. If script ID is provided, the associated value is an array containing the specific script. (object) 返回一个对象,该对象的属性和数组为事件ID可用的脚本作为值。如果提供了脚本ID,则关联的值是一个包含特定脚本的数组。 ::: notetip The method will automatically expand macros in the confirmation text, manualinput prompt text and url.

If the manualinput parameter is provided, the {MANUALINPUT} macro will be resolved to the specified value. ::: ::: 请注意 该方法将自动展开“确认”文本中的宏,手动输入提示text和url

如果提供了manualinput参数,{MANUALPINPUT}宏将解析为指定值。 :::

Examples

示例

Retrieve scripts by event IDs

按事件ID检索脚本

Retrieve all scripts available to events "632" and "614". 检索事件ID为"632" and "614"的全部脚本 Request: 请求

{
           "jsonrpc": "2.0",
           "method": "script.getscriptsbyevents",
           "params": [
             {
                "eventid":  "632"
             },
             {
                "eventid":  "614"
             }
           ],
           "id": 1
       }

Response: 响应

{
           "jsonrpc": "2.0",
           "result": {
               "632": [
                   {
                       "scriptid": "3",
                       "name": "Detect operating system",
                       "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
                       "host_access": "2",
                       "usrgrpid": "7",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "",
                       "type": "0",
                       "execute_on": "1",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "",
                       "manualinput_validator_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "1",
                       "name": "Ping",
                       "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "",
                       "type": "0",
                       "execute_on": "1",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "",
                       "manualinput_validator_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "4",
                       "name": "Open Zabbix page",
                       "command": "",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "Are you sure you want to open page *UNKNOWN*?",
                       "type": "6",
                       "execute_on": "2",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                       "new_window": "1",
                       "manualinput": "1",
                       "manualinput_prompt": "Zabbix page to open:",
                       "manualinput_validator_type": "1",
                       "manualinput_validator": "dashboard.view,discovery.view",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "2",
                       "name": "Traceroute",
                       "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "",
                       "type": "0",
                       "execute_on": "1",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "",
                       "manualinput_validator_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   }
               ],
               "614": [
                   {
                       "scriptid": "3",
                       "name": "Detect operating system",
                       "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
                       "host_access": "2",
                       "usrgrpid": "7",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "",
                       "type": "0",
                       "execute_on": "1",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "",
                       "manualinput_validator_type": "1",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "1",
                       "name": "Ping",
                       "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "",
                       "type": "0",
                       "execute_on": "1",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "",
                       "manualinput_validator_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "4",
                       "name": "Open Zabbix page",
                       "command": "",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "Are you sure you want to open page *UNKNOWN*?",
                       "type": "6",
                       "execute_on": "2",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                       "new_window": "1",
                       "manualinput": "1",
                       "manualinput_prompt": "Zabbix page to open:",
                       "manualinput_validator_type": "1",
                       "manualinput_validator": "dashboard.view,discovery.view",
                       "manualinput_default_value": "",
                       "parameters": []
                   },
                   {
                       "scriptid": "2",
                       "name": "Traceroute",
                       "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
                       "host_access": "2",
                       "usrgrpid": "0",
                       "groupid": "0",
                       "description": "",
                       "confirmation": "",
                       "type": "0",
                       "execute_on": "1",
                       "timeout": "30s",
                       "scope": "4",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "",
                       "manualinput_validator_type": "0",
                       "manualinput_validator": "",
                       "manualinput_default_value": "",
                       "parameters": []
                   }
               ]
           },
           "id": 1
       }

Retrieve specific script with manualinput value.

检索具有manualinput值的特定脚本。

Retrieve script with ID "4" on event "632" with manualinput value "dashboard.view". 检索具有手动输入值“dashboard.view”的事件“632”的ID为“4”的脚本。 Request: 请求

{
           "jsonrpc": "2.0",
           "method": "script.getscriptsbyevents",
           "params": [
             {
               "eventid":  "632",
               "scriptid": "4",
               "manualinput": "dashboard.view"
             }
         ],
           "id": 1
       }

Response: 响应

{
           "jsonrpc": "2.0",
           "result": {
             "632": [
               {
                 "scriptid": "4",
                 "name": "Open Zabbix page",
                 "command": "",
                 "host_access": "2",
                 "usrgrpid": "0",
                 "groupid": "0",
                 "description": "",
                 "confirmation": "Are you sure you want to open page dashboard.view?",
                 "type": "6",
                 "execute_on": "2",
                 "timeout": "30s",
                 "scope": "4",
                 "port": "",
                 "authtype": "0",
                 "username": "",
                 "password": "",
                 "publickey": "",
                 "privatekey": "",
                 "menu_path": "",
                 "url": "http://localhost/ui/zabbix.php?action=dashboard.view",
                 "new_window": "1",
                 "manualinput": "1",
                 "manualinput_prompt": "Zabbix page to open:",
                 "manualinput_validator_type": "1",
                 "manualinput_validator": "dashboard.view,discovery.view",
                 "manualinput_default_value": "",
                 "parameters": []
               }
             ]
           },
           "id": 1
       }

Source

来源

CScript::getScriptsByEvents() in ui/include/classes/api/services/CScript.php.