Ad Widget

Collapse

Update port on all hosts with API?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guertin
    Junior Member
    • Mar 2010
    • 9

    #1

    Update port on all hosts with API?

    We're updating all of our Zabbix hosts from passive agents to active agents, which means updating the interface port from 10050 to 10051 on all of the hosts. I can do this manually in the web UI and get a successful connection, but I need to do this on many hosts, so I'm looking at the API. Unfortunately my experience with the API is limited so I'm somewhere groping the dark. I can replicate the examples in the documentation, but I'm having trouble extrapolating to update the port number.

    Before trying to do this on all hosts, I'm starting with a simpler case of changing one host. My JSON input looks like this:

    Code:
    {
        "jsonrpc": "2.0",
        "method": "item.update",
        "params": {
            "itemid":"10716"
            "port":"10051"
        },
        "id": 5
    }
    But this results in an "invalid JSON" error. What would be the correct syntax to do this? And to extend this, what would be the syntax to apply this to all hosts?
  • guertin
    Junior Member
    • Mar 2010
    • 9

    #2
    Okay, so I overlooked the obvious and didn't see the missing comma. I've updated the JSON to:

    Code:
    {
        "jsonrpc": "2.0",
        "method": "item.update",
        "params": {
            "itemid":"10716",
            "interfaces":[{
                "port":"10051"
            }]
        },
        "id": 5
    }
    Which is valid JSON but now gives a different error:
    "No permissions to referred object or it does not exist!"
    I'm logged in as the local admin so I would think I have permissions.

    Comment


    • kyus
      kyus commented
      Editing a comment
      The API Key that you're using is a key for the Admin User aswell?
  • guertin
    Junior Member
    • Mar 2010
    • 9

    #3
    Yes, it's the key for the Admin user.

    Comment

    • kyus
      Senior Member
      • Feb 2024
      • 171

      #4
      Oh! I didn't see that you used item.update in your request. If you want to change the host interface you'll need to use host.update

      Comment

      • guertin
        Junior Member
        • Mar 2010
        • 9

        #5
        Thanks. I couldn't find a way to do it with host.update, but in doing so I also stumbled across hostinterface.update, which does sort of do what I want, with a limitation that I haven't yet figured out a way around. In order to update the port number of an interface, I need to know the interfaceid, which is easy enough to get for a single host, but I can't can't figure out a way to script it for a bunch of hosts. i.e. "For all interfaces on all hosts with a port of 10050, update the port to 10051".

        In the end I just changed them all manually, clicking away through the web UI. :-/

        Comment

        Working...