Skip to content

Commit fa08c1c

Browse files
authored
Release v2.0.4
2 parents 9521f00 + 036b0c3 commit fa08c1c

File tree

7 files changed

+130
-10
lines changed

7 files changed

+130
-10
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [2.0.4](https://github.com/zabbix/python-zabbix-utils/compare/v2.0.3...v2.0.4) (2025-12-17)
2+
3+
### Changes:
4+
5+
- added examples of how to push item history
6+
- updated examples of how to clear item history
7+
8+
### Bug fixes:
9+
10+
- fixed issue [#34](https://github.com/zabbix/python-zabbix-utils/issues/34) with timeout ignorance
11+
- fixed small bugs and flaws
12+
113
## [2.0.3](https://github.com/zabbix/python-zabbix-utils/compare/v2.0.2...v2.0.3) (2025-07-03)
214

315
### Features:

examples/api/asynchronous/clear_history.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717

1818
# IDs of items for which the history should be cleared
19-
ITEM_IDS = [70060]
19+
ITEM_IDS = [70060, 70061, 70062]
2020

2121

2222
async def main():
@@ -32,10 +32,10 @@ async def main():
3232

3333
# Clear history for items with specified IDs
3434
try:
35-
await api.history.clear(*ITEM_IDS)
35+
await api.history.clear(ITEM_IDS)
3636

37-
# Alternative way to do the same (since v2.0.2):
38-
# await api.history.clear(ITEM_IDS)
37+
# A way to do the same for versions prior to v2.0.2:
38+
# await api.history.clear(*ITEM_IDS)
3939
except APIRequestError as e:
4040
print(f"An error occurred when attempting to delete items: {e}")
4141
else:
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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, APIRequestError
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+
# IDs and values of items to push
19+
ITEM_VALUES = [
20+
{
21+
"itemid": 70060,
22+
"value": 55
23+
},
24+
{
25+
"itemid": 70061,
26+
"value": 1.8,
27+
"clock": 1690891294,
28+
"ns": 45440940
29+
},
30+
{
31+
"itemid": 70062,
32+
"value": 123,
33+
"clock": 1690891295
34+
}
35+
]
36+
37+
38+
async def main():
39+
"""
40+
The main function to perform asynchronous tasks.
41+
"""
42+
43+
# Create an instance of the AsyncZabbixAPI class
44+
api = AsyncZabbixAPI(ZABBIX_SERVER)
45+
46+
# Authenticating with Zabbix API using the provided username and password.
47+
await api.login(**ZABBIX_AUTH)
48+
49+
# Clear history for items with specified IDs
50+
try:
51+
await api.history.push(ITEM_VALUES)
52+
53+
# A way to do the same for versions prior to v2.0.2:
54+
# await api.history.push(*ITEM_VALUES)
55+
except APIRequestError as e:
56+
print(f"An error occurred when attempting to delete items: {e}")
57+
else:
58+
# Logout to release the Zabbix API session
59+
await api.logout()
60+
61+
# Run the main coroutine
62+
asyncio.run(main())

examples/api/synchronous/clear_history.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
}
1414

1515
# IDs of items for which the history should be cleared
16-
ITEM_IDS = [70060]
16+
ITEM_IDS = [70060, 70061, 70062]
1717

1818
# Create an instance of the ZabbixAPI class with the specified authentication details
1919
api = ZabbixAPI(**ZABBIX_AUTH)
2020

2121
# Clear history for items with specified IDs
2222
try:
23-
api.history.clear(*ITEM_IDS)
23+
api.history.clear(ITEM_IDS)
2424

25-
# Alternative way to do the same (since v2.0.2):
25+
# A way to do the same for versions prior to v2.0.2:
2626
# api.history.clear(*ITEM_IDS)
2727
except APIRequestError as e:
2828
print(f"An error occurred when attempting to clear items' history: {e}")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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, APIRequestError
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+
# IDs and values of items to push
16+
ITEM_VALUES = [
17+
{
18+
"itemid": 70060,
19+
"value": 55
20+
},
21+
{
22+
"itemid": 70061,
23+
"value": 1.8,
24+
"clock": 1690891294,
25+
"ns": 45440940
26+
},
27+
{
28+
"itemid": 70062,
29+
"value": 123,
30+
"clock": 1690891295
31+
}
32+
]
33+
34+
# Create an instance of the ZabbixAPI class with the specified authentication details
35+
api = ZabbixAPI(**ZABBIX_AUTH)
36+
37+
# Push history for the list of item IDs and values
38+
try:
39+
api.history.push(ITEM_VALUES)
40+
41+
# A way to do the same for versions prior to v2.0.2:
42+
# api.history.push(*ITEM_VALUES)
43+
except APIRequestError as e:
44+
print(f"An error occurred when attempting to clear items' history: {e}")
45+
46+
# Logout to release the Zabbix API session
47+
api.logout()

zabbix_utils/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ def send_api_request(self, method: str, params: Optional[dict] = None,
347347
headers=headers,
348348
method='POST'
349349
)
350-
req.timeout = self.timeout
351350

352351
# Disable SSL certificate validation if needed.
353352
if not self.validate_certs:
@@ -360,7 +359,7 @@ def send_api_request(self, method: str, params: Optional[dict] = None,
360359
ctx = None
361360

362361
try:
363-
resp = ul.urlopen(req, context=ctx)
362+
resp = ul.urlopen(req, context=ctx, timeout=self.timeout)
364363
resp_json = json.loads(resp.read().decode('utf-8'))
365364
except URLError as err:
366365
raise ProcessingError(f"Unable to connect to {self.url}:", err) from None

zabbix_utils/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323
# OTHER DEALINGS IN THE SOFTWARE.
2424

25-
__version__ = "2.0.3"
25+
__version__ = "2.0.4"
2626

2727
__min_supported__ = 6.0
2828
__max_supported__ = 7.4

0 commit comments

Comments
 (0)