-1

I would like to get 'itemid' by item.get api, and filter it by host ip

I tried this request, but it doesn't work (works only when giving host id):

{ "jsonrpc": "2.0", "method": "item.get", "params": { "output": "extend", "selectInterfaces":["ip"], "search": { "ip": "1.1.1.1" } }, "auth": "038e1d7b1735c6a5436ee9eae095879e", "id": 1 }

Any idea for me pls?

user
  • 136
  • 2
  • 16
  • The interface is part of the host, not the item. You need to use item.get() to fetch hostids, then get interfaces with host.get(), then filter by yourself. – Iron Bishop Jul 09 '22 at 10:10

1 Answers1

1

I guess you want the item id of a specific item key/name from an host with specific ip address.

You can do a hostinterface.get with a filter for the required ip address, to obtain the hostid. Then you can do a item.get passing the hostid and a filter for the item key or name to get the itemid.

Simone Zabberoni
  • 2,024
  • 1
  • 10
  • 15
  • Thank you for replynig ! there is no way to do it by one api request? – user Jul 10 '22 at 06:57
  • It should be, but it's highly inefficient: a single `item.get` with key/name filter and `selectInterfaces` will return an object with all the matching items. You'll need to cycle through the returned interfaces to find the correct ip. – Simone Zabberoni Jul 11 '22 at 07:14