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.

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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

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. "hostid": "10001"
  17. },
  18. {
  19. "scriptid": "1",
  20. "name": "Ping",
  21. "command": "/bin/ping -c 3 {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. "hostid": "10001"
  30. },
  31. {
  32. "scriptid": "2",
  33. "name": "Traceroute",
  34. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  35. "host_access": "2",
  36. "usrgrpid": "0",
  37. "groupid": "0",
  38. "description": "",
  39. "confirmation": "",
  40. "type": "0",
  41. "execute_on": "1",
  42. "hostid": "10001"
  43. }
  44. ],
  45. "30073": [
  46. {
  47. "scriptid": "3",
  48. "name": "Detect operating system",
  49. "command": "sudo /usr/bin/nmap -O {HOST.CONN} 2>&1",
  50. "host_access": "2",
  51. "usrgrpid": "7",
  52. "groupid": "0",
  53. "description": "",
  54. "confirmation": "",
  55. "type": "0",
  56. "execute_on": "1",
  57. "hostid": "10001"
  58. },
  59. {
  60. "scriptid": "1",
  61. "name": "Ping",
  62. "command": "/bin/ping -c 3 {HOST.CONN} 2>&1",
  63. "host_access": "2",
  64. "usrgrpid": "0",
  65. "groupid": "0",
  66. "description": "",
  67. "confirmation": "",
  68. "type": "0",
  69. "execute_on": "1",
  70. "hostid": "10001"
  71. },
  72. {
  73. "scriptid": "2",
  74. "name": "Traceroute",
  75. "command": "/usr/bin/traceroute {HOST.CONN} 2>&1",
  76. "host_access": "2",
  77. "usrgrpid": "0",
  78. "groupid": "0",
  79. "description": "",
  80. "confirmation": "",
  81. "type": "0",
  82. "execute_on": "1",
  83. "hostid": "10001"
  84. }
  85. ]
  86. },
  87. "id": 1
  88. }

Source

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