Ad Widget

Collapse

Can I access a host's item value through the Zabbix API?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spaghetti
    Junior Member
    • Apr 2023
    • 5

    #1

    Can I access a host's item value through the Zabbix API?

    Just as in the title, I need to access a certain host's Item and do some stuff with it in a python script. For reasons that are too complicated to explain, I need to do what I am trying to do this exact way. I know that there's a Zabbix API and that you can make requests to it via a python script but I don't know whether it's possible to access a host's item, I looked in the docs and googled this issue but nothing has come up. So I come asking, is it possible? And if so, how do i do it?

    Zabbix 5.0.16
  • markosa
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Aug 2022
    • 104

    #2
    Yes you can, using item.get API call, there you define hostid which you want to query.

    Below is a sample code generated by postman.
    Code:
    import requests
    
    url = "http://YOUR_ZABBIX_URL/api_jsonrpc.php"
    
    payload = "{\r\n    \"jsonrpc\": \"2.0\",\r\n    \"method\": \"item.get\",\r\n    \"params\": {\r\n        \"output\": \"extend\",\r\n        \"hostids\": \"YOUR_HOST_ID\"\r\n    },\r\n    \"auth\": \"YOUR_API_KEY\",\r\n    \"id\": 1\r\n}"
    headers = {
      'Content-Type': ' application/json'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload)
    
    print(response.text)
    ​

    Comment

    Working...