script.get

Description

integer/array script.get(object parameters)

The method allows to retrieve scripts according to the given parameters.

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
groupidsstring/arrayReturn only scripts that can be run on the given host groups.
hostidsstring/arrayReturn only scripts that can be run on the given hosts.
scriptidsstring/arrayReturn only scripts with the given IDs.
usrgrpidsstring/arrayReturn only scripts that can be run by users in the given user groups.
selectHostGroupsqueryReturn a hostgroups property with host groups that the script can be run on.
selectHostsqueryReturn a hosts property with hosts that the script can be run on.
selectActionsqueryReturn a actions property with actions that the script is associated with.
sortfieldstring/arraySort the result by the given properties.

Possible values: scriptid, name.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean
selectGroups
(deprecated)
queryThis parameter is deprecated, please use selectHostGroups instead.
Return a groups property with host groups that the script can be run on.

Return values

(integer/array) Returns either:

  • an array of objects;
  • the count of retrieved objects, if the countOutput parameter has been used.

Examples

Retrieve all scripts

Retrieve all configured scripts.

Request:

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

Response:

  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. "parameters": []
  27. },
  28. {
  29. "scriptid": "2",
  30. "name": "Traceroute",
  31. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  32. "host_access": "2",
  33. "usrgrpid": "0",
  34. "groupid": "0",
  35. "description": "",
  36. "confirmation": "",
  37. "type": "0",
  38. "execute_on": "1",
  39. "timeout": "30s",
  40. "scope": "2",
  41. "port": "",
  42. "authtype": "0",
  43. "username": "",
  44. "password": "",
  45. "publickey": "",
  46. "privatekey": "",
  47. "menu_path": "",
  48. "url": "",
  49. "new_window": "1",
  50. "parameters": []
  51. },
  52. {
  53. "scriptid": "3",
  54. "name": "Detect operating system",
  55. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  56. "host_access": "2",
  57. "usrgrpid": "7",
  58. "groupid": "0",
  59. "description": "",
  60. "confirmation": "",
  61. "type": "0",
  62. "execute_on": "1",
  63. "timeout": "30s",
  64. "scope": "2",
  65. "port": "",
  66. "authtype": "0",
  67. "username": "",
  68. "password": "",
  69. "publickey": "",
  70. "privatekey": "",
  71. "menu_path": "",
  72. "url": "",
  73. "new_window": "1",
  74. "parameters": []
  75. },
  76. {
  77. "scriptid": "4",
  78. "name": "Webhook",
  79. "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}",
  80. "host_access": "2",
  81. "usrgrpid": "7",
  82. "groupid": "0",
  83. "description": "",
  84. "confirmation": "",
  85. "type": "5",
  86. "execute_on": "1",
  87. "timeout": "30s",
  88. "scope": "2",
  89. "port": "",
  90. "authtype": "0",
  91. "username": "",
  92. "password": "",
  93. "publickey": "",
  94. "privatekey": "",
  95. "menu_path": "",
  96. "url": "",
  97. "new_window": "1",
  98. "parameters": [
  99. {
  100. "name": "token",
  101. "value": "{$WEBHOOK.TOKEN}"
  102. },
  103. {
  104. "name": "host",
  105. "value": "{HOST.HOST}"
  106. },
  107. {
  108. "name": "v",
  109. "value": "2.2"
  110. }
  111. ]
  112. },
  113. {
  114. "scriptid": "5",
  115. "name": "URL",
  116. "command": "",
  117. "host_access": "2",
  118. "usrgrpid": "0",
  119. "groupid": "0",
  120. "description": "",
  121. "confirmation": "Go to {HOST.NAME}?",
  122. "type": "6",
  123. "execute_on": "1",
  124. "timeout": "30s",
  125. "scope": "4",
  126. "port": "",
  127. "authtype": "0",
  128. "username": "",
  129. "password": "",
  130. "publickey": "",
  131. "privatekey": "",
  132. "menu_path": "",
  133. "url": "http://zabbix/ui/zabbix.php?action=latest.view&hostids[]={HOST.ID}",
  134. "new_window": "0",
  135. "parameters": []
  136. }
  137. ],
  138. "id": 1
  139. }

See also

Source

CScript::get() in ui/include/classes/api/services/CScript.php.