2026-02-02 11:55:44 +07:00
2025-12-24 14:09:35 +07:00
2025-12-24 14:57:21 +07:00
2025-12-24 14:57:21 +07:00
2025-12-24 14:57:21 +07:00
2025-12-24 14:11:28 +07:00
2026-02-02 11:55:44 +07:00
2025-12-24 14:11:28 +07:00

Zabbix Automation Scripts

Project Overview

This repository contains a small collection of Python scripts that automate common Zabbix monitoring tasks. Each script performs a single, welldefined operation:

Script Purpose
auto-close.py Automatically close tickets that meet a specified condition (e.g., resolved, stale).
auto-acknowledge.py Automatically acknowledge tickets to indicate they are being handled.
get_host.py Retrieve host information from Zabbix for reporting or further automation.
disable_host_by_trigger.py Disable a host when a particular trigger fires, helping to isolate problems.

The scripts are intentionally lightweight and can be run from the command line or scheduled via cron/Task Scheduler.

Prerequisites

  • Python 3.9+ (tested on 3.10 and 3.11)
  • Zabbix API access (URL, user, and password or API token)
  • The following Python packages:
    • requests
    • zabbix-api

You can install the dependencies with:

pip install -r requirements.txt

If requirements.txt is empty, add the packages manually:

pip install requests zabbix-api

Configuration

All scripts read configuration from environment variables. Create a .env file in the repository root or export the variables directly.

Variable Description
ZABBIX_URL Full URL to the Zabbix API endpoint (e.g., https://zabbix.example.com/api_jsonrpc.php).
ZABBIX_USER Username for Zabbix API authentication.
ZABBIX_PASSWORD Password for Zabbix API authentication.
ZABBIX_TOKEN Optional API token; if provided, it overrides user/password.
LOG_LEVEL Logging level (DEBUG, INFO, WARNING, ERROR). Default is INFO.

Example .env:

ZABBIX_URL=https://zabbix.example.com/api_jsonrpc.php
ZABBIX_USER=admin
ZABBIX_PASSWORD=secret
LOG_LEVEL=INFO

The scripts use the python-dotenv package to load these variables automatically.

Usage

Each script accepts commandline arguments. Run python <script> --help for details.

auto-close.py

python auto-close.py --days 7

Closes tickets that have been resolved for more than 7 days.

auto-acknowledge.py

python auto-acknowledge.py --status new

Acknowledges all tickets with status new.

get_host.py

python get_host.py --host "web-server-01"

Prints JSON containing host details.

disable_host_by_trigger.py

python disable_host_by_trigger.py --trigger "CPU overload"

Disables the host that triggered the specified event.

Testing

The repository currently does not include automated tests. If you add tests, place them in a tests/ directory and run them with pytest.

Contributing

  1. Fork the repository.
  2. Create a feature branch: git checkout -b feature/your-feature.
  3. Commit your changes with a clear message.
  4. Push the branch and open a pull request.

Please follow the existing code style and add tests for new functionality.

License

MIT License see the LICENSE file.


This README was generated automatically by Claude Code.

Description
No description provided
Readme 41 KiB
Languages
Python 100%