host.create

説明

object host.create(object/array hosts)

このメソッドでは、新しいホストを作成することができます。

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

パラメータ

(object/array) 作成するホスト

standard host propertiesに加えて、このメソッドは以下のパラメータを受け付けます。

パラメータ Type 説明
groups
(required)
object/array Host groups to add the host to.

The host groups must have the groupid property defined.
interfaces object/array Interfaces to be created for the host.
tags object/array Host tags.
templates object/array Templates to be linked to the host.

The templates must have the templateid property defined.
macros object/array User macros to be created for the host.
inventory object Host inventory properties.

戻り値

(object) hostidsプロパティの下に生成されたホストのIDを含むオブジェクトを返します。返されるIDの順序は、渡されたホストの順序と一致します。

ホストの作成

IPインターフェースとタグを持つ "Linux server" というホストを作成し、グループに追加し、テンプレートをリンクし、
ホストインベントリにMACアドレスを設定します.

Request:

{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Linux server",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "192.168.3.1",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "50"
            }
        ],
        "tags": [
            {
                "tag": "Host name",
                "value": "Linux server"
            }
        ],
        "templates": [
            {
                "templateid": "20045"
            }
        ],
        "macros": [
            {
                "macro": "{$USER_ID}",
                "value": "123321"
            },
            {
                "macro": "{$USER_LOCATION}",
                "value": "0:0:0",
                "description": "latitude, longitude and altitude coordinates"
            }
        ],
        "inventory_mode": 0,
        "inventory": {
            "macaddress_a": "01234",
            "macaddress_b": "56768"
        }
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "107819"
        ]
    },
    "id": 1
}

SNMPインターフェイスを持つホストの作成

SNMPv3 インタフェースを持つホスト "SNMP host" を詳細とともに作成します。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "SNMP host",
        "interfaces": [
            {
                "type": 2,
                "main": 1,
                "useip": 1,
                "ip": "127.0.0.1",
                "dns": "",
                "port": "161",
                "details": {
                    "version": 3,
                    "bulk": 0,
                    "securityname": "mysecurityname",
                    "contextname": "",
                    "securitylevel": 1
                }
            }
        ],
        "groups": [
            {
                "groupid": "4"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10658"
        ]
    },
    "id": 1
}

PSK 暗号化を使用したホストの作成

PSK 暗号化が設定された "PSK ホスト"というホストを作成します。 ホストは PSK を使用するように事前設定 されている必要があります。

Request:

{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "PSK host",
        "interfaces": [
            {
                "type": 1,
                "ip": "192.168.3.1",
                "dns": "",
                "port": "10050",
                "useip": 1,
                "main": 1
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "tls_accept": 2,
        "tls_connect": 2,
        "tls_psk_identity": "PSK 001",
        "tls_psk": "1f87b595725ac58dd977beef14b97461a7c1045b9a1c963065002c5473194952"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10590"
        ]
    },
    "id": 1
}

参照

ソース

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