A simple way to connect to Zabbix api. It enables engineers to handle Zabbix resources more easily.
zapi = ZabbixAPI(url='http://your.zabbix.address', user='admin', password='zabbix')
zapi.login()
print zapi.Graph.find({'graphid':'49931'}, attr_name='graphid')[0]
hostid = zapi.Host.find({'ip':ip}, attr_name='hostid')[0]
print zapi.Host.exists({'filter':{'host':'Zabbix-Proxy-Hostname'}})
host = zapi.createObject(Host, 'HostToCreate')
item = host.getItem('444107')
zapi.host.get({'hostids':['16913','17411'],'output':'extend'})
group = zapi.createObject(Hostgroup, '926')
print zapi.getHostByHostid('16913')
Release notes:
- Remove test cases in zapi.py
- Add use cases in
README.md.
TODO:
- Confirm the compatibility of higher version of zabbix.
Release notes:
- Fix bugs about list index problems.
- Add some
try...exceptto make code more robust. - Add method
findto classZabbixAPIObjectFactoryfor get data easily. This method will filter column of response and create missing object which you asked for. For example, if you want to get a template namedTemplate_Testand api can not find it in Zabbix, methodfindwill create it. So vilation for the response can be threw away. It can save a lot lines of code. - Completed
TODO 1inv0.4. New scan_host(now named 'Spider' due to George RR Martin's great novel 'A Song of Ice and Fire'). - Completed some frontend of Zabbix for its own php is hard to use and slow to load.
- Add some readable excetions.
TODO:
- Add more elements to Zabbix Platform(new frontend of Zabbix). According to the essential needs of work.
Release notes:
- Overwrite
__getattr__inZabbixAPIto make it dynamic to create Zabbix API object. No API objects unused will be created. - Add all API object to ZabbixAPI.
- Abandon
TODO 1.inv0.3because the attribues - mac and ip are connected to CMDB, not Zabbix. I move them to another CMDB API. - Abandon
TODO 4.inv0.3. It will be a procedure as coding. - Completed
TODO 5.inv0.3.
TODO:
- To be considered later. I will use this API to refactor
scan_hostof Zabbix. Plus,scan_hostis a script to add a host to Zabbix with its IP. And the script will add templates to the host according to thenetstat -ldunpcommand andps -efcommand. This command can fetch process running on host and its port infomation is available.
Release notes:
- 'TODO 1.' postponed because connect to CMDB is in the first priority.
- 'TODO 2.' improve relation between Host and Item.
- Add staticmethod in ZabbixAPI 'zabbixGet' for get data remotely with 'zabbix_get'.
TODO:
- Add Host attributes: mac address and ip address.
- Doc.(long long long tern Oh, I'm so lazzzzzy)
- Refactor with more design patterns.(long tern)
- Make code more readable.
- More readable exceptions.
Release notes:
- Complete
TODO 1.inv0.1. Very thanks to gesheit. Now a factory class is used to make all api object with method__getattr__. Plus, a new decorator is made to act as a proxy for api object likehost,itemand etc,. - Copmplete
TODO 6.inv0.1. Use teams' git for version control.
TODO:
- Fullfill
ZabbixAPIObject. - Research on the issue - relation among Resources.
- Docs.(long long long tern Oh, I'm so lazzzzzy)
- Refactor with more design patterns.(long tern)
- Make code more readable.
- More readable exceptions.
Release notes:
- Make framework for communication between script and web service.
- Use decorator to POST/GET json and check users' auth.
- Design patter 'Singleton' apply to main object(zapi in the example).
- Two layers of objects - lower is called
ZabbixAPIObjectand the other is calledZabbixObject.ZabbixAPIObjectis used to wrap json andZabbixObjectis the abstract of every RESOURCE(host,item, ...). - Use
execto define methods which is nearly alike in batch (everyZabbixAPIObjecthas a lot of methods which is nearly alike, only a word is different.(need to improved) - Complete main
ZabbixObject-HostandItempartly. They two is a sample ofZabbixObjectrelations.
TODO:
- Replace
execwith other elegent method. - Fullfill
ZabbixAPIObject. - Research on the issue - relation among Resources.
- Doc.(long tern)
- Refactor with more design patterns.(long tern)
- Github.
- More readable exceptions.