这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

获取

描述

integer/array drule.get(object parameters)

此方法允许根据给定参数检索发现规则。

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

参数

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

此方法支持以下参数。

参数 类型 描述
dhostids string/array 仅返回创建给定已发现主机的发现规则。
druleids string/array 仅返回具有给定 ID 的发现规则。
dserviceids string/array 仅返回创建给定已发现服务的发现规则。
selectDChecks query 返回 dchecks 属性,其中包含发现规则使用的发现检查。

支持 count
selectDHosts query 返回 dhosts 属性,其中包含由发现规则创建的已发现主机。

Supports count.
limitSelects integer 限制子选择返回的记录数。

适用于以下子选择:
selectDChecks - 结果将按照 dcheckid 排序;
selectDHosts - 结果将按照 dhostsid 排序。
sortfield string/array 根据给定的属性对结果进行排序。

可用值:druleidname
countOutput boolean 这些参数对于所有的 get 方法都是通用的,详细描述请参见 参考说明
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

(integer/array) 返回其中一种结果:

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

示例

检索所有发现规则

检索所有配置的发现规则及其使用的发现检查。

请求:

{
           "jsonrpc": "2.0",
           "method": "drule.get",
           "params": {
               "output": "extend",
               "selectDChecks": "extend"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "druleid": "2",
                   "proxy_hostid": "0",
                   "name": "Local network",
                   "iprange": "192.168.3.1-255",
                   "delay": "5s",
                   "nextcheck": "1348754327",
                   "status": "0",
                   "dchecks": [
                       {
                           "dcheckid": "7",
                           "druleid": "2",
                           "type": "3",
                           "key_": "",
                           "snmp_community": "",
                           "ports": "21",
                           "snmpv3_securityname": "",
                           "snmpv3_securitylevel": "0",
                           "snmpv3_authpassphrase": "",
                           "snmpv3_privpassphrase": "",
                           "uniq": "0",
                           "snmpv3_authprotocol": "0",
                           "snmpv3_privprotocol": "0",
                           "host_source": "1",
                           "name_source": "0"                     
                       },
                       {
                           "dcheckid": "8",
                           "druleid": "2",
                           "type": "4",
                           "key_": "",
                           "snmp_community": "",
                           "ports": "80",
                           "snmpv3_securityname": "",
                           "snmpv3_securitylevel": "0",
                           "snmpv3_authpassphrase": "",
                           "snmpv3_privpassphrase": "",
                           "uniq": "0",
                           "snmpv3_authprotocol": "0",
                           "snmpv3_privprotocol": "0",
                           "host_source": "1",
                           "name_source": "0"                    
                       }
                   ]
               },
               {
                   "druleid": "6",
                   "proxy_hostid": "0",
                   "name": "Zabbix agent discovery",
                   "iprange": "192.168.1.1-255",
                   "delay": "1h",
                   "nextcheck": "0",
                   "status": "0",
                   "dchecks": [
                       {
                           "dcheckid": "10",
                           "druleid": "6",
                           "type": "9",
                           "key_": "system.uname",
                           "snmp_community": "",
                           "ports": "10050",
                           "snmpv3_securityname": "",
                           "snmpv3_securitylevel": "0",
                           "snmpv3_authpassphrase": "",
                           "snmpv3_privpassphrase": "",
                           "uniq": "0",
                           "snmpv3_authprotocol": "0",
                           "snmpv3_privprotocol": "0",
                           "host_source": "2",
                           "name_source": "3"                    
                       }
                   ]
               }
           ],
           "id": 1
       }

参见

来源

ui/include/classes/api/services/CDRule.php 中的 CDRule::get()。