根据事件获取脚本

描述

object script.getscriptsbyevents(object parameters)

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

任何类型的用户都可以使用此方法。权限调用该方法可以在用户角色设置中撤消。请参阅[用户 角色](/manual/web_interface/frontend_actions/users/user_roles)了解更多信息。

参数

(object/array) 该方法接受具有以下参数的对象或对象数组。 |参数|类型|说明| |—|—|———| |eventid|ID|要返回脚本的事件的ID。必须是唯一的。

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

返回值

(object) 返回一个对象,该对象的属性和数组为事件ID可用的脚本作为值。如果提供了脚本ID,则关联的值是一个包含特定脚本的数组。

该方法将自动展开“确认”文本中的宏,手动输入提示text和url

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

示例

按事件ID检索脚本

检索事件ID为”632” and “614”的全部脚本 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "script.getscriptsbyevents",
  4. "params": [
  5. {
  6. "eventid": "632"
  7. },
  8. {
  9. "eventid": "614"
  10. }
  11. ],
  12. "id": 1
  13. }

响应

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "632": [
  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": "4",
  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": "4",
  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": "4",
  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": "1",
  86. "manualinput_prompt": "Zabbix page to open:",
  87. "manualinput_validator_type": "1",
  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": "4",
  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. "614": [
  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": "4",
  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": "1",
  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": "4",
  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": "4",
  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": "4",
  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. }

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

检索具有手动输入值“dashboard.view”的事件“632”的ID为“4”的脚本。 请求:

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

响应

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "632": [
  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": "4",
  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::getScriptsByEvents() in ui/include/classes/api/services/CScript.php.