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. (string/array) 主机IDs

Return values 返回值

(object) Returns an object with host IDs as properties and arrays of available scripts as values. (object) 返回一个对象,该对象的主机id作为属性,而可用脚本的数组作为值。 <note tip>The method will automatically expand macros in the confirmation text. ::: <note tip>该方法将在confirmation文本中自动扩展宏。 :::

Examples 示例如下

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

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.