Ad Widget

Collapse

API call - search 2 items for 1 host

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KingJoey
    Junior Member
    • Feb 2021
    • 4

    #1

    API call - search 2 items for 1 host

    Hi there,

    I would like to find 2 items for 1 specific host using zabbix api call.

    In this case I want to find for host with hostid 10381 items containing the name "uptime" and "Total memory"

    I have no problem to find 1 item in a query:

    curl -s -X POST -H 'Content-Type: application/json-rpc' -d " \

    {
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
    "output": "extend",
    "hostids": "10381",
    "search": {
    "name": "uptime"
    },
    "sortfield": "name"
    },


    "auth": "$auth",
    "id": 1
    }

    " $url | jq . | grep lastvalue

    OUTPUT: "lastvalue": "76833",




    However, when I want to find 2 items in one query with e.g. the name "uptime" and "Total memory", it doesnt work:



    curl -s -X POST -H 'Content-Type: application/json-rpc' -d " \

    {
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
    "output": "extend",
    "hostids": "10381",
    "search": {
    "name": ["Total memory", "uptime"]
    },
    "sortfield": "name"
    },


    "auth": "$auth",
    "id": 1
    }

    " $url | jq .

    OUTPUT:

    "jsonrpc": "2.0",
    "result": [],
    "id": 1


    My variables: $auth, $url, specific hostid

    Is there any posibility to search for 2 items in 1 query?



  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    By default, elements specified in "search" are "AND-ed". In order to "OR" them add searchByAny:
    Code:
    "search": {
        "name": ["total memory", "uptime"]
    },
    "searchByAny": true
    Last edited by dimir; 16-04-2021, 17:37.

    Comment


    • KingJoey
      KingJoey commented
      Editing a comment
      Great! It works! Thank you for your advice!
Working...