通过主机获取脚本

描述

object script.getscriptsbyhosts(array hostIds) 此方法允许检索特定主机可用的脚本。

此方法允许任何用户使用。可以在用户角色设置中撤销调用此方法的权限。更多信息见User roles

参数

(字符串/数组) 用于检索脚本的主机ID。

返回值

(对象) 返回一个以主机ID为属性、以可用脚本数组为值的对象。 ::: notetip 此方法会自动拓展confirmation 中的宏. :::

示例

通过主机ID检索脚本

检索主机“30079”和“30073”上所有脚本。 请求:

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

相应:

  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. }

源代码

CScript::getScriptsByHosts() 在frontends/php/include/classes/api/services/CScript.php