manual:api:reference:host:get

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:api:reference:host:get [2020/03/06 11:22]
iivs added and fixed examples (ZBXNEXT-5694)
manual:api:reference:host:get [2021/01/27 20:27] (current)
Line 6: Line 6:
  
 The method allows to retrieve hosts according to the given parameters. The method allows to retrieve hosts according to the given parameters.
 +
 +<​note>​This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See [[:​manual/​web_interface/​frontend_sections/​administration/​user_roles|User roles]] for more information.</​note>​
  
 ==== Parameters ==== ==== Parameters ====
Line 13: Line 15:
 The method supports the following parameters. The method supports the following parameters.
  
-^Parameter^Type^Description^+^Parameter^[[:​manual/​api/​reference_commentary#​data_types|Type]]^Description^
 |groupids|string/​array| Return only hosts that belong to the given groups. |  |groupids|string/​array| Return only hosts that belong to the given groups. | 
 |applicationids|string/​array| Return only hosts that have the given applications. | |applicationids|string/​array| Return only hosts that have the given applications. |
Line 60: Line 62:
 |selectMacros|query|Return a ''​[[:​manual/​api/​reference/​usermacro/​object|macros]]''​ property with host macros. ​ | |selectMacros|query|Return a ''​[[:​manual/​api/​reference/​usermacro/​object|macros]]''​ property with host macros. ​ |
 |selectParentTemplates|query|Return a ''​[[:​manual/​api/​reference/​template/​object|parentTemplates]]''​ property with templates that the host is linked to.\\ \\ Supports ''​count''​. | |selectParentTemplates|query|Return a ''​[[:​manual/​api/​reference/​template/​object|parentTemplates]]''​ property with templates that the host is linked to.\\ \\ Supports ''​count''​. |
-|selectScreens|query|Return a ''​[[:​manual/​api/​reference/​screen/object|screens]]''​ property ​with host screens.\\ \\ Supports ''​count''​. |+|selectDashboards ​| query | Return a ''​[[:​manual/​api/​reference/​templatedashboard/object|dashboards]]''​ property. \\ \\ Supports ''​count''​. |
 |selectTags|query|Return a ''​[[:​manual/​api/​reference/​host/​object#​host_tag|tags]]''​ property with host tags. | |selectTags|query|Return a ''​[[:​manual/​api/​reference/​host/​object#​host_tag|tags]]''​ property with host tags. |
 |selectInheritedTags|query| Return an ''​[[:​manual/​api/​reference/​host/​object#​host_tag|inheritedTags]]''​ property with tags that are on all templates which are linked to host. | |selectInheritedTags|query| Return an ''​[[:​manual/​api/​reference/​host/​object#​host_tag|inheritedTags]]''​ property with tags that are on all templates which are linked to host. |
Line 66: Line 68:
 ^  ||| ^  |||
 |filter ​ | object |Return only those results that exactly match the given filter.\\ \\ Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against. \\ \\ Allows filtering by interface properties. | |filter ​ | object |Return only those results that exactly match the given filter.\\ \\ Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against. \\ \\ Allows filtering by interface properties. |
-| limitSelects | integer | Limits the number of records returned by subselects. \\  \\ Applies to the following subselects: \\ ''​selectParentTemplates''​ - results will be sorted by ''​host'';​ \\ ''​selectInterfaces'';​ \\ ''​selectItems''​ - sorted by ''​name'';​ \\ ''​selectDiscoveries''​ - sorted by ''​name'';​ \\ ''​selectTriggers''​ - sorted by ''​description'';​ \\ ''​selectGraphs''​ - sorted by ''​name'';​ \\ ''​selectApplications''​ - sorted by ''​name'';​ \\ ''​selectScreens''​ - sorted by ''​name''​. |+| limitSelects | integer | Limits the number of records returned by subselects. \\  \\ Applies to the following subselects: \\ ''​selectParentTemplates''​ - results will be sorted by ''​host'';​ \\ ''​selectInterfaces'';​ \\ ''​selectItems''​ - sorted by ''​name'';​ \\ ''​selectDiscoveries''​ - sorted by ''​name'';​ \\ ''​selectTriggers''​ - sorted by ''​description'';​ \\ ''​selectGraphs''​ - sorted by ''​name'';​ \\ ''​selectApplications''​ - sorted by ''​name'';​ \\ ''​selectDashboards''​ - sorted by ''​name''​. |
 |search ​ | object |Return results that match the given wildcard search.\\ \\ Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a ''​LIKE "​%…%"''​ search.\\ \\ Allows searching by interface properties. Works only with text fields. | |search ​ | object |Return results that match the given wildcard search.\\ \\ Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a ''​LIKE "​%…%"''​ search.\\ \\ Allows searching by interface properties. Works only with text fields. |
 |searchInventory | object | Return only hosts that have inventory data matching the given wildcard search. \\ \\ This parameter is affected by the same additional parameters as ''​search''​. | |searchInventory | object | Return only hosts that have inventory data matching the given wildcard search. \\ \\ This parameter is affected by the same additional parameters as ''​search''​. |
Line 280: Line 282:
             "​parentTemplates":​ [             "​parentTemplates":​ [
                 {                 {
-                    "​name":​ "Template OS Linux",​+                    "​name":​ "​Linux",​
                     "​templateid":​ "​10001"​                     "​templateid":​ "​10001"​
                 },                 },
                 {                 {
-                    "​name":​ "Template App Zabbix Server",​+                    "​name":​ "​Zabbix Server",​
                     "​templateid":​ "​10047"​                     "​templateid":​ "​10047"​
                 }                 }
Line 392: Line 394:
 </​code>​ </​code>​
  
-Retrieve hosts that have "​Disaster"​ problems.+Retrieve hosts that have these tags not only on host level but also in their linked parent templates. 
 Request: Request:
 <code java> <code java>
Line 400: Line 403:
     "​params":​ {     "​params":​ {
         "​output":​ ["​name"​],​         "​output":​ ["​name"​],​
-        "severities": ​5+        "tags": ​[{"​tag":​ "​A",​ "​value":​ "​1",​ "​operator":​ "​0"​}],​ 
 +        "​inheritedTags":​ true
     },     },
     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​
Line 413: Line 417:
     "​result":​ [     "​result":​ [
         {         {
-            "​hostid":​ "10160", +            "​hostid":​ "10623", 
-            "​name":​ "Zabbix server"+            "​name":​ "PC room 1" 
 +        }, 
 +        { 
 +            "​hostid":​ "​10601",​ 
 +            "​name":​ "​Office"
         }         }
     ],     ],
Line 421: Line 429:
 </​code>​ </​code>​
  
-Retrieve ​hosts that have "​Average" ​and "​High"​ problems.+=== Searching host with tags and template tags === 
 + 
 +Retrieve ​a host with tags and all tags that are linked to parent templates. 
 Request: Request:
 <code java> <code java>
Line 429: Line 440:
     "​params":​ {     "​params":​ {
         "​output":​ ["​name"​],​         "​output":​ ["​name"​],​
-        "severities": [34]+        "hostids":​ 10502, 
 +        "​selectTags": ["​tag"​"​value"​],​ 
 +        "​selectInheritedTags":​ ["​tag",​ "​value"​]
     },     },
     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​
Line 442: Line 455:
     "​result":​ [     "​result":​ [
         {         {
-            "​hostid":​ "20170", +            "​hostid":​ "10502", 
-            "​name":​ "Database+            "​name":​ "Desktop", 
-        }, +            "​tags":​ [ 
-        +                { 
-            "hostid": "20183", +                    "​tag":​ "​A",​ 
-            "name": "workstation"+                    "​value":​ "​1"​ 
 +                ​} 
 +            ]
 +            "​inheritedTags":​ [ 
 +                ​
 +                    "tag": "B", 
 +                    "value": "2" 
 +                } 
 +            ]
         }         }
     ],     ],
Line 454: Line 475:
 </​code>​ </​code>​
  
-Retrieve hosts that have these tags not only on host level but also in their linked parent templates.+=== Searching hosts by problem severity === 
 + 
 +Retrieve hosts that have "​Disaster"​ problems. 
 Request: Request:
 <code java> <code java>
Line 462: Line 486:
     "​params":​ {     "​params":​ {
         "​output":​ ["​name"​],​         "​output":​ ["​name"​],​
-        "tags": ​[{"​tag":​ "​A",​ "​value":​ "​1",​ "​operator":​ "​0"​}],​ +        "severities": ​5
-        "​inheritedTags":​ true+
     },     },
     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​
Line 476: Line 499:
     "​result":​ [     "​result":​ [
         {         {
-            "​hostid":​ "10623", +            "​hostid":​ "10160", 
-            "​name":​ "PC room 1" +            "​name":​ "Zabbix server"
-        }, +
-        { +
-            "​hostid":​ "​10601",​ +
-            "​name":​ "​Office"+
         }         }
     ],     ],
Line 488: Line 507:
 </​code>​ </​code>​
  
-Retrieve ​a host with tags and all tags that are linked to parent templates.+Retrieve ​hosts that have "​Average"​ and "​High"​ problems. 
 Request: Request:
 <code java> <code java>
Line 496: Line 516:
     "​params":​ {     "​params":​ {
         "​output":​ ["​name"​],​         "​output":​ ["​name"​],​
-        "hostids":​ 10502, +        "severities": [34]
-        "​selectTags": ["​tag"​"​value"​],​ +
-        "​selectInheritedTags":​ ["​tag",​ "​value"​]+
     },     },
     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​     "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​
Line 511: Line 529:
     "​result":​ [     "​result":​ [
         {         {
-            "​hostid":​ "10502", +            "​hostid":​ "20170", 
-            "​name":​ "Desktop", +            "​name":​ "Database
-            "​tags":​ [ +        }, 
-                { +        
-                    "​tag":​ "​A",​ +            "hostid": "20183", 
-                    "​value":​ "​1"​ +            "name": "workstation"
-                ​} +
-            ]+
-            "​inheritedTags":​ [ +
-                ​+
-                    "tag": "B", +
-                    "value": "2" +
-                } +
-            ]+
         }         }
     ],     ],
Line 530: Line 540:
 } }
 </​code>​ </​code>​
- 
  
 ==== See also ==== ==== See also ====
Line 541: Line 550:
 ==== Source ==== ==== Source ====
  
-CHost::​get() in //frontends/​php/​include/​classes/​api/​services/​CHost.php//​.+CHost::​get() in //ui/​include/​classes/​api/​services/​CHost.php//​.