Skip to content

Instantly share code, notes, and snippets.

@htnosm
Created November 8, 2020 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htnosm/ecd39bf2c9710e6d2ede5aa66e1ed4d3 to your computer and use it in GitHub Desktop.
Save htnosm/ecd39bf2c9710e6d2ede5aa66e1ed4d3 to your computer and use it in GitHub Desktop.
Zabbix Export Sample. (Zabbix Ver 4.x)
from pyzabbix import ZabbixAPI
import os
import json
zapi = ZabbixAPI("Your Zabbix URL")
zapi.session.verify = False
zapi.login("Your Zabbix User", "Your Zabbix Password")
print("Connected to Zabbix API Version %s" % zapi.api_version())
output_dir = './var'
os.makedirs(output_dir, exist_ok=True)
# hostgroup
hostgroups = zapi.hostgroup.get(selectHosts="extend")
with open(f"{output_dir}/hostgroups.json", 'w') as f:
json.dump(hostgroups, f, ensure_ascii=False, indent=2)
# host
hosts = zapi.host.get(selectItems="extend")
with open(f"{output_dir}/hosts.json", 'w') as f:
json.dump(hosts, f, ensure_ascii=False, indent=2)
# item
items = zapi.item.get(selectTriggers="extend", webitems=1)
with open(f"{output_dir}/items.json", 'w') as f:
json.dump(items, f, ensure_ascii=False, indent=2)
# triggers
triggers = zapi.trigger.get(selectItems="extend", expandExpression=True)
with open(f"{output_dir}/triggers.json", 'w') as f:
json.dump(triggers, f, ensure_ascii=False, indent=2)
# web_senarios (httptest)
web_senarios = zapi.httptest.get(selectHosts="extend", selectSteps="extend")
with open(f"{output_dir}/web_senarios.json", 'w') as f:
json.dump(web_senarios, f, ensure_ascii=False, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment