Skip to main content

ZABBIX-CLI - Zabbix terminal client

Project description

Zabbix-cli

PyPI PyPI - Python Version PyPI - License GitHub Workflow Status

Zabbix-CLI v3 has been completely rewritten from the ground up. The old version can be found here.

About

Zabbix-cli is a command line interface for performing common administrative tasks tasks in Zabbix monitoring system via the Zabbix API.

The zabbix-cli code is written in Python and distributed under the GNU General Public License v3. It has been developed and tested by University Center for Information Technology at the University of Oslo, Norway.

The project home page is on GitHub. Please report any issues or improvements there.

The manual is available online at https://unioslo.github.io/zabbix-cli/.

Install

From source

[!NOTE] We are in the process of acquiring the name zabbix-cli on PyPI. Until then, installation must be done via the mirror package zabbix-cli-uio.

pip(x)

pipx install zabbix-cli-uio

uv

uv tool install zabbix-cli-uio

uvx

uvx --from zabbix-cli-uio zabbix-cli

Homebrew

A homebrew package exists, but it is maintained by a third party. It can be installed with:

brew install zabbix-cli

Binary

Binaries built with PyInstaller can be found on the releases page. We build binaries for Linux (x86), macOS (ARM) and Windows (x86) for each release.

Quick start

# Initialize the config file with your Zabbix URL
zabbix-cli init --zabbix-url https://your-zabbix-url.com/
# Start the REPL
zabbix-cli

Usage

Zabbix-cli is a command line interface for Zabbix. It can be used in three ways:

  1. Interactive mode: Start the REPL by running zabbix-cli. This will start a shell where you can run multiple commands in a persistent session.
  2. Single command: Run a single command by running zabbix-cli COMMAND. This will run the command and print the output.
  3. Batch mode: Run multiple commands from a file by running zabbix-cli -f FILE. The file should contain one command per line.

Command reference can be found in the online user guide or by running zabbix-cli --help.

Formats

Zabbix-cli supports two output formats: table and JSON. The default format is table, but it can be changed with the --format parameter:

# Show hosts in table format (default)
zabbix-cli show_hosts
# Show hosts in JSON format
zabbix-cli --format json show_hosts

# Setting format in REPL
> --format json show_hosts

Or by setting the app.output_format parameter in the config file:

[app]
output_format = "json"

Table

format-table

The default rendering mode is a Rich table that adapts to the width of the terminal.

JSON

format-json

The JSON output format is always in this format, where ResultT is the expected result type:

{
  "message": "",
  "errors": [],
  "return_code": "Done",
  "result": ResultT
}

The type of the result field varies based on the command run. For show_host it is a single Host object, while for show_hosts it is an array of Host objects.

Configuration

Zabbix-cli needs a config file. This can be created with the zabbix-cli init command.

zabbix-cli init --zabbix-url https://zabbix.example.com/

Zabbix-cli will look for config files in the following order:

  1. The path specified with the --config parameter
  2. ./zabbix-cli.toml
  3. XDG config directory (usually ~/.config/zabbix-cli/zabbix-cli.toml), or equivalent Platformdirs directory on Windows and macOS
  4. XDG site config directory (usually /etc/xdg/zabbix-cli/zabbix-cli.toml), or equivalent Platformdirs directory on Windows and macOS

To show the directories used by the application run:

zabbix-cli show_dirs

To open the default config directory with the default window manager run:

zabbix-cli open config

Or print the path to the default config directory:

zabbix-cli open config --path

Zabbix-cli provides commands for showing the current and default configuration:

zabbix-cli show_config
zabbix-cli sample_config

If you run into problems it is useful to enable debug logging in the config file:

[logging]
enabled = true
log_level = "DEBUG"

Find the log file with:

zabbix-cli open logs

Authentication

Zabbix-cli provides several ways to authenticate. They are tried in the following order if multiple are set:

  1. API token from config file
  2. API token from environment variables
  3. Auth token from auth token file
  4. Username and password from config file
  5. Username and password from auth file
  6. Username and password from environment variables
  7. Username and password from prompt

Username and Password

Password-based authentication is the default way to authenticate with Zabbix-cli. If the application is unable to determine authentication from other sources, it will prompt for a username and password.

