host.massadd

Description

object host.massadd(object **parameters**)

This method allows to simultaneously add multiple related objects to all the given hosts.

Parameters

(object) Parameters containing the IDs of the hosts to update and the objects to add to all the hosts.

The method accepts the following parameters.

ParameterTypeDescription
hosts
(required)
object/arrayHosts to be updated.

The hosts must have the hostid property defined.
groupsobject/arrayHost groups to add to the given hosts.

The host groups must have the groupid property defined.
interfacesobject/arrayHost interfaces to be created for the given hosts.
macrosobject/arrayUser macros to be created for the given hosts.
templatesobject/arrayTemplates to link to the given hosts.

The templates must have the templateid property defined.

Return values

(object) Returns an object containing the IDs of the updated hosts under the hostids property.

Examples

Adding macros

Add two new macros to two hosts.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.massadd",
  4. "params": {
  5. "hosts": [
  6. {
  7. "hostid": "10160"
  8. },
  9. {
  10. "hostid": "10167"
  11. }
  12. ],
  13. "macros": [
  14. {
  15. "macro": "{$TEST1}",
  16. "value": "MACROTEST1"
  17. },
  18. {
  19. "macro": "{$TEST2}",
  20. "value": "MACROTEST2",
  21. "description": "Test description"
  22. }
  23. ]
  24. },
  25. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  26. "id": 1
  27. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10160",
  6. "10167"
  7. ]
  8. },
  9. "id": 1
  10. }

See also

Source

CHost::massAdd() in ui/include/classes/api/services/CHost.php.