Ad Widget

Collapse

Zabbix API: Query all hosts with same description

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jarne St
    Member
    • Sep 2019
    • 63

    #1

    Zabbix API: Query all hosts with same description

    Hello

    I was wondering if you can get all the hosts with the same description from the API?

    If I look at the documentation: https://www.zabbix.com/documentation...rence/host/get
    I didn't see anything to get the description.
    I want to get all the hosts with a specific description. (in my case SAM0105)

    I have tried this:
    Code:
    {
        "jsonrpc": "2.0",
        "method":"host.get",
        "params": {
            "description": "SAM0105"
        },
        "id":1,
        "auth":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }
    and this:
    Code:
    {
        "jsonrpc": "2.0",
        "method":"host.get",
        "params": {
            "filter": {
                "description": [
                    "SAM0105"
                ]
            }
        },
        "id":1,
        "auth":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }
    But so far I only get errors. Does anyone knows if you can do this?
    Thanks for any help!
    Last edited by Jarne St; 12-02-2020, 18:00.
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    I don't believe you can make the API do the filtering for you in the case of description. If you look at the first part of the parameters for host.get(), these give you some idea of the things you can filter by. I don't see description as an option anywhere, in the current API.

    What you can do is not filter, include description in the list of attributes you return, and then have your script or program do the filtering. You're effectively "post-processing" the full list of hosts (that your API user has access to), rather than having the API only return the set of hosts you want.

    Comment

    • Jarne St
      Member
      • Sep 2019
      • 63

      #3
      Thank you splitek

      This worked for me:
      Code:
      {
          "jsonrpc": "2.0",
          "method":"host.get",
          "params": {
              "output": ["host"],
              "search" :{
                  "description": "SAM0102"
              }
          },
          "id": 1,
          "auth":"XXXXXXXXXXXXXXXXXXXXXXXXXXX"
      }
      and can I update the same hosts with the host.massupdate API call (to enable or disable these hosts)

      Comment

      Working...