HOME | ARTICLES | PROJECTS | MEMORIES | ABOUT | CONTACT |
---|
pip install zabbix-utils
from zabbix_utils import ZabbixAPI
import csv
api = ZabbixAPI(url="https://example.com")
api.login(user="Admin", password="zabbix")
hostsfile = csv.reader(open("hosts.list"), delimiter=';')
for (host_name, host_ip, group_id, template_id) in hostsfile:
host_params = {
'host': host_name,
'interfaces': [{
'type': 1,
'main': 1,
'useip': 1,
'ip': host_ip,
'dns': '',
'port': '10050'
}],
'groups': [{'groupid': group_id}],
'templates': [{'templateid': template_id}]
}
try:
result = api.host.create(host_params)
print(f"'{host_name}' - {result['hostids'][0]}")
except Exception as e:
print(f"'{host_name}': {e}")
api.logout()
hostname;ipaddr;hostgroup_id;template_id