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.4.tar.gz (4.5 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.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyzab-0.1.4.tar.gz
  • Upload date:
  • Size: 4.5 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.4.tar.gz
Algorithm Hash digest
SHA256 edfcfc56bf1cd368b252a3657ef4763b2f0a1c88c28451895a519ddac22f8d76
MD5 e5cb96a5c1639feb9495bb277ee6350a
BLAKE2b-256 0fe7a3ab83d862e60d5294b18c9fddd0dab93ea33808f857237474667dd49760

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyzab-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d1ea436e7337c99e3938c10e5a125b272179afa40c1568def33c39bf9283f477
MD5 1b7eb6d5c0436958eb0c1df430e13969
BLAKE2b-256 e2b07517c074ff149f79e5fe3b6e64dc47d6f4d74ff09398b4805705682c6fe5

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