通过主机获取脚本

描述

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”上可用的所有脚本。 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "script.getscriptsbyhosts",
  4. "params": [
  5. {
  6. "hostid": "30079"
  7. },
  8. {
  9. "hostid": "30073"
  10. }
  11. ],
  12. "id": 1
  13. }

响应

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "30079": [
  5. {
  6. "scriptid": "3",
  7. "name": "Detect operating system",
  8. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  9. "host_access": "2",
  10. "usrgrpid": "7",
  11. "groupid": "0",
  12. "description": "",
  13. "confirmation": "",
  14. "type": "0",
  15. "execute_on": "1",
  16. "timeout": "30s",
  17. "scope": "2",
  18. "port": "",
  19. "authtype": "0",
  20. "username": "",
  21. "password": "",
  22. "publickey": "",
  23. "privatekey": "",
  24. "menu_path": "",
  25. "url": "",
  26. "new_window": "1",
  27. "manualinput": "0",
  28. "manualinput_prompt": "",
  29. "manualinput_validator_type": "0",
  30. "manualinput_validator": "",
  31. "manualinput_default_value": "",
  32. "parameters": []
  33. },
  34. {
  35. "scriptid": "1",
  36. "name": "Ping",
  37. "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
  38. "host_access": "2",
  39. "usrgrpid": "0",
  40. "groupid": "0",
  41. "description": "",
  42. "confirmation": "",
  43. "type": "0",
  44. "execute_on": "1",
  45. "timeout": "30s",
  46. "scope": "2",
  47. "port": "",
  48. "authtype": "0",
  49. "username": "",
  50. "password": "",
  51. "publickey": "",
  52. "privatekey": "",
  53. "menu_path": "",
  54. "url": "",
  55. "new_window": "1",
  56. "manualinput": "0",
  57. "manualinput_prompt": "",
  58. "manualinput_validator_type": "0",
  59. "manualinput_validator": "",
  60. "manualinput_default_value": "",
  61. "parameters": []
  62. },
  63. {
  64. "scriptid": "4",
  65. "name": "Open Zabbix page",
  66. "command": "",
  67. "host_access": "2",
  68. "usrgrpid": "0",
  69. "groupid": "0",
  70. "description": "",
  71. "confirmation": "Are you sure you want to open page *UNKNOWN*?",
  72. "type": "6",
  73. "execute_on": "2",
  74. "timeout": "30s",
  75. "scope": "2",
  76. "port": "",
  77. "authtype": "0",
  78. "username": "",
  79. "password": "",
  80. "publickey": "",
  81. "privatekey": "",
  82. "menu_path": "",
  83. "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
  84. "new_window": "1",
  85. "manualinput": "0",
  86. "manualinput_prompt": "Zabbix page to open:",
  87. "manualinput_validator_type": "0",
  88. "manualinput_validator": "dashboard.view,discovery.view",
  89. "manualinput_default_value": "",
  90. "parameters": []
  91. },
  92. {
  93. "scriptid": "2",
  94. "name": "Traceroute",
  95. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  96. "host_access": "2",
  97. "usrgrpid": "0",
  98. "groupid": "0",
  99. "description": "",
  100. "confirmation": "",
  101. "type": "0",
  102. "execute_on": "1",
  103. "timeout": "30s",
  104. "scope": "2",
  105. "port": "",
  106. "authtype": "0",
  107. "username": "",
  108. "password": "",
  109. "publickey": "",
  110. "privatekey": "",
  111. "menu_path": "",
  112. "url": "",
  113. "new_window": "1",
  114. "manualinput": "0",
  115. "manualinput_prompt": "",
  116. "manualinput_validator_type": "0",
  117. "manualinput_validator": "",
  118. "manualinput_default_value": "",
  119. "parameters": []
  120. }
  121. ],
  122. "30073": [
  123. {
  124. "scriptid": "3",
  125. "name": "Detect operating system",
  126. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  127. "host_access": "2",
  128. "usrgrpid": "7",
  129. "groupid": "0",
  130. "description": "",
  131. "confirmation": "",
  132. "type": "0",
  133. "execute_on": "1",
  134. "timeout": "30s",
  135. "scope": "2",
  136. "port": "",
  137. "authtype": "0",
  138. "username": "",
  139. "password": "",
  140. "publickey": "",
  141. "privatekey": "",
  142. "menu_path": "",
  143. "url": "",
  144. "new_window": "1",
  145. "manualinput": "0",
  146. "manualinput_prompt": "",
  147. "manualinput_validator_type": "0",
  148. "manualinput_validator": "",
  149. "manualinput_default_value": "",
  150. "parameters": []
  151. },
  152. {
  153. "scriptid": "1",
  154. "name": "Ping",
  155. "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
  156. "host_access": "2",
  157. "usrgrpid": "0",
  158. "groupid": "0",
  159. "description": "",
  160. "confirmation": "",
  161. "type": "0",
  162. "execute_on": "1",
  163. "timeout": "30s",
  164. "scope": "2",
  165. "port": "",
  166. "authtype": "0",
  167. "username": "",
  168. "password": "",
  169. "publickey": "",
  170. "privatekey": "",
  171. "menu_path": "",
  172. "url": "",
  173. "new_window": "1",
  174. "manualinput": "0",
  175. "manualinput_prompt": "",
  176. "manualinput_validator_type": "0",
  177. "manualinput_validator": "",
  178. "manualinput_default_value": "",
  179. "parameters": []
  180. },
  181. {
  182. "scriptid": "4",
  183. "name": "Open Zabbix page",
  184. "command": "",
  185. "host_access": "2",
  186. "usrgrpid": "0",
  187. "groupid": "0",
  188. "description": "",
  189. "confirmation": "Are you sure you want to open page *UNKNOWN*?",
  190. "type": "6",
  191. "execute_on": "2",
  192. "timeout": "30s",
  193. "scope": "2",
  194. "port": "",
  195. "authtype": "0",
  196. "username": "",
  197. "password": "",
  198. "publickey": "",
  199. "privatekey": "",
  200. "menu_path": "",
  201. "url": "http://localhost/ui/zabbix.php?action=*UNKNOWN*",
  202. "new_window": "1",
  203. "manualinput": "1",
  204. "manualinput_prompt": "Zabbix page to open:",
  205. "manualinput_validator_type": "1",
  206. "manualinput_validator": "dashboard.view,discovery.view",
  207. "manualinput_default_value": "",
  208. "parameters": []
  209. },
  210. {
  211. "scriptid": "2",
  212. "name": "Traceroute",
  213. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  214. "host_access": "2",
  215. "usrgrpid": "0",
  216. "groupid": "0",
  217. "description": "",
  218. "confirmation": "",
  219. "type": "0",
  220. "execute_on": "1",
  221. "timeout": "30s",
  222. "scope": "2",
  223. "port": "",
  224. "authtype": "0",
  225. "username": "",
  226. "password": "",
  227. "publickey": "",
  228. "privatekey": "",
  229. "menu_path": "",
  230. "url": "",
  231. "new_window": "1",
  232. "manualinput": "0",
  233. "manualinput_prompt": "",
  234. "manualinput_validator_type": "0",
  235. "manualinput_validator": "",
  236. "manualinput_default_value": "",
  237. "parameters": []
  238. }
  239. ]
  240. },
  241. "id": 1
  242. }

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

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

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "script.getscriptsbyhosts",
  4. "params": [
  5. {
  6. "hostid": "30079",
  7. "scriptid": "4",
  8. "manualinput": "dashboard.view"
  9. }
  10. ],
  11. "id": 1
  12. }

响应

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "30079": [
  5. {
  6. "scriptid": "4",
  7. "name": "Open Zabbix page",
  8. "command": "",
  9. "host_access": "2",
  10. "usrgrpid": "0",
  11. "groupid": "0",
  12. "description": "",
  13. "confirmation": "Are you sure you want to open page dashboard.view?",
  14. "type": "6",
  15. "execute_on": "2",
  16. "timeout": "30s",
  17. "scope": "2",
  18. "port": "",
  19. "authtype": "0",
  20. "username": "",
  21. "password": "",
  22. "publickey": "",
  23. "privatekey": "",
  24. "menu_path": "",
  25. "url": "http://localhost/ui/zabbix.php?action=dashboard.view",
  26. "new_window": "1",
  27. "manualinput": "1",
  28. "manualinput_prompt": "Zabbix page to open:",
  29. "manualinput_validator_type": "1",
  30. "manualinput_validator": "dashboard.view,discovery.view",
  31. "manualinput_default_value": "",
  32. "parameters": []
  33. }
  34. ]
  35. },
  36. "id": 1
  37. }

源代码

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