这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

获取

描述

integer/array discoveryrule.get(object parameters)

该方法允许根据给定的参数检索 LLD 规则。

此方法对于任何用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看 用户角色

参数

(object)定义所需输出的参数。

该方法支持以下参数。

参数 类型 描述
itemids ID/array 只返回具有给定IDs的LLD规则。
groupids ID/array 只返回属于给定组的LLD规则。
hostids ID/array 只返回属于给定主机的LLD规则。
inherited boolean 如果设置为true,则只返回从模板继承的LLD规则。
interfaceids ID/array 只返回使用给定主机接口的LLD规则。
monitored boolean 如果设置为true,则只返回属于被监控主机的启用的LLD规则。
templated boolean 如果设置为true,则只返回属于模板的LLD规则。
templateids ID/array 只返回属于给定模板的LLD规则。
selectFilter query 返回一个filter属性,包含LLD规则使用的过滤器数据。
selectGraphs query 返回一个graphs属性,包含属于LLD规则的图表原型。支持count
selectHostPrototypes query 返回一个hostPrototypes属性,包含属于LLD规则的主机原型。支持count
selectHosts query 返回一个hosts属性,包含LLD规则所属的主机数组。
selectItems query 返回一个items属性,包含属于LLD规则的监控项原型。支持count
selectTriggers query 返回一个triggers属性,包含属于LLD规则的触发器原型。支持count
selectLLDMacroPaths query 返回一个lld_macro_paths属性,包含LLD宏和分配给每个相应宏的值路径列表。
selectPreprocessing query 返回一个preprocessing属性,包含LLD规则的预处理选项。
selectOverrides query 返回一个lld_rule_overrides属性,包含对原型对象执行的覆盖过滤器、条件和操作的列表。
filter object 只返回完全符合给定过滤器的结果。接受一个对象,其中键是属性名称,值是单一值或要匹配的值数组。不支持text 数据类型的属性。支持额外属性:host - LLD规则所属的主机的技术名称。
limitSelects integer 限制子选择返回的记录数。适用于以下子选择:selectItems, selectGraphs, selectTriggers
sortfield string/array 根据给定属性对结果进行排序。可能的值:itemid, name, key_, delay, type, status
countOutput boolean 这些参数对于所有get方法都是通用的,在参考注释中有详细描述。
editable boolean
excludeSearch boolean
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

(integer/array) 返回任一值:

  • 对象数组;
  • 检索到的对象的计数,如果使用了 countOutput 参数。

示例

检索主机发现规则

返回主机"10202"所有自动发现规则。

请求

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

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "27425",
                   "type": "0",
                   "snmp_oid": "",
                   "hostid": "10202",
                   "name": "Network interface discovery",
                   "key_": "net.if.discovery",
                   "delay": "1h",
                   "status": "0",
                   "trapper_hosts": "",
                   "templateid": "22444",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "interfaceid": "119",
                   "description": "Discovery of network interfaces as defined in global regular expression \"Network interfaces for discovery\".",
                   "lifetime": "30d",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "lifetime_type": "0",
                   "enabled_lifetime_type": "2",
                   "enabled_lifetime": "0",
                   "state": "0",
                   "error": "",
                   "parameters": []
               },
               {
                   "itemid": "27426",
                   "type": "0",
                   "snmp_oid": "",
                   "hostid": "10202",
                   "name": "Mounted filesystem discovery",
                   "key_": "vfs.fs.discovery",
                   "delay": "1h",
                   "status": "0",
                   "trapper_hosts": "",
                   "templateid": "22450",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "interfaceid": "119",
                   "description": "Discovery of file systems of different types as defined in global regular expression \"File systems for discovery\".",
                   "lifetime": "30d",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "",
                   "query_fields": [],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [],
                   "retrieve_mode": "0",
                   "request_method": "0",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "lifetime_type": "0",
                   "enabled_lifetime_type": "2",
                   "enabled_lifetime": "0",
                   "state": "0",
                   "error": "",
                   "parameters": []
               }
           ],
           "id": 1
       }

检索过滤条件

检索 LLD 规则的名称“24681”及其过滤条件。过滤器使用“and”求值类型,因此 formula 属性为空,并自动生成 eval_formula

请求

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

响应:

{
           "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": "9",
                               "formulaid": "B"
                           },
                           {
                               "macro": "{#MACRO3}",
                               "value": "",
                               "operator": "12",
                               "formulaid": "C"
                           },
                           {
                               "macro": "{#MACRO4}",
                               "value": "",
                               "operator": "13",
                               "formulaid": "D"
                           }
                       ],
                       "eval_formula": "A and B and C and D"
                   }
               }
           ],
           "id": 1
       }

