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

创建

说明

object discoveryrule.create(object/array lldRules)

此方法允许创建新的LLD规则。

参数

(object/array) 要创建的LLD规则。

除了标准LLD规则属性之外,该方法还接受以下参数。

属性 类 描述
filter object LLD规则LLD规则的过滤对象
preprocessing array LLD规则预处理选项
lld_macro_paths array LLD规则预处理选项
overrides array LLD规则覆盖选项

返回值

(object)itemids属性下返回一个包含IDs的被创建的LLD规则。返回的IDs的顺序与传递的LLD规则顺序相匹配。

示例

新建LLD规则

创建Zabbix agent LLD规则去发现以已装入的文件系统。发现监控项(items)将被每30s被更新一次。

请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Mounted filesystem discovery",
               "key_": "vfs.fs.discovery",
               "hostid": "10197",
               "type": "0",
               "interfaceid": "112",
               "delay": "30s"
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "27665"
               ]
           },
           "id": 1
       }

使用一个过滤器

创建有由一套删选条件的得到的LLD规则。这些条件将使用逻辑“和”运算符将条件组合在一起。

请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Filtered LLD rule",
               "key_": "lld",
               "hostid": "10116",
               "type": "0",
               "interfaceid": "13",
               "delay": "30s",
               "filter": {
                   "evaltype": 1,
                   "conditions": [
                       {
                           "macro": "{#MACRO1}",
                           "value": "@regex1"
                       },
                       {
                           "macro": "{#MACRO2}",
                           "value": "@regex2"
                       },
                       {
                           "macro": "{#MACRO3}",
                           "value": "@regex3"
                       }
                   ]
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "27665"
               ]
           },
           "id": 1
       }

使用自定义表达式的筛选器

创建一个带有过滤器的LLD规则,该过滤器将使用自定义表达式来计算条件。LLD规则必须只发现“{#MACRO1}”宏值同时匹配正则表达式“regex1”和“regex2”的对象,“{#MACRO2}”宏值同时匹配“regex3”或“regex4”的对象。公式id“A”、“B”、“C”和“D”是任意选择的。

请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Filtered LLD rule",
               "key_": "lld",
               "hostid": "10116",
               "type": "0",
               "interfaceid": "13",
               "delay": "30s",
               "filter": {
                   "evaltype": 3,
                   "formula": "(A and B) and (C or D)",
                   "conditions": [
                       {
                           "macro": "{#MACRO1}",
                           "value": "@regex1",
                           "formulaid": "A"
                       },
                       {
                           "macro": "{#MACRO1}",
                           "value": "@regex2",
                           "formulaid": "B"
                       },
                       {
                           "macro": "{#MACRO2}",
                           "value": "@regex3",
                           "formulaid": "C"
                       },
                       {
                           "macro": "{#MACRO2}",
                           "value": "@regex4",
                           "formulaid": "D"
                       }
                   ]
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "27665"
               ]
           },
           "id": 1
       }

使用自定义查询字段和报头

创建具有自定义查询字段和标题的LLD规则。

请求:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "hostid": "10257",
               "interfaceid": "5",
               "type": "19",
               "name": "API HTTP agent",
               "key_": "api_discovery_rule",
               "value_type": "3",
               "delay": "5s",
               "url": "http://127.0.0.1?discoverer.php",
               "query_fields": [
                   {
                       "mode": "json"
                   },
                   {
                       "elements":"2"
                   }
               ],
               "headers": {
                   "X-Type": "api",
                   "Authorization": "Bearer mF_A.B5f-2.1JcM"
               },
               "allow_traps": "1",
               "trapper_hosts": "127.0.0.1",
               "id": 35,
               "auth": "d678e0b85688ce578ff061bd29a20d3b",
           }
       }

响应:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "28336"
               ]
           },
           "id": 35
       }

参见

来源

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

Creating a LLD rule with overrides

Request:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Discover database host",
               "key_": "lld.with.overrides",
               "hostid": "10001",
               "type": 0,
               "value_type": 3,
               "delay": "60s",
               "interfaceid": "1155",
               "overrides": [
                   {
                       "name": "Discover MySQL host",
                       "step": "1",
                       "stop": "1",
                       "filter": {
                           "evaltype": "2",
                           "conditions": [
                               {
                                   "macro": "{#UNIT.NAME}",
                                   "operator": "8",
                                   "value": "^mysqld\\.service$"
                               },
                               {
                                   "macro": "{#UNIT.NAME}",
                                   "operator": "8",
                                   "value": "^mariadb\\.service$"
                               }
                           ]
                       },
                       "operations": [
                           {
                               "operationobject": "3",
                               "operator": "2",
                               "value": "Database host",
                               "opstatus": {
                                   "status": "0"
                               },
                               "optemplate": [
                                   {
                                       "templateid": "10170"
                                   }
                               ]
                           }
                       ]
                   },
                   {
                       "name": "Discover PostgreSQL host",
                       "step": "2",
                       "stop": "1",
                       "filter": {
                           "evaltype": "0",
                           "conditions": [
                               {
                                   "macro": "{#UNIT.NAME}",
                                   "operator": "8",
                                   "value": "^postgresql\\.service$"
                               }
                           ]
                       },
                       "operations": [
                           {
                               "operationobject": "3",
                               "operator": "2",
                               "value": "Database host",
                               "opstatus": {
                                   "status": "0"
                               },
                               "optemplate": [
                                   {
                                       "templateid": "10263"
                                   }
                               ]
                           }
                       ]
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "itemids": [
                   "30980"
               ]
           },
           "id": 1
       }

See also

Source

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