Ad Widget

Collapse

Zabbix Api : filter items with tag

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • c.lelu
    Junior Member
    • Feb 2025
    • 4

    #1

    Zabbix Api : filter items with tag

    Hello
    I'd like to use the zabbix API in PHP in order to display the items with a specific tag.
    I use Zabbix 6.0 and an authentification by token.
    The request, I tried is :
    itemRequest = [
    'jsonrpc' => '2.0',
    'method' => 'item.get',
    'params' => [
    'hostids' => '10633',
    'output' => ['itemid', 'name', 'lastvalue'],
    'selectTags' => 'extend',
    'filter' => [
    'tags' => [
    'tag' => 'filesystem',
    'value' => '/'
    ]
    ]
    ],
    'auth' => $authToken,
    'id' => 1
    ];
    The request displays the differents items of thehost, but don't filter anything.
    I tried different syntaxes but none is working.
    Thank you for your help.
  • Petr N.
    Junior Member
    • Feb 2025
    • 5

    #2
    For a host with these Tags

    Click image for larger version

Name:	Tags.png
Views:	525
Size:	14.5 KB
ID:	499314

    according to the docs https://www.zabbix.com/documentation...rence/item/get why not use the "tags" parameter? So the request should be
    Code:
    {
      "jsonrpc": "2.0",
      "method": "item.get",
      "params": {
        "hostids": "15549",
        "output": ["itemid", "name", "lastvalue"],
        "selectTags": "extend",
        "tags": [
          {
            "tag": "Application",
            "value": "Filesystems",
            "operator": "1"
          }
        ]
      },
      "id": 1
    }

    for the Tags from the example above. For me this returns the right results (Zabbix 7.2).

    P.S. The "params" parameter should be an JSON object ( { ... } ) and not an array ( [ ... ] ). And I have ommited the "auth" parameter, because Zabbix 7.2 doesn't support this parameter anymore.

    Comment

    • c.lelu
      Junior Member
      • Feb 2025
      • 4

      #3
      Yes it works !
      Thank you
      The code for the request in php is :
      $itemRequest = [
      'jsonrpc' => '2.0',
      ‘method' => 'item.get',
      'params' => [
      'hostids' => '10084',
      'output' => ['itemid', 'name', 'lastvalue'],
      'selectTags' => 'extend',
      'tags' => [
      [
      'tag' => 'filesystem',
      'value' => '/',
      'operator' => '1'
      ]
      ]
      ],
      'auth' => $authToken,
      'id' => 1
      ];

      Comment

      Working...