CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-py-zabbix

Python module to work with Zabbix monitoring systems through API and sender functionality

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

py-zabbix

A comprehensive Python module to work with Zabbix monitoring systems through both API and sender functionality. It provides a ZabbixAPI class for authentication and performing various operations like host management, data retrieval, and configuration changes through Zabbix's JSON-RPC API, plus ZabbixSender functionality for pushing metrics data to Zabbix trappers.

Package Information

  • Package Name: py-zabbix
  • Package Type: pypi
  • Language: Python
  • Installation: pip install py-zabbix

Core Imports

from pyzabbix import ZabbixAPI, ZabbixAPIException, ZabbixMetric, ZabbixSender, ZabbixResponse, ssl_context_compat

Specific module imports:

from pyzabbix.api import ZabbixAPI, ZabbixAPIException, ssl_context_compat
from pyzabbix.sender import ZabbixMetric, ZabbixSender, ZabbixResponse

Basic Usage

API Interaction

from pyzabbix import ZabbixAPI

# Create ZabbixAPI instance and authenticate
zapi = ZabbixAPI(url='https://zabbix.example.com', user='Admin', password='zabbix')

# Get all monitored hosts
hosts = zapi.host.get(monitored_hosts=1, output='extend')

# Get disabled hosts using raw request
disabled_hosts = zapi.do_request('host.get', {
    'filter': {'status': 1},
    'output': 'extend'
})

# Logout when done
zapi.user.logout()

Metric Sending

from pyzabbix import ZabbixMetric, ZabbixSender

# Create metrics to send
metrics = [
    ZabbixMetric('hostname1', 'cpu_usage', 85.2),
    ZabbixMetric('hostname1', 'memory_usage', '60%'),
    ZabbixMetric('hostname1', 'disk_free', 1024, 1411598020),  # with timestamp
]

# Send metrics to Zabbix server
sender = ZabbixSender(zabbix_server='192.168.1.100')
result = sender.send(metrics)

Architecture

py-zabbix provides two main functional areas:

  • API Interface: ZabbixAPI class provides a Python interface to Zabbix's JSON-RPC API with automatic authentication, session management, and dynamic method dispatch
  • Metric Sender: ZabbixSender enables pushing monitoring data to Zabbix trappers with batch processing and configurable connection parameters

The library supports Python 2 and 3, includes automatic password masking for security, context manager support for resource cleanup, and built-in logging capabilities.

Capabilities

Zabbix API Interface

Complete interface to Zabbix's JSON-RPC API with authentication management, dynamic method dispatch, and comprehensive error handling for all Zabbix monitoring operations.

class ZabbixAPI:
    def __init__(self, url=None, use_authenticate=False, use_basic_auth=False, user=None, password=None): ...
    def api_version(self): ...
    def do_request(self, method, params=None): ...
    def get_id(self, item_type, item=None, with_id=False, hostid=None, **args): ...

Zabbix API Interface

Metric Sending

Send monitoring metrics to Zabbix server via trapper protocol with batch processing, configurable connection parameters, and comprehensive response handling.

class ZabbixSender:
    def __init__(self, zabbix_server='127.0.0.1', zabbix_port=10051, use_config=None, chunk_size=250, socket_wrapper=None, timeout=10): ...
    def send(self, metrics): ...

class ZabbixMetric:
    def __init__(self, host, key, value, clock=None): ...

class ZabbixResponse:
    def parse(self, response): ...

Metric Sending

Exception Handling

class ZabbixAPIException(Exception):
    """Custom exception for Zabbix API errors"""
    def __init__(self, error): ...

The ZabbixAPIException provides detailed error information including error code, message, and sanitized request data for debugging.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/py-zabbix@1.1.x
Publish Source
CLI
Badge
tessl/pypi-py-zabbix badge