获取

描述

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

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

参数

(对象) 定义所需输出的参数。

此方法支持如下参数。

参数类型描述
groupidsstring/array返回可以在给定主机组上运行的脚本
hostidsstring/array返回可以在给定主机上运行的脚本。
scriptidsstring/array返回具有给定ID的脚本。
usrgrpidsstring/array返回可以被给定用户组中用户运行的脚本
selectGroupsquery返回可以在其上运行脚本的主机群组的 群组 属性。
selectHostsquery返回可以在其上运行脚本的主机的主机属性。
selectActionsquery返回与脚本相关联的动作的动作属性。
sortfieldstring/array根据给定属性将结果排序。

可能的值: scriptidname.
countOutputboolean这些参数与所有get方法相同,详细描述见reference commentary.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

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

示例

检索所有脚本

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

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

响应:

  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. "parameters": []
  17. },
  18. {
  19. "scriptid": "2",
  20. "name": "Traceroute",
  21. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  22. "host_access": "2",
  23. "usrgrpid": "0",
  24. "groupid": "0",
  25. "description": "",
  26. "confirmation": "",
  27. "type": "0",
  28. "execute_on": "1",
  29. "timeout": "30s",
  30. "parameters": []
  31. },
  32. {
  33. "scriptid": "3",
  34. "name": "Detect operating system",
  35. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  36. "host_access": "2",
  37. "usrgrpid": "7",
  38. "groupid": "0",
  39. "description": "",
  40. "confirmation": "",
  41. "type": "0",
  42. "execute_on": "1",
  43. "timeout": "30s",
  44. "parameters": []
  45. },
  46. {
  47. "scriptid": "4",
  48. "name": "Webhook",
  49. "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}",
  50. "host_access": "2",
  51. "usrgrpid": "7",
  52. "groupid": "0",
  53. "description": "",
  54. "confirmation": "",
  55. "type": "5",
  56. "execute_on": "1",
  57. "timeout": "30s",
  58. "parameters": [
  59. {
  60. "name": "token",
  61. "value": "{$WEBHOOK.TOKEN}"
  62. },
  63. {
  64. "name": "host",
  65. "value": "{HOST.HOST}"
  66. },
  67. {
  68. "name": "v",
  69. "value": "2.2"
  70. }
  71. ]
  72. }
  73. ],
  74. "id": 1
  75. }

另外参考

源代码

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