Config file

The password can be set directly in the config file:

[api]
zabbix_url = "https://zabbix.example.com/"
username = "Admin"
password = "zabbix"

Auth file

An auth file named .zabbix-cli_auth can be created in the user's home directory. The content of this file should be in the USERNAME::PASSWORD format.

echo "Admin::zabbix" > ~/.zabbix-cli_auth

The location of this file can be changed in the config file:

[app]
auth_file = "/path/to/auth/file"

Environment variables

The username and password can be set as environment variables:

export ZABBIX_USERNAME="Admin"
export ZABBIX_PASSWORD="zabbix"

Prompt

By omitting the password parameter in the config file or when all other authentication methods have been exhausted, you will be prompted for a password when starting zabbix-cli:

[api]
zabbix_url = "https://zabbix.example.com/"
username = "Admin"

API token

API token authentication foregoes the need for a username and password. The token can be an API token created in the web frontend or a user's session token obtained by logging in.

API token (config file)

API token can be specified directly in the config file:

[api]
auth_token = "API_TOKEN"

API token (environment variables)

API token can be specified as an environment variable:

export ZABBIX_API_TOKEN="API TOKEN"

Auth token file

The application can store the session token returned by the Zabbix API when logging in to a file on your computer. The file is then used for subsequent sessions to authenticate with the Zabbix API.

This feature useful when authenticating with a username and password from a prompt, which would otherwise require you to enter your password every time you start the application.

The feature is enabled by default in the config file:

[app]
use_auth_token_file = true

The location of the auth token file can be changed in the config file:

[app]
auth_token_file = "/path/to/auth/token/file"

By default, the auth token file is not required to have secure permissions. If you want to require the file to have 600 (rw-------) permissions, you can set allow_insecure_auth_file=false in the config file. This has no effect on Windows.

[app]
allow_insecure_auth_file = false

Zabbix-cli attempts to set 600 permissions when writing the auth token file if allow_insecure_auth_file=false.

Development

Zabbix-cli currently uses Hatch for project management and packaging. To start off, clone the repository:

git clone https://github.com/unioslo/zabbix-cli.git

Then make a virtual environment using Hatch:

hatch shell

This will create a new virtual environment, install the required dependencies and enter the environment.

If you do not wish to use Hatch, you can create a virtual environment manually:

python -m venv .venv
source .venv/bin/activate
pip install -U -e ".[test]"

Testing

Run unit tests (without coverage):

hatch run test

Generate coverage report:

hatch run cov

Documentation

To serve the documentation locally:

hatch run docs:serve

This will start a local web server on http://localhost:8001 that is automatically refreshed when you make changes to the documentation. However, some hooks are only run on startup, such as the creation of pages for each command. Changes to command examples or docstrings will require a restart.

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

zabbix_cli_uio-3.2.0.tar.gz (159.9 kB view details)

Uploaded Source

Built Distribution

zabbix_cli_uio-3.2.0-py3-none-any.whl (195.6 kB view details)

Uploaded Python 3

File details

Details for the file zabbix_cli_uio-3.2.0.tar.gz.

File metadata

  • Download URL: zabbix_cli_uio-3.2.0.tar.gz
  • Upload date:
  • Size: 159.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.7

File hashes

Hashes for zabbix_cli_uio-3.2.0.tar.gz
Algorithm Hash digest
SHA256 0f3bf50a10c52fb1cda03935132db4ab4cca5f7a039f12afe0088e03ead5fa99
MD5 4e14b8d2ade6263d0a0842832f806633
BLAKE2b-256 a1656bf3026fabc38f1ee7d91394ddb0261badee9453cbde5fa6efbe6b354f81

See more details on using hashes here.

File details

Details for the file zabbix_cli_uio-3.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for zabbix_cli_uio-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dced45a3ee26280b612f2e91000a76012df86bd8c1b4f91c8883f143437dcee6
MD5 1e2abded9d89447c4a71eb3efadc89eb
BLAKE2b-256 6d627ebcd882c65e451398c4980f9ec0107672376e1ed0f86159a1c0044c646d

See more details on using hashes here.

Supported by

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