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.

itemprototype.create

説明

object itemprototype.create(object/array itemPrototypes)

このメソッドは新しいアイテムプロトタイプを作成します。

このメソッドは管理者およびスーパ管理者ユーザータイプでのみ利用可能です。メソッドの呼び出し権限はユーザーロールの設定で取り消すことができます。詳細はユーザーロールを参照してください。

パラメータ

(object/array) 作成するアイテムプロトタイプ。

標準のアイテムプロトタイププロパティに加えて、このメソッドは以下のパラメータを受け付けます。

パラメータ タイプ 説明
ruleid ID アイテムが属するLLDルールのID。

パラメータの動作:
- 必須
preprocessing array アイテムプロトタイプの事前処理オプション。
tags array アイテムプロトタイプのタグ

戻り値

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

アイテムプロトタイプの作成

検出されたファイルシステムの空きディスク容量を監視するアイテムプロトタイプを作成します。検出されたアイテムは、30秒ごとに更新される数値型のZabbixエージェントアイテムである必要があります。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.create",
           "params": {
               "name": "Free disk space on {#FSNAME}",
               "key_": "vfs.fs.size[{#FSNAME},free]",
               "hostid": "10197",
               "ruleid": "27665",
               "type": 0,
               "value_type": 3,
               "interfaceid": "112",
               "delay": "30s"
           },
           "id": 1
       }

レスポンス:

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

前処理付きアイテムプロトタイプの作成

1秒あたりの変化量とカスタム乗数を2番目のステップとして使用してアイテムを作成します。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.create",
           "params": {
               "name": "Incoming network traffic on {#IFNAME}",
               "key_": "net.if.in[{#IFNAME}]",
               "hostid": "10001",
               "ruleid": "27665",
               "type": 0,
               "value_type": 3,
               "delay": "60s",
               "units": "bps",
               "interfaceid": "1155",
               "preprocessing": [
                   {
                       "type": 10,
                       "params": "",
                       "error_handler": 0,
                       "error_handler_params": ""
                   },
                   {
                       "type": 1,
                       "params": "8",
                       "error_handler": 2,
                       "error_handler_params": "10"
                   }
               ]
           },
           "id": 1
       }

レスポンス:

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

依存アイテムプロトタイプの作成

ID 44211のマスターアイテムプロトタイプに対して依存アイテムプロトタイプを作成します。 同じホスト(テンプレート/ディスカバリールール)でのみ依存関係が許可されているため、マスターと依存アイテムは同じhostidおよびruleidを持つ必要があります。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.create",
           "params": {
             "hostid": "10001",
             "ruleid": "27665",
             "name": "Dependent test item prototype",
             "key_": "dependent.prototype",
             "type": 18,
             "master_itemid": "44211",
             "value_type": 3
           },
           "id": 1
       }

レスポンス:

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

HTTPエージェントのアイテムプロトタイプの作成

ユーザーマクロ、クエリフィールド、カスタムヘッダーを使用したURLでアイテムプロトタイプを作成します。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.create",
           "params": {
               "type": "19",
               "hostid": "10254",
               "ruleid": "28256",
               "interfaceid": "2",
               "name": "api item prototype example",
               "key_": "api_http_item",
               "value_type": 3,
               "url": "{$URL_PROTOTYPE}",
               "query_fields": [
                   {
                       "name": "min",
                       "value": "10"
                   },
                   {
                       "name": "max",
                       "value" "100"
                   }
               ],
               "headers": [
                   {
                       "name": "X-Source",
                       "value": "api"
                   }
               ],
               "delay": "35"
           },
           "id": 1
       }

レスポンス:

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

スクリプトアイテムプロトタイプの作成

スクリプトアイテムプロトタイプを使用してシンプルなデータ収集を作成します。

リクエスト:

{
           "jsonrpc": "2.0",
           "method": "itemprototype.create",
           "params": {
               "name": "Script example",
               "key_": "custom.script.itemprototype",
               "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
       }

レスポンス:

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

ソース

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