script.getscriptsbyhosts

Description

object script.getscriptsbyhosts(array hostIds)

This method allows to retrieve scripts available on the given hosts.

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

(string/array) IDs of hosts to return scripts for.

Return values

(object) Returns an object with host IDs as properties and arrays of available scripts as values.

The method will automatically expand macros in the confirmation text and url.

Examples

Retrieve scripts by host IDs

Retrieve all scripts available on hosts “30079” and “30073”.

Request:

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

Response:

  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. "parameters": []
  28. },
  29. {
  30. "scriptid": "1",
  31. "name": "Ping",
  32. "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
  33. "host_access": "2",
  34. "usrgrpid": "0",
  35. "groupid": "0",
  36. "description": "",
  37. "confirmation": "",
  38. "type": "0",
  39. "execute_on": "1",
  40. "timeout": "30s",
  41. "scope": "2",
  42. "port": "",
  43. "authtype": "0",
  44. "username": "",
  45. "password": "",
  46. "publickey": "",
  47. "privatekey": "",
  48. "menu_path": "",
  49. "url": "",
  50. "new_window": "1",
  51. "parameters": []
  52. },
  53. {
  54. "scriptid": "2",
  55. "name": "Traceroute",
  56. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  57. "host_access": "2",
  58. "usrgrpid": "0",
  59. "groupid": "0",
  60. "description": "",
  61. "confirmation": "",
  62. "type": "0",
  63. "execute_on": "1",
  64. "timeout": "30s",
  65. "scope": "2",
  66. "port": "",
  67. "authtype": "0",
  68. "username": "",
  69. "password": "",
  70. "publickey": "",
  71. "privatekey": "",
  72. "menu_path": "",
  73. "url": "",
  74. "new_window": "1",
  75. "parameters": []
  76. }
  77. ],
  78. "30073": [
  79. {
  80. "scriptid": "3",
  81. "name": "Detect operating system",
  82. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  83. "host_access": "2",
  84. "usrgrpid": "7",
  85. "groupid": "0",
  86. "description": "",
  87. "confirmation": "",
  88. "type": "0",
  89. "execute_on": "1",
  90. "timeout": "30s",
  91. "scope": "2",
  92. "port": "",
  93. "authtype": "0",
  94. "username": "",
  95. "password": "",
  96. "publickey": "",
  97. "privatekey": "",
  98. "menu_path": "",
  99. "url": "",
  100. "new_window": "1",
  101. "parameters": []
  102. },
  103. {
  104. "scriptid": "1",
  105. "name": "Ping",
  106. "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
  107. "host_access": "2",
  108. "usrgrpid": "0",
  109. "groupid": "0",
  110. "description": "",
  111. "confirmation": "",
  112. "type": "0",
  113. "execute_on": "1",
  114. "timeout": "30s",
  115. "scope": "2",
  116. "port": "",
  117. "authtype": "0",
  118. "username": "",
  119. "password": "",
  120. "publickey": "",
  121. "privatekey": "",
  122. "menu_path": "",
  123. "url": "",
  124. "new_window": "1",
  125. "parameters": []
  126. },
  127. {
  128. "scriptid": "2",
  129. "name": "Traceroute",
  130. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  131. "host_access": "2",
  132. "usrgrpid": "0",
  133. "groupid": "0",
  134. "description": "",
  135. "confirmation": "",
  136. "type": "0",
  137. "execute_on": "1",
  138. "timeout": "30s",
  139. "scope": "2",
  140. "port": "",
  141. "authtype": "0",
  142. "username": "",
  143. "password": "",
  144. "publickey": "",
  145. "privatekey": "",
  146. "menu_path": "",
  147. "url": "",
  148. "new_window": "1",
  149. "parameters": []
  150. }
  151. ]
  152. },
  153. "id": 1
  154. }

Source

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