To run the examples in this directory, you need to set up a few environment variables. These variables provide the necessary credentials and endpoint for connecting to your Zabbix API.
Before running any example, ensure the following environment variables are set in your shell:
ZABBIX_API_URL: The full URL to your Zabbix API endpoint.- Example:
http://localhost:3080/api_jsonrpc.php
- Example:
ZABBIX_API_USER: The username for Zabbix API authentication.- Example:
Admin
- Example:
ZABBIX_API_PASSWORD: The password for the Zabbix API user.- Example:
zabbix
- Example:
Some examples might require additional specific environment variables. These will be noted in their respective run commands.
You can run each example using the cargo run --example <example_name> --features v7,full command.
This example demonstrates basic API connectivity, fetching API version, and obtaining an authentication token.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example api_basics --features v7,fullThis example shows how to fetch host information from Zabbix.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_hosts_example --features v7,fullThis example demonstrates fetching host groups, optionally filtering by name.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_host_groups_example --features v7,fullThis example demonstrates creating a new host, including prerequisite host group creation and assigning an agent interface.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example create_host_example --features v7,fullThis example demonstrates creating a new host group.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example create_host_group_example --features v7,fullThis example shows how to create a new item on a specified host. It requires an additional environment variable:
ZABBIX_HOST_ID_FOR_ITEM_EXAMPLE: The ID of an existing host in your Zabbix instance where the item will be created.- Example:
10010
- Example:
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
export ZABBIX_HOST_ID_FOR_ITEM_EXAMPLE="10001" # Replace "10001" with an actual host ID
cargo run --example create_item_example --features v7,fullReplace "10001" with an actual host ID from your Zabbix setup. The ID "10001" is a placeholder.
This example demonstrates fetching items, for instance, by searching for a specific item key.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_items_example --features v7,fullThis example demonstrates how to use the raw_api_call method for direct interaction with the Zabbix API, useful for methods not yet specifically implemented in the client or for custom parameter structures.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example raw_api_call_example --features v7,fullThis example demonstrates fetching trigger information from Zabbix, including their tags.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_triggers_example --features v7,fullThis example demonstrates fetching web scenario information from Zabbix, including their steps.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_webscenarios_example --features v7,fullThis example demonstrates fetching user information from Zabbix.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_users_example --features v7,fullThis example demonstrates creating a new user group in Zabbix.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example create_user_group_example --features v7,fullThis example demonstrates fetching user group information from Zabbix, including users within those groups.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example get_user_groups_example --features v7,fullThis example demonstrates creating a new user in Zabbix. It includes creating a user group for the new user and assigning the user to it with a specific role.
export ZABBIX_API_URL=http://localhost:3080/api_jsonrpc.php
export ZABBIX_API_USER=Admin
export ZABBIX_API_PASSWORD=zabbix
cargo run --example create_user_example --features v7,fullNote: Ensure your Zabbix server is accessible and the API user has the necessary permissions for the operations performed by each example. The example commands use the features v7 and full (which enables item, host, trigger, webscenario, user, etc.). The commands also demonstrate setting the required environment variables (ZABBIX_API_URL, ZABBIX_API_USER, ZABBIX_API_PASSWORD).