获取脚本

描述

integer/array script.get(object parameters)

此方法允许根据给定参数检索脚本。

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

参数

(object) 定义所需输出的参数。 此方法支持如下参数。 |参数|类型|描述| |————-|—————————————————————————-|—————-| |groupids|string/array|返回可以在给定主机组上运行的脚本| |hostids|string/array|返回可以在给定主机上运行的脚本。| |scriptids|string/array|返回具有给定ID的脚本。| |usrgrpids|string/array|返回可以被给定用户组中用户运行的脚本| |selectGroups|query|返回可以在其上运行脚本的主机群组的 群组 属性。| |selectHosts|query|返回可以在其上运行脚本的主机的主机属性。| |selectActions|query|返回与脚本相关联的动作的动作属性。| |sortfield|string/array|根据给定属性将结果排序。

可能的值: scriptidname.| |countOutput|boolean|这些参数与所有get方法相同,详细描述见reference commentary.| |editable|boolean|^| |excludeSearch|boolean|^| |filter|object|^| |limit|integer|^| |output|query|^| |preservekeys|boolean|^| |search|object|^| |searchByAny|boolean|^| |searchWildcardsEnabled|boolean|^| |sortorder|string/array|^| |startSearch|boolean|^| |selectGroups
(deprecated)|query|该参数已经被启用,请使用 selectHostGroups 单数返回groups ,其中包含可以运行脚本的主机组。|

返回值

(整型/数组) 返回其中之一: - 一组对象; - 如果用到countOutput参数,被检索到的对象数,。

示例

检索所有脚本

检索所有配置的脚本。 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "script.get",
  4. "params": {
  5. "output": "extend"
  6. },
  7. "id": 1
  8. }

