Ad Widget

Collapse

API item.get: search by multiple filters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kelbergs
    Junior Member
    • Jul 2012
    • 5

    #1

    API item.get: search by multiple filters

    Hi there,

    I'm doing below api call to Zabbix 2.0.1 using zbxapi.rb lib. And it works perfectly
    I get all items with name matching my pattern.

    #!/bin/env ruby
    require 'zbxapi'
    zbx_url="http://localhost/zabbix"
    server = ZabbixAPI.new(zbx_url)
    server.login('admin','zabbix')

    params = {
    "output"=> "extend",
    "search"=> {"name"=> "myItemPatternToSearch"}
    }

    result = server.raw_api("item.get",params)
    puts result

    However, I was trying to narrow down this, to query only for hosts matching some pattern. API doc says that "search" is an array.
    So I've changed the "search" to be an array:
    params = {
    "output"=> "extend",
    "search"=> [{"name"=> "myItemPatternToSearch"}, {"host"=> "myHOSTPatternToSearch"}]
    }
    And that didn't work. Well it didn't produce any errors, but just stopped doing ANY filtering at all. Basically just returned all items that are there for all servers.
    Looks like am bumped into a wall with this one. Can't find a solution in the documentation/google.

    If anyone can point me in the right direction, I would really appreciate it.

    Thanks!
    Stan
  • richlv
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Oct 2005
    • 3112

    #2
    ...necroposting, but in case somebody else stumbles upon this - the following might work :

    Code:
    "search"=> {"name"=> "myItemPatternToSearch", "host"=> "myHOSTPatternToSearch"}
    or in raw json :

    Code:
    "search"=> {"name":"myItemPatternToSearch", "host":"myHOSTPatternToSearch"}
    Zabbix 3.0 Network Monitoring book

    Comment

    Working...