获取

描述

integer/array discoveryrule.get(object parameters)

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

此方法对任何类型的用户都可用。 调用该方法的权限可在用户角色设置中撤销。 更多信息请参见 用户角色

参数

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

该方法支持以下参数。

参数 类型 说明
itemids ID/array 仅返回具有给定 ID 的 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 规则。
selectDiscoveryData query 返回 discoveryData 属性,其中包含 LLD 规则发现对象数据。LLD 规则发现对象将已发现的 LLD 规则关联到发现该规则的 LLD 规则原型。
selectDiscoveryRulePrototypes query 返回 discoveryRulePrototypes 属性,其中包含属于该 LLD 规则的 LLD 规则原型。

支持 count
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 data type 的属性。

支持附加属性:
host - LLD 规则所属主机的技术名称。
limitSelects integer 限制子选择返回的记录数。

适用于以下子选择:selectItemsselectGraphsselectTriggers
sortfield string/array 按给定属性对结果进行排序。

可能的值:itemidnamekey_delaytypestatus
countOutput boolean 这些参数在参考说明中进行了描述。
editable boolean
excludeSearch boolean
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

(integer/array) 返回以下之一:

  • 对象数组
  • 如果使用了 countOutput 参数,则返回检索到的对象数量。

示例

从主机中检索发现规则

检索指定主机 ID 的所有发现规则。

请求

{
    "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": "",
            "flags": "1",
            "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",
            "output_format": "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": "",
            "flags": "1",
            "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",
            "output_format": "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": "",
            "flags": "1",
            "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",
            "output_format": "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 规则

获取一个具有多种覆盖项设置的 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
}

另请参阅

源代码

位于 ui/include/classes/api/services/CDiscoveryRule.php 中的 CDiscoveryRule::get()。