通过 URL 检索 LLD 规则

通过规则 URL 字段值检索主机的 LLD 规则。仅支持为 LLD 规则定义的 URL 字符串的完全匹配。

请求

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.get",
           "params": {
               "hostids": "10257",
               "filter": {
                   "type": 19,
                   "url": "http://127.0.0.1/discoverer.php"
               }
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "28336",
                   "type": "19",
                   "snmp_oid": "",
                   "hostid": "10257",
                   "name": "API HTTP agent",
                   "key_": "api_discovery_rule",
                   "delay": "5s",
                   "status": "0",
                   "trapper_hosts": "",
                   "templateid": "0",
                   "valuemapid": "0",
                   "params": "",
                   "ipmi_sensor": "",
                   "authtype": "0",
                   "username": "",
                   "password": "",
                   "publickey": "",
                   "privatekey": "",
                   "interfaceid": "5",
                   "description": "",
                   "lifetime": "30d",
                   "jmx_endpoint": "",
                   "master_itemid": "0",
                   "timeout": "",
                   "url": "http://127.0.0.1/discoverer.php",
                   "query_fields": [
                       {
                           "name": "mode",
                           "value": "json"
                       },
                       {
                           "name": "elements",
                           "value": "2"
                       }
                   ],
                   "posts": "",
                   "status_codes": "200",
                   "follow_redirects": "1",
                   "post_type": "0",
                   "http_proxy": "",
                   "headers": [
                       {
                           "name" : "X-Type",
                           "value": "api"
                       },
                       {
                           "name": "Authorization",
                           "value": "Bearer mF_A.B5f-2.1JcM"
                       }
                   ],
                   "retrieve_mode": "0",
                   "request_method": "1",
                   "ssl_cert_file": "",
                   "ssl_key_file": "",
                   "ssl_key_password": "",
                   "verify_peer": "0",
                   "verify_host": "0",
                   "allow_traps": "0",
                   "uuid": "",
                   "lifetime_type": "0",
                   "enabled_lifetime_type": "2",
                   "enabled_lifetime": "0",
                   "state": "0",
                   "error": "",
                   "parameters": []
               }
           ],
           "id": 1
       }

使用覆盖检索 LLD 规则

检索一个具有多种覆盖设置的LLD规则。

请求

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.get",
           "params": {
               "output": ["name"],
               "itemids": "30980",
               "selectOverrides": ["name", "step", "stop", "filter", "operations"]
           },
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "name": "Discover database host",
                   "overrides": [
                       {
                           "name": "Discover MySQL host",
                           "step": "1",
                           "stop": "1",
                           "filter": {
                               "evaltype": "2",
                               "formula": "",
                               "conditions": [
                                   {
                                       "macro": "{#UNIT.NAME}",
                                       "operator": "8",
                                       "value": "^mysqld\\.service$",
                                       "formulaid": "A"
                                   },
                                   {
                                       "macro": "{#UNIT.NAME}",
                                       "operator": "8",
                                       "value": "^mariadb\\.service$",
                                       "formulaid": "B"
                                   }
                               ],
                               "eval_formula": "A or B"
                           },
                           "operations": [
                               {
                                   "operationobject": "3",
                                   "operator": "2",
                                   "value": "Database host",
                                   "opstatus": {
                                       "status": "0"
                                   },
                                   "optag": [
                                       {
                                           "tag": "Database",
                                           "value": "MySQL"
                                       }
                                   ],
                                   "optemplate": [
                                       {
                                           "templateid": "10170"
                                       }
                                   ]
                               }
                           ]
                       },
                       {
                           "name": "Discover PostgreSQL host",
                           "step": "2",
                           "stop": "1",
                           "filter": {
                               "evaltype": "0",
                               "formula": "",
                               "conditions": [
                                   {
                                       "macro": "{#UNIT.NAME}",
                                       "operator": "8",
                                       "value": "^postgresql\\.service$",
                                       "formulaid": "A"
                                   }
                               ],
                               "eval_formula": "A"
                           },
                           "operations": [
                               {
                                   "operationobject": "3",
                                   "operator": "2",
                                   "value": "Database host",
                                   "opstatus": {
                                       "status": "0"
                                   },
                                   "optag": [
                                       {
                                           "tag": "Database",
                                           "value": "PostgreSQL"
                                       }
                                   ],
                                   "optemplate": [
                                       {
                                           "templateid": "10263"
                                       }
                                   ]
                               }
                           ]
                       }
                   ]
               }
           ],
           "id": 1
       }

参阅

来源

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