item.create

説明

object item.create(object/array items)

このメソッドを使用すると、新しいアイテムを作成できます。

Zabbix API を介して Web アイテムを作成することはできません。

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

パラメータ

(object/array) 作成するアイテム

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

パラメータ タイプ 説明
preprocessing array アイテムの 事前処理 オプション
tags array アイテムタグ

戻り値

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

例

アイテムの作成

ID"30074"のホストの空きディスク容量を監視するために、2 つのアイテム タグを持つ数値の Zabbix エージェント アイテムを作成します。

Request:

{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Free disk space on /home/joe/",
        "key_": "vfs.fs.size[/home/joe/,free]",
        "hostid": "30074",
        "type": 0,
        "value_type": 3,
        "interfaceid": "30084",
        "tags": [
            {
                "tag": "Disc usage"
            },
            {
                "tag": "Equipment",
                "value": "Workstation"
            }
        ],
        "delay": "30s"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

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

ホスト インベントリ アイテムの作成

ホストの"OS"インベントリフィールドに入力する Zabbix エージェント アイテムを作成します。

Request:

{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "uname",
        "key_": "system.uname",
        "hostid": "30021",
        "type": 0,
        "interfaceid": "30007",
        "value_type": 1,
        "delay": "10s",
        "inventory_link": 5
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

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

事前処理を伴うアイテムの作成

乗数を使用してアイテムを作成します

Request:

{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "name": "Device uptime",
        "key_": "sysUpTime",
        "hostid": "11312",
        "type": 4,
        "snmp_oid": "SNMPv2-MIB::sysUpTime.0",
        "value_type": 1,
        "delay": "60s",
        "units": "uptime",
        "interfaceid": "1156",
        "preprocessing": [
            {
                "type": 1,
                "params": "0.01",
                "error_handler": 1,
                "error_handler_params": ""
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

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

依存アイテムの作成

ID 24759 のマスター アイテムの依存アイテムを作成します。同じホストへの依存のみが許可されるため、マスターと依存アイテムは同じホスト ID を持つ必要があります。

Request:

{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
      "hostid": "30074",
      "name": "Dependent test item",
      "key_": "dependent.item",
      "type": 18,
      "master_itemid": "24759",
      "value_type": 2
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

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

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

JSONレスポンスの事前処理で POST リクエスト メソッド アイテムを作成します。

Request:

{
    "jsonrpc": "2.0",
    "method": "item.create",
    "params": {
        "url": "http://127.0.0.1/http.php",
        "query_fields": [
            {
                "mode": "json"
            },
            {
                "min": "10"
            },
            {
                "max": "100"
            }
        ],
        "interfaceid": "1",
        "type": 19,
        "hostid": "10254",
        "delay": "5s",
        "key_": "json",
        "name": "HTTP agent example JSON",
        "value_type": 0,
        "output_format": 1,
        "preprocessing": [
            {
                "type": 12,
                "params": "$.random",
                "error_handler": 0,
                "error_handler_params": ""
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 2
}

Response:

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

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

スクリプトアイテムを使用して簡単なデータコレクションを作成します。

Request:

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

ソース

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