This is a translation of the original English documentation page. Help us make it better.

discoveryrule.create

説明

object discoveryrule.create(object/array lldRules)

このメソッドは、新しいLLDルールを作成することができます。

このメソッドは、AdminおよびSuper adminタイプのユーザーのみ利用可能です。メソッドを呼び出す権限は、ユーザーの役割の設定で取り消すことができます。 詳細はユーザーの役割を参照してください。

パラメーター

(object/array) 作成するLLDルール。

標準LLDルールプロパティに加えて、メソッドは次のパラメーターをサポートします。

パラメーター タイプ 説明
filter object LLDルールのLLDルールフィルターオブジェクト。
preprocessing object/array LLDルール事前処理オプション。
lld_macro_paths object/array LLDルール lld_macro_pathオプション。
overrides object/array LLDルールオーバーライドオプション。

戻り値

(object) itemidsプロパティの下で作成されたLLDルールのIDを含むオブジェクトを返します。 返されるIDの順序は、渡されたLLDルールの順序と一致します。

LLDルールの作成

ZabbixエージェントLLDルールを作成して、マウントされたファイルシステムを検出します。 発見されたアイテムは30秒ごとに更新されます。

Request:

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

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

フィルタを使用

結果をフィルタリングするための一連の条件を使用してLLDルールを作成します。 条件は、論理"and"演算子を使用してグループ化されます。

Request:

{
           "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",
                           "operator": "9"
                       },
                       {
                           "macro": "{#MACRO3}",
                           "value": "",
                           "operator": "12"
                       },
                       {
                           "macro": "{#MACRO4}",
                           "value": "",
                           "operator": "13"
                       }
                   ]
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

マクロパスを使用したLLDルールの作成

Request:

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

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

カスタム式フィルターの使用

カスタム式を使用して条件を評価するフィルターでLLDルールを作成します。 LLDルールは"{#MACRO1}"マクロ値が正規表現"regex1"と"regex2"の両方に一致し、"{#MACRO2}"の値が"regex3"または"regex4"のいずれかに一致するオブジェクトのみを検出する必要があります。 式ID"A",B","C","D"は任意に選択されています。

Request:

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

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

カスタムクエリフィールドとヘッダーの使用

カスタムクエリフィールドとヘッダーを使用してLLDルールを作成します。

Request:

{
           "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"
           },
           "auth": "d678e0b85688ce578ff061bd29a20d3b",
           "id": 1
       }

Response:

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

事前処理を使用したLLDルールの作成

Request:

{
           "jsonrpc": "2.0",
           "method": "discoveryrule.create",
           "params": {
               "name": "Discovery rule with preprocessing",
               "key_": "lld.with.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": ""
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

オーバーライドを使用したLLDルールの作成

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"
                                   }
                               ],
                               "optag": [
                                   {
                                       "tag": "Database",
                                       "value": "MySQL"
                                   }
                               ]
                           }
                       ]
                   },
                   {
                       "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"
                                   }
                               ],
                               "optag": [
                                   {
                                       "tag": "Database",
                                       "value": "PostgreSQL"
                                   }
                               ]
                           }
                       ]
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

スクリプトLLDルールを作成する

スクリプトLLDルールを使用して単純なデータコレクションを作成します。

Request:

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

Response:

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

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
       }

参照

ソース

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