Skip to content

Commit 74065f1

Browse files
committed
added examples of how to pass get request parameters
1 parent 6bda76c commit 74065f1

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (C) 2001-2023 Zabbix SIA
2+
#
3+
# Zabbix SIA licenses this file to you under the MIT License.
4+
# See the LICENSE file in the project root for more information.
5+
6+
import asyncio
7+
from zabbix_utils import AsyncZabbixAPI
8+
9+
# Zabbix server URL or IP address
10+
ZABBIX_SERVER = "127.0.0.1"
11+
12+
# Zabbix server authentication credentials
13+
ZABBIX_AUTH = {
14+
"user": "Admin", # Zabbix user name for authentication
15+
"password": "zabbix" # Zabbix user password for authentication
16+
}
17+
18+
19+
async def main():
20+
"""
21+
The main function to perform asynchronous tasks.
22+
"""
23+
24+
# Create an instance of the AsyncZabbixAPI class
25+
api = AsyncZabbixAPI(ZABBIX_SERVER)
26+
27+
# Authenticating with Zabbix API using the provided username and password.
28+
await api.login(**ZABBIX_AUTH)
29+
30+
# There are only three ways to pass parameters of type dictionary:
31+
#
32+
# 1. Specifying values directly with their keys:
33+
problems = await api.problem.get(tags=[{"tag": "scope", "value": "notice", "operator": "0"}])
34+
#
35+
# 2. Unpacking dictionary keys and values using `**`:
36+
# request_params = {"tags": [{"tag": "scope", "value": "notice", "operator": "0"}]}
37+
# problems = await api.problem.get(**request_params)
38+
#
39+
# 3. Passing the dictionary directly as an argument (since v2.0.2):
40+
# request_params = {"tags": [{"tag": "scope", "value": "notice", "operator": "0"}]}
41+
# problems = await api.problem.get(request_params)
42+
43+
# Print the names of the retrieved users
44+
for problem in problems:
45+
print(problem['name'])
46+
47+
# Logout to release the Zabbix API session
48+
await api.logout()
49+
50+
# Run the main coroutine
51+
asyncio.run(main())
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2001-2023 Zabbix SIA
2+
#
3+
# Zabbix SIA licenses this file to you under the MIT License.
4+
# See the LICENSE file in the project root for more information.
5+
6+
from zabbix_utils import ZabbixAPI
7+
8+
# Zabbix server details and authentication credentials
9+
ZABBIX_AUTH = {
10+
"url": "127.0.0.1", # Zabbix server URL or IP address
11+
"user": "Admin", # Zabbix user name for authentication
12+
"password": "zabbix" # Zabbix user password for authentication
13+
}
14+
15+
# Create an instance of the ZabbixAPI class with the specified authentication details
16+
api = ZabbixAPI(**ZABBIX_AUTH)
17+
18+
# There are only three ways to pass parameters of type dictionary:
19+
#
20+
# 1. Specifying values directly with their keys:
21+
problems = api.problem.get(tags=[{"tag": "scope", "value": "notice", "operator": "0"}])
22+
#
23+
# 2. Unpacking dictionary keys and values using `**`:
24+
# request_params = {"tags": [{"tag": "scope", "value": "notice", "operator": "0"}]}
25+
# problems = api.problem.get(**request_params)
26+
#
27+
# 3. Passing the dictionary directly as an argument (since v2.0.2):
28+
# request_params = {"tags": [{"tag": "scope", "value": "notice", "operator": "0"}]}
29+
# problems = api.problem.get(request_params)
30+
31+
# Print the names of the retrieved users
32+
for problem in problems:
33+
print(problem['name'])
34+
35+
# Logout to release the Zabbix API session
36+
api.logout()

0 commit comments

Comments
 (0)