响应

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "scriptid": "1",
  6. "name": "Ping",
  7. "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
  8. "host_access": "2",
  9. "usrgrpid": "0",
  10. "groupid": "0",
  11. "description": "",
  12. "confirmation": "",
  13. "type": "0",
  14. "execute_on": "1",
  15. "timeout": "30s",
  16. "scope": "2",
  17. "port": "",
  18. "authtype": "0",
  19. "username": "",
  20. "password": "",
  21. "publickey": "",
  22. "privatekey": "",
  23. "menu_path": "",
  24. "url": "",
  25. "new_window": "1",
  26. "manualinput": "0",
  27. "manualinput_prompt": "",
  28. "manualinput_validator": "",
  29. "manualinput_validator_type": "0",
  30. "manualinput_default_value": "",
  31. "parameters": []
  32. },
  33. {
  34. "scriptid": "2",
  35. "name": "Traceroute",
  36. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  37. "host_access": "2",
  38. "usrgrpid": "0",
  39. "groupid": "0",
  40. "description": "",
  41. "confirmation": "",
  42. "type": "0",
  43. "execute_on": "1",
  44. "timeout": "30s",
  45. "scope": "2",
  46. "port": "",
  47. "authtype": "0",
  48. "username": "",
  49. "password": "",
  50. "publickey": "",
  51. "privatekey": "",
  52. "menu_path": "",
  53. "url": "",
  54. "new_window": "1",
  55. "manualinput": "0",
  56. "manualinput_prompt": "",
  57. "manualinput_validator": "",
  58. "manualinput_validator_type": "0",
  59. "manualinput_default_value": "",
  60. "parameters": []
  61. },
  62. {
  63. "scriptid": "3",
  64. "name": "Detect operating system",
  65. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  66. "host_access": "2",
  67. "usrgrpid": "7",
  68. "groupid": "0",
  69. "description": "",
  70. "confirmation": "",
  71. "type": "0",
  72. "execute_on": "1",
  73. "timeout": "30s",
  74. "scope": "2",
  75. "port": "",
  76. "authtype": "0",
  77. "username": "",
  78. "password": "",
  79. "publickey": "",
  80. "privatekey": "",
  81. "menu_path": "",
  82. "url": "",
  83. "new_window": "1",
  84. "manualinput": "0",
  85. "manualinput_prompt": "",
  86. "manualinput_validator": "",
  87. "manualinput_validator_type": "0",
  88. "manualinput_default_value": "",
  89. "parameters": []
  90. },
  91. {
  92. "scriptid": "4",
  93. "name": "Webhook",
  94. "command": "try {\n var request = new HttpRequest(),\n response,\n data;\n\n request.addHeader('Content-Type: application/json');\n\n response = request.post('https://localhost/post', value);\n\n try {\n response = JSON.parse(response);\n }\n catch (error) {\n response = null;\n }\n\n if (request.getStatus() !== 200 || !('data' in response)) {\n throw 'Unexpected response.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.log(3, '[Webhook Script] response data: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.log(3, '[Webhook Script] script execution failed: ' + error);\n throw 'Execution failed: ' + error + '.';\n}",
  95. "host_access": "2",
  96. "usrgrpid": "7",
  97. "groupid": "0",
  98. "description": "",
  99. "confirmation": "",
  100. "type": "5",
  101. "execute_on": "1",
  102. "timeout": "30s",
  103. "scope": "2",
  104. "port": "",
  105. "authtype": "0",
  106. "username": "",
  107. "password": "",
  108. "publickey": "",
  109. "privatekey": "",
  110. "menu_path": "",
  111. "url": "",
  112. "new_window": "1",
  113. "manualinput": "0",
  114. "manualinput_prompt": "",
  115. "manualinput_validator": "",
  116. "manualinput_validator_type": "0",
  117. "manualinput_default_value": "",
  118. "parameters": [
  119. {
  120. "name": "token",
  121. "value": "{$WEBHOOK.TOKEN}"
  122. },
  123. {
  124. "name": "host",
  125. "value": "{HOST.HOST}"
  126. },
  127. {
  128. "name": "v",
  129. "value": "2.2"
  130. }
  131. ]
  132. },
  133. {
  134. "scriptid": "5",
  135. "name": "URL",
  136. "command": "",
  137. "host_access": "2",
  138. "usrgrpid": "0",
  139. "groupid": "0",
  140. "description": "",
  141. "confirmation": "Go to {HOST.NAME}?",
  142. "type": "6",
  143. "execute_on": "1",
  144. "timeout": "30s",
  145. "scope": "4",
  146. "port": "",
  147. "authtype": "0",
  148. "username": "",
  149. "password": "",
  150. "publickey": "",
  151. "privatekey": "",
  152. "menu_path": "",
  153. "url": "http://zabbix/ui/zabbix.php?action=latest.view&hostids[]={HOST.ID}",
  154. "new_window": "0",
  155. "manualinput": "0",
  156. "manualinput_prompt": "",
  157. "manualinput_validator": "",
  158. "manualinput_validator_type": "0",
  159. "manualinput_default_value": "",
  160. "parameters": []
  161. },
  162. {
  163. "scriptid": "6",
  164. "name": "URL with user input",
  165. "command": "",
  166. "host_access": "2",
  167. "usrgrpid": "0",
  168. "groupid": "0",
  169. "description": "",
  170. "confirmation": "Open zabbix page {MANUALINPUT}?",
  171. "type": "6",
  172. "execute_on": "1",
  173. "timeout": "30s",
  174. "scope": "2",
  175. "port": "",
  176. "authtype": "0",
  177. "username": "",
  178. "password": "",
  179. "publickey": "",
  180. "privatekey": "",
  181. "menu_path": "",
  182. "url": "http://zabbix/ui/zabbix.php?action={MANUALINPUT}",
  183. "new_window": "0",
  184. "manualinput": "1",
  185. "manualinput_prompt": "Select a page to open:",
  186. "manualinput_validator": "dashboard.view,script.list,actionlog.list",
  187. "manualinput_validator_type": "1",
  188. "parameters": []
  189. }
  190. ],
  191. "id": 1
  192. }

另外参考

源代码

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