File: with_context.py

package info (click to toggle)
pyzabbix 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: python: 903; makefile: 45
file content (14 lines) | stat: -rw-r--r-- 365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""
Prints hostnames for all known hosts.
"""

from pyzabbix import ZabbixAPI

ZABBIX_SERVER = "https://zabbix.example.com"

# Use context manager to auto-logout after request is done.
with ZabbixAPI(ZABBIX_SERVER) as zapi:
    zapi.login("api_username", "api_password")
    hosts = zapi.host.get(output=["name"])
    for host in hosts:
        print(host["name"])