script.getscriptsbyhosts

Description说明

object script.getscriptsbyhosts(array hostIds)

This method allows to retrieve scripts available on the given hosts此方法允许检索给定主机上可用的脚本.

Parameters参数

(string/array) IDs of hosts to return scripts for要返回脚本的主机的ID.

Return values返回值

(object) Returns an object with host IDs as properties and arrays of available scripts as values返回一个具有主机ID的对象和可用脚本的数组作为值.

The method will automatically expand macros in the confirmation text该方法将自动在confirmation文本中展开宏.

Examples范例

Retrieve scripts by host IDs通过主机ID检索脚本

Retrieve all scripts available on hosts “30079” and “30073”检索主机“30079” 和“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 frontends/php/include/classes/api/services/CScript.php.