[ZBX-13589] API host.update method fails if interfaces specified and templates are linked Created: 2018 Mar 07  Updated: 2024 Apr 10  Resolved: 2018 Apr 17

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 3.4.6
Fix Version/s: None

Type: Incident report Priority: Major
Reporter: Larry Dorman Assignee: Unassigned
Resolution: Won't fix Votes: 0
Labels: host.update
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

n/a


Issue Links:
Duplicate
Team: Team B
Sprint: Sprint 30, Sprint 31, Sprint 32
Story Points: 0

 Description   

Step 1) Create a host (manually or with API) with standard agent interface (type: 1, main: 1) and assign a template that has Zabbix Agent items so that interface is in use.

Step 2) Call the API method host.update and populate 'interfaces' in the call. This can be the exact same interface information. The call will fail with a message akin to:

{
  "code": -32602,
  "message": "Invalid params.",
  "data": "Interface is linked to item \"Total memory\" on \"example.com\"."
}

The wisdom of the crowds suggests the method is trying to delete the interface and readd it. Because the interface is in use it can't be deleted and the update fails. (See the write-up at https://github.com/express42/zabbixapi/issues/4 which includes the kind of workaround that has to be employed .)

This has apparently been around for a long time and likely impacts most active versions.

Marked this as Major because it requires a lot of additional code to work around what seems to be a design defect in the API.



 Comments   
Comment by Kaspars Mednis [ 2018 Mar 16 ]

Hi !

For 'host.update' method you provide "interfaces" object with 'main' => 1 property.
The object will try to replace interfaces on the host (i.e. firstly delete existing one), but as the host has some items required at least one interface - it produces the correct error message. See https://www.zabbix.com/documentation/3.4/manual/api/reference/host/update

To change IP address for some interface - you need to use another method - "hostinterface.update"
See https://www.zabbix.com/documentation/3.4/manual/api/reference/hostinterface/update

Regards
Kaspars

Comment by Larry Dorman [ 2018 Mar 16 ]

You've confirmed that it does a delete first which is the source of the problem. At best, this is a terrible design. This makes it nearly impossible to use host.update if specifying interfaces. In many cases the interfaces being passed with host.update would be identical to the ones in place. This error should only be returned if there were an attempt to update the host and leave it without a main interface that was in-use.

Comment by Andrejs Griščenko [ 2018 Apr 17 ]

Dear LarryDorman,

host.update API method is working as intended.
You must specify interfaceid for each interface when updating interfaces using it.
To get interfaceid you may use host.get or hostinterface.get method.
See examples below.

1. Get interfaces.
1.1. Using host.get method:

{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "hostids": ["10119"],
        "selectInterfaces": ["interfaceid"]
    },
    "auth": "f22de29e4e8175b2acdf9b0b5388a986",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10119",
            "interfaces": [
                {
                    "interfaceid": "14"
                }
            ]
        }
    ],
    "id": 1
}

1.2. Using hostinterface.get method:

{
    "jsonrpc": "2.0",
    "method": "hostinterface.get",
    "params": {
        "output": ["interfaceid"],
        "hostids": "10119"
    },
    "auth": "f22de29e4e8175b2acdf9b0b5388a986",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "interfaceid": "14"
        }
    ],
    "id": 1
}

2. Update interfaces.
2.1. Using host.update method:

{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10119",
        "status": 0,
        "interfaces": [
            {
                "type": 1,
                "interfaceid": "14",
                "main": 1,
                "useip": 1,
                "ip": "127.0.0.1",
                "dns": false,
                "port": 10050
            }
        ]
    },
    "auth": "f22de29e4e8175b2acdf9b0b5388a986",
    "id": 1
}

Response:

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

2.2. Using hostinterface.update method:

{
    "jsonrpc": "2.0",
    "method": "hostinterface.update",
    "params": {
        "type": 1,
        "interfaceid": "14",
        "main": 1,
        "useip": 1,
        "ip": "127.0.0.1",
        "dns": false,
        "port": 10050
    },
    "auth": "f22de29e4e8175b2acdf9b0b5388a986",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "interfaceids": [
            "14"
        ]
    },
    "id": 1
}
Comment by Larry Dorman [ 2018 May 04 ]

Andrejs Griščenko, now add a template that uses interfaceid 14 in your example and re-execute the "2.1. Using host.update method:" example.  You will find that the API now throws an error which makes it impossible to do a one-step host update.  You now have to do a host.update without any interfaces specified and you have to do a separate hostinterface.update.

There is no (good) reason one should not be able to do a one-step update of a host, including interfaces, using the host.update call.  Only in those cases in which there is an attempt to remove an in-use interface should an error be returned.

Comment by Andrejs Griščenko [ 2018 May 07 ]

LarryDorman, I have created a host with 2 interfaces (Agent and SNMP) and added 2 items to this host each using its own interface. Now, to update interfaces on this host using host.update method all interfaces with linked items must be specified. Otherwise "Interface is linked to item ... on ... ." error will be returned. There is nothing wrong and it is expected behaviour.
To update specific interface (or set of interfaces) hostinterface.update method should be used instead.

In case I have missed something, please provide exact API calls you are using to reproduce the problem.

Generated at Wed Jul 16 11:23:17 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.