Package: pybix
pybixNOTE: This module is still in development and may not be fully stable. Use at own risk.DescriptionPython based Zabbix API utility containing helper functions and CLI capabilities.Takes inspiration from existing Python-Zabbix API modules likelukecyca/pyzabbixandadubkov/py-zabbix.While this module can be used in a similar way, the aim is to add a few out of the box helper functions and CLI handling for a more "batteries included" module. For example GraphImage as described in usage which enables saving Zabbix graphs which is not possible via the API at this time.InstallPippip install pybixDockerTODO - not yet available.RequirementsPython 3.6 or greaterZabbix 2.0 or greaterOnly tested on >4.0UsageZabbix APIRefer toZabbix Offical API objectreferences for objects that can be queried and their parameters.API structure all uses format likeZAPI.<object>.<action>(<parameters>)e.g.ZAPI.host.get(output='extend').Import as Python moduleDirectlyfrompybiximportZabbixAPIZAPI=ZabbixAPI(url="http://localhost/zabbix")ZAPI.login(user="Admin",password="zabbix")# Print all monitored hostsforhostinZAPI.host.get(output="extend",monitored_hosts=1):print(host['host'])ZAPI.logout()# Explicitly logout to clear Zabbix sessionWith context manager to handle logoutNote: Login still must be done manually (as in the future we may allow passing existing session, hence might not need to login everytime).frompybiximportZabbixAPIwithZabbixAPI()asZAPI:# using defaults for serverZAPI.login()# using defaults for user, password# Print all monitored hostsforhostinZAPI.host.get(output="extend",monitored_hosts=1):print(host['host'])Zabbix API CLIZabbix API CLI UsageUsage:pybix.py<method>[--zabbix-server=ZABBIX_SERVER][--zabbix-user=ZABBIX_USER][--zabbix-password=ZABBIX_PASSWORD][--ssl-verify][(-v|--verbose)][<args>...]pybix.py(-h|--help)pybix.py--version

Arguments:methodeitherZabbixAPIreferenceas'<object>.<action>'orGraphImageAPIas'graphimage.<search_type>'(e.g.'host.get'or'graphimage.graph_id')argswhatargumentstopasstoAPIcall

Options:-h,--help--version-v,--verboseWhethertouseverboselogging[default:False]--output-path=PATHWheretosavegraphstodefault:cwd--zabbix-server=ZABBIX_SERVER[default:https://localhost/zabbix]--zabbix-user=ZABBIX_USER[default:Admin]--zabbix-password=ZABBIX_PASSWORD[default:zabbix]--ssl-verifyWhethertouseSSLverificationforAPI[default:True]Zabbix API CLI Examplepython-mpybixhost.getfilter="{host:server1}"# Get host server1python-mpybixhost.getfilter="{host:[server1,server2]}"# Get host server1 and server2python-mpybixuser.get# Get all UsersGraph Image ExportZabbix does not let you export graphs via API (only the configuration for them). Instead of usingZabbixAPIclass, use includedGraphImage.GraphImage Python ExamplefrompybiximportGraphImageAPIgraph=GraphImageAPI(url="http://localhost/zabbix",user="Admin",password="zabbix")graph.get_by_graphid("4038")# will save to png file in current working directorygraph.get_by_graphname("CPU")# will save any "CPU" graph png images to file in current working directoryGraphImage CLIGraphImage CLI UsageRefer toZabbixAPI usage.search_typesincludegraph_id, graph_name, item_names, item_keys, item_idsGraphImage CLI Examplespython-mpybixgraphimage.graph_namegraph_name=CPUhost_names=server1
python-mpybixgraphimage.graph_namegraph_name=CPUhost_names=[server1,server2]python-mpybixgraphimage.item_namesitem_names=CPUhost_names=server1
python-mpybixgraphimage.item_keysitem_keys=availability.agent.availablehost_names=server1# Not as useful, but is what above methods call after calculating idpython-mpybixgraphimage.graph_idgraph_id=4038host_names=server1
python-mpybixgraphimage.item_idsitem_ids=138780,138781host_names=server1Known IssuesSSL VerificationIf server using a self signed cert or serving on HTTPS, will need to usessl_verifyoverideUser configurationZabbix user used during API calls must have viewing rights to queried Zabbix objecti.e. appropriate hostgroup read rights to user/usergroup OR super adminIf it does not, it will simply return empty results without warningGraph Items UsageUser used to login must have frontend access (i.e. in Zabbix user group, set frontend access to true)No error messages or warnings if graph is invalid (i.e. wrong values used to call it)ContributingFeel free to raise any feature requests/problems/improvements as issue or pull request viaGitHub.