Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [2.0.4](https://github.com/zabbix/python-zabbix-utils/compare/v2.0.3...v2.0.4) (2025-12-17)

### Changes:

- added examples of how to push item history
- updated examples of how to clear item history

### Bug fixes:

- fixed issue [#34](https://github.com/zabbix/python-zabbix-utils/issues/34) with timeout ignorance
- fixed small bugs and flaws

## [2.0.3](https://github.com/zabbix/python-zabbix-utils/compare/v2.0.2...v2.0.3) (2025-07-03)

### Features:
Expand Down
8 changes: 4 additions & 4 deletions examples/api/asynchronous/clear_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

# IDs of items for which the history should be cleared
ITEM_IDS = [70060]
ITEM_IDS = [70060, 70061, 70062]


async def main():
Expand All @@ -32,10 +32,10 @@ async def main():

# Clear history for items with specified IDs
try:
await api.history.clear(*ITEM_IDS)
await api.history.clear(ITEM_IDS)

# Alternative way to do the same (since v2.0.2):
# await api.history.clear(ITEM_IDS)
# A way to do the same for versions prior to v2.0.2:
# await api.history.clear(*ITEM_IDS)
except APIRequestError as e:
print(f"An error occurred when attempting to delete items: {e}")
else:
Expand Down
62 changes: 62 additions & 0 deletions examples/api/asynchronous/push_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (C) 2001-2023 Zabbix SIA
#
# Zabbix SIA licenses this file to you under the MIT License.
# See the LICENSE file in the project root for more information.

import asyncio
from zabbix_utils import AsyncZabbixAPI, APIRequestError

# Zabbix server URL or IP address
ZABBIX_SERVER = "127.0.0.1"

# Zabbix server authentication credentials
ZABBIX_AUTH = {
"user": "Admin", # Zabbix user name for authentication
"password": "zabbix" # Zabbix user password for authentication
}

# IDs and values of items to push
ITEM_VALUES = [
{
"itemid": 70060,
"value": 55
},
{
"itemid": 70061,
"value": 1.8,
"clock": 1690891294,
"ns": 45440940
},
{
"itemid": 70062,
"value": 123,
"clock": 1690891295
}
]


async def main():
"""
The main function to perform asynchronous tasks.
"""

# Create an instance of the AsyncZabbixAPI class
api = AsyncZabbixAPI(ZABBIX_SERVER)

# Authenticating with Zabbix API using the provided username and password.
await api.login(**ZABBIX_AUTH)

# Clear history for items with specified IDs
try:
await api.history.push(ITEM_VALUES)

# A way to do the same for versions prior to v2.0.2:
# await api.history.push(*ITEM_VALUES)
except APIRequestError as e:
print(f"An error occurred when attempting to delete items: {e}")
else:
# Logout to release the Zabbix API session
await api.logout()

# Run the main coroutine
asyncio.run(main())
6 changes: 3 additions & 3 deletions examples/api/synchronous/clear_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
}

# IDs of items for which the history should be cleared
ITEM_IDS = [70060]
ITEM_IDS = [70060, 70061, 70062]

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

# Clear history for items with specified IDs
try:
api.history.clear(*ITEM_IDS)
api.history.clear(ITEM_IDS)

# Alternative way to do the same (since v2.0.2):
# A way to do the same for versions prior to v2.0.2:
# api.history.clear(*ITEM_IDS)
except APIRequestError as e:
print(f"An error occurred when attempting to clear items' history: {e}")
Expand Down
47 changes: 47 additions & 0 deletions examples/api/synchronous/push_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (C) 2001-2023 Zabbix SIA
#
# Zabbix SIA licenses this file to you under the MIT License.
# See the LICENSE file in the project root for more information.

from zabbix_utils import ZabbixAPI, APIRequestError

# Zabbix server details and authentication credentials
ZABBIX_AUTH = {
"url": "127.0.0.1", # Zabbix server URL or IP address
"user": "Admin", # Zabbix user name for authentication
"password": "zabbix" # Zabbix user password for authentication
}

# IDs and values of items to push
ITEM_VALUES = [
{
"itemid": 70060,
"value": 55
},
{
"itemid": 70061,
"value": 1.8,
"clock": 1690891294,
"ns": 45440940
},
{
"itemid": 70062,
"value": 123,
"clock": 1690891295
}
]

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

# Push history for the list of item IDs and values
try:
api.history.push(ITEM_VALUES)

# A way to do the same for versions prior to v2.0.2:
# api.history.push(*ITEM_VALUES)
except APIRequestError as e:
print(f"An error occurred when attempting to clear items' history: {e}")

# Logout to release the Zabbix API session
api.logout()
3 changes: 1 addition & 2 deletions zabbix_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ def send_api_request(self, method: str, params: Optional[dict] = None,
headers=headers,
method='POST'
)
req.timeout = self.timeout

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

try:
resp = ul.urlopen(req, context=ctx)
resp = ul.urlopen(req, context=ctx, timeout=self.timeout)
resp_json = json.loads(resp.read().decode('utf-8'))
except URLError as err:
raise ProcessingError(f"Unable to connect to {self.url}:", err) from None
Expand Down
2 changes: 1 addition & 1 deletion zabbix_utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

__version__ = "2.0.3"
__version__ = "2.0.4"

__min_supported__ = 6.0
__max_supported__ = 7.4
Loading