You are viewing documentation for the development version, it may be incomplete.
Join our translation project and help translate Zabbix documentation into your native language.

discoveryrule.create

Beschrijving

object discoveryrule.create(object/array lldRules)

Deze methode maakt het mogelijk om nieuwe LLD-regels te maken.

Deze methode is alleen beschikbaar voor gebruikerstypes Admin en Superadmin. Rechten om de methode aan te roepen kunnen worden ingetrokken in de instellingen van gebruikersrollen. Zie Gebruikersrollen voor meer informatie.

Parameters

(object/array) LLD-regels om te creëren.

Naast de standaard LLD-regel eigenschappen, accepteert de methode de volgende parameters.

Parameter Type Omschrijving
filter object LLD-regel filter voor de LLD-regel.
preprocessing array LLD-regel preprocessing opties.
lld_macro_paths array LLD-regel lld_macro_path opties.
overrides array LLD-regel overrides opties.

retourwaarden

(object) Geeft een object terug dat de ID's van de gemaakte LLD-regels bevat onder de eigenschap itemids. De volgorde van de teruggegeven ID's komt overeen met de volgorde van de doorgegeven LLD-regels.

Voorbeelden

LLD-regel creëren

Creëer een Zabbix agent LLD-regel om gemounte bestandssystemen te ontdekken. Ontdekte items worden elke 30 seconden bijgewerkt.

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Ontdekking van gemounte bestandssystemen",
               "key_": "vfs.fs.discovery",
               "hostid": "10197",
               "type": 0,
               "interfaceid": "112",
               "delay": "30s"
           },
           "id": 1
       }

Reactie:

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

Gebruik van een filter

Creëer een LLD-regel met een reeks voorwaarden om de resultaten te filteren. De voorwaarden zullen worden gegroepeerd met behulp van de logische "en" operator.

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Gefilterde LLD-regel",
               "key_": "lld",
               "hostid": "10116",
               "type": 0,
               "interfaceid": "13",
               "delay": "30s",
               "filter": {
                   "evaltype": 1,
                   "conditions": [
                       {
                           "macro": "{#MACRO1}",
                           "value": "@regex1"
                       },
                       {
                           "macro": "{#MACRO2}",
                           "value": "@regex2",
                           "operator": "9"
                       },
                       {
                           "macro": "{#MACRO3}",
                           "value": "",
                           "operator": "12"
                       },
                       {
                           "macro": "{#MACRO4}",
                           "value": "",
                           "operator": "13"
                       }
                   ]
               }
           },
           "id": 1
       }

Reactie:

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

Creëren van een LLD-regel met LLD-macro-paden

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "LLD-regel met LLD-macro-paden",
               "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"
                   }
               ]
           },
           "id": 1
       }

Reactie:

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

Gebruik van een aangepaste expressie-filter

Creëer een LLD-regel met een filter dat een aangepaste expressie zal gebruiken om de voorwaarden te evalueren. De LLD-regel moet alleen objecten ontdekken waarvan de waarde van de "{#MACRO1}"-macro zowel overeenkomt met de reguliere expressies "regex1" en "regex2", en de waarde van "{#MACRO2}" overeenkomt met ofwel "regex3" of "regex4". De formule-ID's "A", "B", "C" en "D" zijn willekeurig gekozen.

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Gefilterde LLD-regel",
               "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"
                       }
                   ]
               }
           },
           "id": 1
       }

Reactie:

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

Gebruik van aangepaste query-velden en headers

Creëer een LLD-regel met aangepaste query-velden en headers.

Aanvraag:

{
           "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": 1
       }

Reactie:

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

LLD-regel creëren met preprocessing

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "LLD-regel met preprocessing",
               "key_": "lld.met.preprocessing",
               "hostid": "10001",
               "ruleid": "27665",
               "type": 0,
               "value_type": 3,
               "delay": "60s",
               "interfaceid": "1155",
               "preprocessing": [
                   {
                       "type": 20,
                       "params": "20",
                       "error_handler": 0,
                       "error_handler_params": ""
                   }
               ]
           },
           "id": 1
       }

Reactie:

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

LLD-regel creëren met overrides

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Ontdek database host",
               "key_": "lld.met.overrides",
               "hostid": "10001",
               "type": 0,
               "value_type": 3,
               "delay": "60s",
               "interfaceid": "1155",
               "overrides": [
                   {
                       "name": "Ontdek 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"
                                   }
                               ],
                               "optag": [
                                   {
                                       "tag": "Database",
                                       "value": "MySQL"
                                   }
                               ]
                           }
                       ]
                   },
                   {
                       "name": "Ontdek 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"
                                   }
                               ],
                               "optag": [
                                   {
                                       "tag": "Database",
                                       "value": "PostgreSQL"
                                   }
                               ]
                           }
                       ]
                   }
               ]
           },
           "id": 1
       }

Reactie:

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

Script LLD-regel creëren

Creëer een eenvoudige gegevensverzameling met behulp van een script LLD-regel.

Aanvraag:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Voorbeeld script",
               "key_": "custom.script.lldrule",
               "hostid": "12345",
               "type": 21,
               "value_type": 4,
               "params": "var request = new HttpRequest();\nreturn request.post(\"https://postman-echo.com/post\", JSON.parse(value));",
               "parameters": [{
                   "name": "host",
                   "value": "{HOST.CONN}"
               }],
               "timeout": "6s",
               "delay": "30s"
           },
           "id": 1
       }

Reactie:

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

Create LLD rule with a specified time period for disabling and no deletion

Create an LLD rule with custom time period for disabling entity after it is no longer discovered, with the setting that it will never be deleted.

Request:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "lld disable after 1h",
               "key_": "lld.disable",
               "hostid": "10001",
               "type": 2,
               "lifetime_type": 1,
               "enabled_lifetime_type": 0, 
               "enabled_lifetime": "1h"
           },
           "id": 1
       }

Response:

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

Zie ook

Bron

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