[comment]: # ({2709706a-2709706a})
# discoveryrule.create

[comment]: # ({/2709706a-2709706a})

[comment]: # ({bb15db7c-bb15db7c})
### Description

`object discoveryrule.create(object/array lldRules)`

This method allows to create new LLD rules.

[comment]: # ({/bb15db7c-bb15db7c})

[comment]: # ({e9f0c229-1c165cc1})
### Parameters

`(object/array)` LLD rules to create.

Additionally to the [standard LLD rule properties](object#lld_rule), the
method accepts the following parameters.

|Parameter|[Type](/manual/api/reference_commentary#data_types)|Description|
|--|--|------|
|filter|object|LLD rule [filter](/manual/api/reference/discoveryrule/object#lld_rule_filter) object for the LLD rule.|
|preprocessing|array|LLD rule [preprocessing](/manual/api/reference/discoveryrule/object#lld_rule_preprocessing) options.|
|lld\_macro\_paths|array|LLD rule [lld\_macro\_path](/manual/api/reference/discoveryrule/object#lld_macro_path) options.|
|overrides|array|LLD rule [overrides](/manual/api/reference/discoveryrule/object#lld_rule_overrides) options.|

[comment]: # ({/e9f0c229-1c165cc1})

[comment]: # ({08a72633-08a72633})
### Return values

`(object)` Returns an object containing the IDs of the created LLD rules
under the `itemids` property. The order of the returned IDs matches the
order of the passed LLD rules.

[comment]: # ({/08a72633-08a72633})

[comment]: # ({b41637d2-b41637d2})
### Examples

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({c30fe277-c30fe277})
#### Creating an LLD rule

Create a Zabbix agent LLD rule to discover mounted file systems.
Discovered items will be updated every 30 seconds.

Request:

``` {.java}
{
    "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
}
```

Response:

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

[comment]: # ({/c30fe277-c30fe277})

[comment]: # ({45a77a7c-45a77a7c})
#### Using a filter

Create an LLD rule with a set of conditions to filter the results by.
The conditions will be grouped together using the logical "and"
operator.

Request:

``` {.java}
{
    "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
}
```

Response:

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

[comment]: # ({/45a77a7c-45a77a7c})

[comment]: # ({a201a7a1-a201a7a1})
#### Creating a LLD rule with macro paths

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "LLD rule with LLD macro paths",
        "key_": "lld",
        "hostid": "10116",
        "type": "0",
        "interfaceid": "13",
        "delay": "30s",
        "lld_macro_paths": [
            {
                "lld_macro": "{#MACRO1}",
                "path": "$.path.1"
            },
            {
                "lld_macro": "{#MACRO2}",
                "path": "$.path.2"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

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

[comment]: # ({/a201a7a1-a201a7a1})

[comment]: # ({32af137e-32af137e})
#### Using a custom expression filter

Create an LLD rule with a filter that will use a custom expression to
evaluate the conditions. The LLD rule must only discover objects the
"{\#MACRO1}" macro value of which matches both regular expression
"regex1" and "regex2", and the value of "{\#MACRO2}" matches either
"regex3" or "regex4". The formula IDs "A", "B", "C" and "D" have been
chosen arbitrarily.

Request:

``` {.java}
{
    "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
}
```

Response:

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

[comment]: # ({/32af137e-32af137e})

[comment]: # ({001d915b-001d915b})
#### Using custom query fields and headers

Create LLD rule with custom query fields and headers.

Request:

``` {.java}
{
    "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",
    }
}
```

Response:

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

[comment]: # ({/001d915b-001d915b})

[comment]: # ({2ba2c85c-2ba2c85c})
#### Creating a LLD rule with preprocessing

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "discoveryrule.create",
    "params": {
        "name": "Discovery rule with preprocessing",
        "key_": "lld.with.preprocessing",
        "hostid": "10001",
        "type": 0,
        "value_type": 3,
        "delay": "60s",
        "interfaceid": "1155",
        "preprocessing": [
            {
                "type": "20",
                "params": "20",
                "error_handler": "0",
                "error_handler_params": ""
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "itemids": [
            "44211"
        ]
    },
    "id": 1
}
```

[comment]: # ({/2ba2c85c-2ba2c85c})

[comment]: # ({39fcfff5-39fcfff5})
#### Creating a LLD rule with overrides

Request:

``` {.java}
{
    "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:

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

[comment]: # ({/39fcfff5-39fcfff5})

[comment]: # ({f40c8a6e-f40c8a6e})
### See also

-   [LLD rule filter](object#lld_rule_filter)
-   [LLD macro paths](object#lld_macro_path)
-   [LLD rule preprocessing](object#lld_rule_preprocessing)

[comment]: # ({/f40c8a6e-f40c8a6e})

[comment]: # ({73c4009f-73c4009f})
### Source

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

[comment]: # ({/73c4009f-73c4009f})
