This commit is contained in:
Holger Sielaff
2025-10-01 12:20:19 +02:00
parent 35b6ac3fbc
commit e479e08ee0
3 changed files with 10 additions and 11 deletions

View File

@@ -56,4 +56,5 @@ UserParameter=python.exception.log.accessible,[ -r /var/log/zabbix/python.except
UserParameter=python.exception.handler.active,python3 -c "import sys; sys.path.insert(0, '/usr/lib/python3.12'); import zabbix_exception_handler; print('1')" 2>/dev/null || echo "0" UserParameter=python.exception.handler.active,python3 -c "import sys; sys.path.insert(0, '/usr/lib/python3.12'); import zabbix_exception_handler; print('1')" 2>/dev/null || echo "0"
# Alternative check: Prüfe ob Handler-Modul existiert # Alternative check: Prüfe ob Handler-Modul existiert
UserParameter=python.exception.handler.available,[ -f /usr/lib/python3.12/zabbix_exception_handler.py ] && echo "1" || echo "0" UserParameter=python.exception.handler.available,[ -f /usr/lib/python3.12/zabbix_exception_handler.py ] && echo "1" || echo "0"

View File

@@ -8,16 +8,13 @@ This demonstrates how to use the Zabbix exception monitoring in your Python appl
import sys import sys
import os import os
# Add the Zabbix module path # Optional: Add the Zabbix module path
sys.path.insert(0, '/usr/lib/python3.12') # sys.path.insert(0, '/usr/lib/python3.12')
# Method 1: Import the main handler (auto-initializes) # Method 1: Import the main handler (auto-initializes)
import zabbix_exception_handler from zabbix_monitor import zabbix_monitor
# Method 2: Alternative simple import (also auto-initializes) # Method 2: Manual initialization (if you want more control)
# import zabbix_monitor
# Method 3: Manual initialization (if you want more control)
# from zabbix_exception_handler import ZabbixPythonExceptionHandler # from zabbix_exception_handler import ZabbixPythonExceptionHandler
# ZabbixPythonExceptionHandler.init() # ZabbixPythonExceptionHandler.init()
@@ -59,4 +56,4 @@ if __name__ == "__main__":
demonstrate_file_error() demonstrate_file_error()
else: else:
print("No exception generated. Handler is still active for any future exceptions.") print("No exception generated. Handler is still active for any future exceptions.")
print("Your application can continue normally...") print("Your application can continue normally...")

View File

@@ -66,7 +66,7 @@ zabbix_export:
} }
triggers: triggers:
- uuid: 9df96b18c230490a9a0a9e2307226352 - uuid: 9df96b18c230490a9a0a9e2307226352
expression: 'length(last(/Python Exceptions Monitoring/python.exception.latest)) > 15' expression: 'length(last(/Python Exceptions Monitoring/python.exception.latest)) > 15 and change(/Python Exceptions Monitoring/python.exception.latest) <> 0'
name: 'Python Exception Detected' name: 'Python Exception Detected'
event_name: 'New Python Exception Logged' event_name: 'New Python Exception Logged'
priority: HIGH priority: HIGH
@@ -106,6 +106,7 @@ zabbix_export:
value: application value: application
- tag: component - tag: component
value: python value: python
recovery_mode: NONE
- uuid: 8df96b18c230490a9a0a9e2307226343 - uuid: 8df96b18c230490a9a0a9e2307226343
name: 'Python Exception Log Size' name: 'Python Exception Log Size'
type: ZABBIX_PASSIVE type: ZABBIX_PASSIVE
@@ -130,4 +131,4 @@ zabbix_export:
- tag: scope - tag: scope
value: availability value: availability
- tag: component - tag: component
value: python value: python