from pyzabbix import ZabbixAPI zapi = ZabbixAPI("http://zabbix.example.com/api_jsonrpc.php") zapi.login("admin", "zabbix") hosts = zapi.host.get( output=["hostid", "host", "status"], selectInterfaces=["ip"], ) for host in hosts: print(host["host"], host["interfaces"][0]["ip"], host["status"])
from pyzabbix import ZabbixAPI zapi = ZabbixAPI("http://zabbix.example.com/api_jsonrpc.php") zapi.login("admin", "zabbix") host_name = "Test Host" ip_address = "192.168.1.100" group_id = zapi.hostgroup.get(filter={"name": "Linux servers"})[0]["groupid"] host = zapi.host.create( host=host_name, interfaces=[{"type": 1, "main": 1, "ip": ip_address, "dns": "", "port": "10050"}], groups=[{"groupid": group_id}], )The package library used in the examples is pyzabbix. It provides a Pythonic way of interacting with the Zabbix API and makes it easy to work with the response data.