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

script.getscriptsbyhosts

通过主机获取脚本

Description

描述

object script.getscriptsbyhosts(object parameters) 此方法允许根据给定参数检索脚本。 This method allows to retrieve all available scripts on the given host 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. ::: ::: 请注意 此方法允许任何用户使用。可以在用户角色设置中撤销调用此方法的权限。更多信息见User roles。 :::

Parameters

参数

(object/array) The method accepts object or array of objects with the following parameters. (object/array) 该方法接受具有以下参数的对象或对象数组。 |Parameter参数|[Type]类型(/manual/api/reference_commentary#data_types)|Description描述| |--|--|------| |hostid|ID|要返回脚本的主机的ID。必须是唯一的。
Parameter behavior:
- required| |scriptid|ID|返回脚本ID| |manualinput|string|用户提供的{MANUALPINPUT}宏值|

返回值

(对象) 返回一个以主机ID为属性、以可用脚本数组为值的对象。 ::: notetip 此方法会自动拓展confirmation 中的宏. :::

示例

Retrieve scripts by host IDs

通过主机ID检索脚本

Retrieve all scripts available on hosts "30079" and "30073". 检索主机“30079”和“30073”上可用的所有脚本。 Request: 请求

{
           "jsonrpc": "2.0",
           "method": "script.getscriptsbyhosts",
           "params": [
              {
                 "hostid":  "30079"
              },
              {
                 "hostid":  "30073"
              }
           ],
           "id": 1
       }

Response: 响应

{
           "jsonrpc": "2.0",
           "result": {
               "30079": [
                   {
                       "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": "2",
                       "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": "2",
                       "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": "2",
                       "port": "",
                       "authtype": "0",
                       "username": "",
                       "password": "",
                       "publickey": "",
                       "privatekey": "",
                       "menu_path": "",
                       "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
                       "new_window": "1",
                       "manualinput": "0",
                       "manualinput_prompt": "Zabbix page to open:",
                       "manualinput_validator_type": "0",
                       "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": "2",
                       "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": []
                   }
               ],
               "30073": [
                   {
                       "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": "2",
                       "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": "2",
                       "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": "2",
                       "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": "2",
                       "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.

检索具有手工输入值的特定脚本。

Retrieve script with ID "4" on host "30079" with manualinput value "dashboard.view". 检索主机“30079”上ID为“4”、手动输入值为“dashboard.view”的脚本。 Request: 请求

{
           "jsonrpc": "2.0",
           "method": "script.getscriptsbyhosts",
           "params": [
             {
               "hostid":  "30079",
               "scriptid": "4",
               "manualinput": "dashboard.view"
             }
         ],
           "id": 1
       }

Response: 响应

{
           "jsonrpc": "2.0",
           "result": {
             "30079": [
               {
                 "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": "2",
                 "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
       }

源代码

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