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...except
to make code more robust. - Add method
find
to classZabbixAPIObjectFactory
for 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_Test
and api can not find it in Zabbix, methodfind
will create it. So vilation for the response can be threw away. It can save a lot lines of code. - Completed
TODO 1
inv0.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__
inZabbixAPI
to 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.3
because 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_host
of Zabbix. Plus,scan_host
is a script to add a host to Zabbix with its IP. And the script will add templates to the host according to thenetstat -ldunp
command andps -ef
command. 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
,item
and 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
ZabbixAPIObject
and the other is calledZabbixObject
.ZabbixAPIObject
is used to wrap json andZabbixObject
is the abstract of every RESOURCE(host
,item
, ...). - Use
exec
to define methods which is nearly alike in batch (everyZabbixAPIObject
has a lot of methods which is nearly alike, only a word is different.(need to improved) - Complete main
ZabbixObject
-Host
andItem
partly. They two is a sample ofZabbixObject
relations.
TODO:
- Replace
exec
with 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.