2022 Zabbix中国峰会
2022 Zabbix中国峰会

discoveryrule.get

Description

integer/array discoveryrule.get(object parameters)

The method allows to retrieve LLD rules according to the given parameters.该方法允许根据给定的参数检索LLD规则。

Parameters 参数

(object) Parameters defining the desired output.定义所需输出的参数。

The method supports the following parameters.该方法支持以下参数。

属性 类 说明
itemids string/array Return only LLD rules with the given IDs.
hostids string/array Return only LLD rules that belong to the given hosts.
inherited boolean If set to true return only LLD rules inherited from a template.
interfaceids string/array Return only LLD rules use the given host interfaces.
monitored boolean If set to true return only enabled LLD rules that belong to monitored hosts.
templated boolean If set to true return only LLD rules that belong to templates.
templateids string/array Return only LLD rules that belong to the given templates.
selectFilter query Returns the filter used by the LLD rule in the filter property.
selectGraphs query Returns graph prototypes that belong to the LLD rule in the graphs property.

Supports count.
selectHostPrototypes query Returns host prototypes that belong to the LLD rule in the hostPrototypes property.

Supports count.
selectHosts query Returns the host that the LLD rule belongs to as an array in the hosts property.
selectItems query Returns item prototypes that belong to the LLD rule in the items property.

Supports count.
selectTriggers query Returns trigger prototypes that belong to the LLD rule in the triggers property.

Supports count.
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.

Supports additional filters:
host - technical name of the host that the LLD rule belongs to.
limitSelects integer Limits the number of records returned by subselects.

Applies to the following subselects:
selctItems;
selectGraphs;
selectTriggers.
sortfield string/array Sort the result by the given properties.

Possible values are: itemid, name, key_, delay, type and status.
countOutput flag These parameters being common for all get methods are described in detail in the reference commentary.
editable boolean
excludeSearch flag
limit integer
output query
preservekeys flag
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch flag

Return values 返回值

(integer/array) Returns either:

  • an array of objects;
  • the count of retrieved objects, if the countOutput parameter has been used.

Examples 示例

Retrieving discovery rules from a host

Retrieve all discovery rules from host "10202".

Request:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.get",
           "params": {
               "output": "extend",
               "hostids": "10202"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "27425",
                   "type": "0",
                   "snmp_community": "",
                   "snmp_oid": "",
                   "hostid": "10202",
                   "name": "Network interface discovery",
                   "key_": "net.if.discovery",
                   "delay": "1h",
                   "state": "0",
                   "status": "0",
                   "trapper_hosts": "",
                   "snmpv3_securityname": "",
                   "snmpv3_securitylevel": "0",
                   "snmpv3_authpassphrase": "",
                   "snmpv3_privpassphrase": "",
                   "error": "",
                   "templateid": "22444",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "interfaceid": "119",
                   "port": "",
                   "description": "Discovery of network interfaces as defined in global regular expression \"Network interfaces for discovery\".",
                   "lifetime": "30d",
                   "snmpv3_authprotocol": "0",
                   "snmpv3_privprotocol": "0"
               },
               {
                   "itemid": "27426",
                   "type": "0",
                   "snmp_community": "",
                   "snmp_oid": "",
                   "hostid": "10202",
                   "name": "Mounted filesystem discovery",
                   "key_": "vfs.fs.discovery",
                   "delay": "1h",
                   "state": "0",
                   "status": "0",
                   "trapper_hosts": "",
                   "snmpv3_securityname": "",
                   "snmpv3_securitylevel": "0",
                   "snmpv3_authpassphrase": "",
                   "snmpv3_privpassphrase": "",
                   "error": "",
                   "templateid": "22450",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "interfaceid": "119",
                   "port": "",
                   "description": "Discovery of file systems of different types as defined in global regular expression \"File systems for discovery\".",
                   "lifetime": "30d",
                   "snmpv3_authprotocol": "0",
                   "snmpv3_privprotocol": "0"
               }
           ],
           "id": 2
       }

Retrieving filter conditions

Retrieve the name of the LLD rule "24681" and its filter conditions. The filter uses the "and" evaluation type, so the formula property is empty and eval_formula is generated automatically.

Request:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.get",
           "params": {
               "output": [
                   "name"
               ],
               "selectFilter": "extend",
               "itemids": ["24681"]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "24681",
                   "name": "Filtered LLD rule",
                   "filter": {
                       "evaltype": "1",
                       "formula": "",
                       "conditions": [
                           {
                               "macro": "{#MACRO1}",
                               "value": "@regex1",
                               "operator": "8",
                               "formulaid": "A"
                           },
                           {
                               "macro": "{#MACRO2}",
                               "value": "@regex2",
                               "operator": "8",
                               "formulaid": "B"
                           },
                           {
                               "macro": "{#MACRO3}",
                               "value": "@regex3",
                               "operator": "8",
                               "formulaid": "C"
                           }
                       ],
                       "eval_formula": "A and B and C"
                   }
               }
           ],
           "id": 1
       }

See also 参见

Source 来源

CDiscoveryRule::get() in frontends/php/include/classes/api/services/CDiscoveryRule.php.