Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Unverified Commit d72438d1 authored by Fabien CHALON's avatar Fabien CHALON Committed by GitHub
Browse files

Merge pull request #7 from fbst999/dev

add export host and template scripts
parents 08f94520 1f87fbf0
No related branches found
No related tags found
No related merge requests found
##################################################################
### Script usage: python3 export_host.py <output_folder>
### the script will export all host in Zabbix and write
### xml file in the output folder given in parameter
##################################################################
import argparse,logging,time,os,json,xml.dom.minidom
from pyzabbix import ZabbixAPI
from sys import exit
from datetime import datetime
Zabbix_url = "http://zabbix.local"
Zabbix_user = "Zabbix_API"
Zabbix_password = "password"
outputPath=sys.argv[1]
zapi = ZabbixAPI(Zabbix_url,user=Zabbix_user,password=Zabbix_password)
zbxhost = zapi.host.get(output="extend")
for host in zbxhost:
zbxxml = zapi.configuration.export(options={'hosts':[format(h['hostid'])]},format='xml')
dest = outputPath+h['host']+'.xml'
print(h['host']+".xml")
template = xml.dom.minidom.parseString(zbxxml.encode('utf-8'))
date = template.getElementsByTagName("date")[0]
date.firstChild.replaceWholeText('2016-01-01T01:01:01Z')
f = open(dest, 'wb')
f.write(template.toprettyxml().encode('utf-8'))
f.close
##################################################################
### Script usage: python3 export_templates.py <output_folder>
### the script will export all templates in Zabbix and write
### xml file in the output folder given in parameter
##################################################################
import argparse,logging,time,os,json,xml.dom.minidom
from pyzabbix import ZabbixAPI
from sys import exit
from datetime import datetime
Zabbix_url = "http://zabbix.local"
Zabbix_user = "Zabbix_API"
Zabbix_password = "password"
outputPath=sys.argv[1]
zapi = ZabbixAPI(Zabbix_url,user=Zabbix_user,password=Zabbix_password)
zbxtemplate = zapi.template.get(output="extend")
for template in zbxtemplate:
zbxxml = zapi.configuration.export(options={'templates':[format(h['templateid'])]},format='xml')
dest = outputPath+template['host']+'.xml'
print(template['host']+".xml")
template = xml.dom.minidom.parseString(zbxxml.encode('utf-8')
date = template.getElementsByTagName("date")[0]
date.firstChild.replaceWholeText('2016-01-01T01:01:01Z')
f = open(dest, 'wb')
f.write(template.toprettyxml().encode('utf-8'))
f.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment