通过主机获取脚本

描述

object script.getscriptsbyhosts(object parameters) 此方法允许根据给定参数检索脚本。

此方法允许检索给定主机上的所有可用脚本或特定脚本(如果提供了脚本ID)。当提供手动输入时,它用指定的值替换{MANUALPINPUT}宏。

此方法允许任何用户使用。可以在用户角色设置中撤销调用此方法的权限。更多信息见User roles

参数

(object/array) 该方法接受具有以下参数的对象或对象数组。 |参数|类型|描述| |--|--|------| |hostid|ID|要返回脚本的主机的ID。必须是唯一的。
Parameter behavior:
- required| |scriptid|ID|返回脚本ID| |manualinput|string|用户提供的{MANUALPINPUT}宏值|

返回值

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

示例

通过主机ID检索脚本

检索主机“30079”和“30073”上可用的所有脚本。 请求:

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

响应

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

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

检索主机“30079”上ID为“4”、手动输入值为“dashboard.view”的脚本。 请求:

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

响应

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