Zabbix Documentation 2.0

2.23.04.0 (current)In development:4.2 (devel)Unsupported:1.82.02.43.23.4

User Tools

Site Tools


manual:appendix:api:host:massadd

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:appendix:api:host:massadd [2011/04/01 15:30]
richlv quick note on multiple host adding
manual:appendix:api:host:massadd [2019/01/28 14:49] (current)
sasha <code js> => <code java>
Line 1: Line 1:
-===== massAdd() ​===== +===== host.massadd ​===== 
-Available since version: ​**1.8**\\+ 
 +==== Description ==== 
 + 
 +''​object host.massadd(object ​**parameters**)''​ 
 + 
 +This method allows to simultaneously add multiple related objects to all the given hosts. 
 ==== Parameters ==== ==== Parameters ====
-multidimensional array with Hosts, Groups, Template, Macros data\\ 
  
-Only host details can be added this way, not hosts themselves.+''​(object)''​ Parameters containing the IDs of the hosts to update and the objects to add to all the hosts. ​
  
-^Parameter^Type^Optional^Description^Details^ +The method accepts the following parameters.
-|**hosts**|//​array//​| ​ |Host objects to update | | +
-|**groups**|//​array//​| Yes |Host group objects where hosts should be added| | +
-|**templates**|//​array//​| Yes |Template objects which should be linked to hosts. | | +
-|**macros**|//​array//​| Yes |Macros objects which should be added to hosts. ​ | |+
  
-==== Returns ===== +^ Parameter ​^ Type ^ Description ^ 
-^Parameter^Description^ +| **hosts** \\ (required) ​object/array | Hosts to be updated. \\ \\ The hosts must have the ''​hostid''​ property defined. | 
-|**result**|Operation successful. Result will contain ​array of updated Host IDs.| +| groups | object/​array | Host groups to add to the given hosts\\ \\ The host groups must have the ''​groupid''​ property defined.  ​
-|**error**|In case of any errors+interfaces ​object/​array | Host interfaces to be created for the given hosts. ​
-==== Example ====+| macros | object/​array | User macros to be created for the given hosts. | 
 +| templates | object/​array | Templates to link to the given hosts. \\ \\ The templates must have the ''​templateid''​ property defined. |
  
-Add two macros to host with **ID** "​100100000010092"​ +==== Return values ==== 
-<​code>​+ 
 +''​(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: 
 +<​code ​java>
 { {
-"​jsonrpc":"​2.0",​ +    ​"​jsonrpc":​ "​2.0",​ 
-"​method":"​host.massAdd", +    "​method":​ "host.massadd", 
-"​params":​{  +    "​params":​ { 
-"​hosts":​  +        "​hosts": ​[ 
- { +            
-  "​hostid":​ "100100000010092+                "​hostid":​ "10160
- }, +            }, 
-"​macros":​ [ +            { 
-  +                "​hostid":​ "​10167"​ 
-    "​macro":​ "​{$TEST1}",​ +            } 
-    "​value":​ "​MACROTEST1"​ +        ], 
-  }, +        ​"​macros":​ [ 
-  +            
-    "​macro":​ "​{$TEST2}",​ +                "​macro":​ "​{$TEST1}",​ 
-    "​value":​ "​MACROTEST2"​ +                "​value":​ "​MACROTEST1"​ 
-  +            }, 
-+            
-}, +                "​macro":​ "​{$TEST2}",​ 
-"​auth":"​f223adf833b2bf2ff38574a67bba6372", +                "​value":​ "​MACROTEST2"​ 
-"​id":​2+            
 +        
 +    }, 
 +    "​auth":​ "038e1d7b1735c6a5436ee9eae095879e", 
 +    "​id": ​1
 } }
 </​code>​ </​code>​
-Hosts updated successfully:​ 
  
-<​code>​+Response: 
 +<​code ​java>
 { {
-"​jsonrpc":"​2.0",​ +    ​"​jsonrpc":​ "​2.0",​ 
-"​result":​{ +    "​result":​ { 
-   ​"​hostids":​["​100100000010092"] +        "​hostids":​ [ 
-}, +            ​"10160"
-"​id":​2+            "​10167"​ 
 +        ​
 +    }, 
 +    "​id": ​1
 } }
 </​code>​ </​code>​
 +==== See also ====
 +
 +  * [[update|host.update]]
 +  * [[manual:​appendix:​api:​hostgroup:​definitions#​object_details|Host group]]
 +  * [[manual:​appendix:​api:​template:​definitions#​object_details|Template]]
 +  * [[manual:​appendix:​api:​usermacro:​definitions#​hosttemplate_level_macro|User macro]]
 +  * [[manual:​appendix:​api:​hostinterface:​definitions#​host_interface|Host interface]]
 +
 +==== Source ====
 +
 +CHost::​massAdd() in //​frontends/​php/​api/​classes/​CHost.php//​.