template.massadd

Description说明

object template.massadd(object parameters)

This method allows to simultaneously add multiple related objects to the given templates该方法允许同时向给定的模板添加多个相关对象。.

Parameters参数

(object) Parameters containing the IDs of the templates to update and the objects to add to the templates包含要更新的模板的ID和要添加到模板的对象的参数.

The method accepts the following parameters该方法接受以下参数.

Parameter参数 Type类型 Description说明
templates(required) object/array Templates to be updated要更新的模板. The templates must have the templateid property defined模板必须定义templateid属性.
groups object/array Host groups to add the given templates to主机组添加指定的模板. The host groups must have the groupid property defined主机组必须定义groupid属性.
hosts object/array Hosts and templates to link the given templates to将给定模板链接到的主机和模板. The hosts must have the hostid property defined主机必须定义groupid属性.
macros object/array User macros to be created for the given templates为给定的模板创建用户宏.
templates_link object/array Templates to link to the given templates链接到给定模板的模板. The templates must have the templateid property defined模板必须定义templateid属性.

Return values返回值

(object) Returns an object containing the IDs of the updated templates under the templateids property.(object)返回一个对象,它包含templateids属性下更新的模板的ID

Examples范例

Adding templates to a group将模板添加到组

Add two templates to the host group “2”将两个模板添加到主机组“2”.

Request请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.massadd",
  4. "params": {
  5. "templates": [
  6. {
  7. "templateid": "10085"
  8. },
  9. {
  10. "templateid": "10086"
  11. }
  12. ],
  13. "groups": [
  14. {
  15. "groupid": "2"
  16. }
  17. ]
  18. },
  19. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  20. "id": 1
  21. }

Response响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10085",
  6. "10086"
  7. ]
  8. },
  9. "id": 1
  10. }

Linking a template to hosts将模板链接到主机

Link template “10073” to two hosts链接模板“10073”到两个主机。.

Request请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.massadd",
  4. "params": {
  5. "templates": [
  6. {
  7. "templateid": "10073"
  8. }
  9. ],
  10. "hosts": [
  11. {
  12. "hostid": "10106"
  13. },
  14. {
  15. "hostid": "10104"
  16. }
  17. ]
  18. },
  19. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  20. "id": 1
  21. }

Response响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10073"
  6. ]
  7. },
  8. "id": 1
  9. }

See also参考

Source来源

CTemplate::massAdd() in frontends/php/include/classes/api/services/CTemplate.php.