Skip to main content

Simple Python implementation of the Zabbix API.

Project description

pyzab

A simple Python implementation of a Zabbix API wrapper.

Installation

Simply install the https://pypi.org/project/pyzab/ package: pip install pyzab

Usage

First, make sure to have a .env file alongside your script, with your credentials. This helps keep your url and token away from version control by adding it to .gitignore. This is optional, but strongly recommended. If you skip this step, initialize the Zabbix class with your credential strings. The optional .env file should look like this:

## .env.py
zabbix_auth_token='key_from_zabbix_api'
zabbix_url='zabbix_api_url'

On a new python file, import the Zabbix class:

## my_new_zabbix_script.py
from pyzab import Zabbix

Now import and load the .env file (otherwise, use the url and token as strings):

## my_new_zabbix_script.py
from dotenv import load_dotenv # pip install python-dotenv
load_dotenv()

You can now initialize the Pyzab Zabbix api wrapper, and begin making api calls:

## my_new_zabbix_script.py
zabbix = pyzab.Zabbix(os.getenv('zabbix_url'), os.getenv('zabbix_auth_token')) # or zabbix = pyzab.Zabbix('http://your_url/:8080/api_jsonrpc.php', 'your_zabbix_api_token')
all_hosts = zabbix.get_all_hosts() # returns a list with all hosts.

Examples

Example 1: Add a new host to Zabbix server

After you initialize the wrapper as shown above:

zabbix = pyzab.Zabbix(os.getenv('zabbix_url'), os.getenv('zabbix_auth_token'))
new_host = zabbix.create_host(hostname="new_hostname", ip="10.99.99.99", group_id="5", templateid="10186") # You can get groupid and templateid from the zabbix front end with debug enabled

The create_host method returns a python Dict with the new host's 'hostid' (inside a list, we need to index it) to the new_host variable. We can then check the new host's data with another api call:

new_host_data = zabbix.get_host(host_id=new_host['hostids'][0])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyzab-0.1.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyzab-0.1.3-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pyzab-0.1.3.tar.gz.

File metadata

  • Download URL: pyzab-0.1.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pyzab-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4d8d031ea4814e6a2c080131a84b68a0b92db80e243bf3cee78422298be77899
MD5 9e198a43bd567c5c9ac2d8d15426a507
BLAKE2b-256 98c95e6cd01f38138594eb4c2f01cef25cce3f4023c26df17409d3196ee2f181

See more details on using hashes here.

File details

Details for the file pyzab-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyzab-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pyzab-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9b4ebfb25d53701602f7f6e944d1c0cfa4240e9a6cf269e94cc70fcc7a401a48
MD5 ec80d3f79518b25c09ba8513c6cf9918
BLAKE2b-256 388cf47d4107ae546710e0cc4f01ba5312d80c76b42c8065cc4fc6d883be2dad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page