Ad Widget

Collapse

API history.get -> not returning multiple itemIDs when limit = 1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leslie79
    Junior Member
    • Mar 2022
    • 4

    #1

    API history.get -> not returning multiple itemIDs when limit = 1

    Hi,

    Hope I'm not going crazy or made some stupid mistake or even worse it's already been posted !

    Server version is 6.0.6

    I'm calling the API through curl in a bash script and I want to get only the latest history value of multiple items
    All items are Text (4)

    This is my request:

    Code:
    response=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d " \
    {
    \"jsonrpc\": \"2.0\",
    \"method\": \"history.get\",
    \"params\": {
    \"output\": [\"itemid\",\"value\"],
    \"itemids\": [76172,76180],
    \"history\": 4,
    \"sortfield\": \"clock\",
    \"sortorder\": \"DESC\",
    \"limit\": 1
    },
    \"auth\": \"$auth\",
    \"id\": 1
    }
    " $url )

    I'm expecting to get the latest value from all items listed in the array.

    Yet I always get only the value returned from the last item in the array.

    As soon as I remove the 'limit' parameter I get values from all items in the array.

    So my itemids array works fine, but not with the limit parameter.

    Is this expected behaviour ?

    Kind regards,
    Leslie
  • Leslie79
    Junior Member
    • Mar 2022
    • 4

    #2
    I just found out it's intended to work like that. Seems I have to get the latest values in another way.

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #3
      I think it is expected, as you are limiting the results of whole query. What you probably need to do, is loop over your ID-s and return that last value for each of them.

      Comment

      • Leslie79
        Junior Member
        • Mar 2022
        • 4

        #4
        For those interested, a nice workaround is to enable the inventory for the hosts.
        The inventory fields will always get the latest value for the connected item.

        After that you can get your hosts with host.get

        Code:
        response=$(curl -s -X POST -H 'Content-Type: application/json-rpc' -d " \
        {
        \"jsonrpc\": \"2.0\",
        \"method\": \"host.get\",
        \"params\": {
                 \"output\": [\"host\"],
                 \"groupids\": [27],
                 \"selectInventory\": [\"os\",\"model\",\"serialno_a\"]
                    },
        \"auth\": \"$auth\",
        \"id\": 1
        }
        " $url )

        Comment

        Working...