Ad Widget

Collapse

api question, how to associate hostgroups with hosts?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxlock
    Member
    • Mar 2005
    • 32

    #1

    api question, how to associate hostgroups with hosts?

    Hi All,

    I want to write a script to copy all the hosts from one hostgroup to another via the api using hostgroup.massupdate.

    The problem I have is getting a list of hosts that are in the source hostgroup. There's no way to select/filter host.get to show hosts with a matching groupid and hostgroup.get doesn't show hostgroup members?

    Is this something for the wishlist?

    -Cheers Max
  • zabbix_zen
    Senior Member
    • Jul 2009
    • 426

    #2
    Yes there is.

    Using the Python API, (the logic is the same using other zabcon or other wrappers)
    group_id = zapi.hostgroup.get({"filter" : {"name" : 'YourHostGroupName'}})[0]['groupid']
    zapi.host.get({"filter" : {"groupid" : group_id}})
    gets you the hostgroupid and
    the list of hosts from that groupid

    Comment

    • maxlock
      Member
      • Mar 2005
      • 32

      #3
      Hi There,

      Thanks for the suggestions, the API docs specify groupids not groupid, that could be why it's not working. I'll go play

      -Cheers Max.

      Comment

      • maxlock
        Member
        • Mar 2005
        • 32

        #4
        Hi,

        I just updated groupids to groupid, I've still got problems. I posted earlier in the forum about filtering not working and that seems to be the case again now. Regardless of what host group id I specify, all hosts are being returned including those not in the specified host group.

        curl -b /tmp/cookies -m3 -i -X POST -H 'Content-Type: application/json-rpc' -d '{"jsonrpc": "2.0", "method":"host.get","params": {"output": "extend", "filter": {"groupid": ["12"]}},"auth": "dc2c3d4ed2d70ca159eef083762d63fc", "id": 0}' http://hostname/zabbix/api_jsonrpc.php

        -Cheers Max.

        Comment

        Working...